I am making a very simple Visual Basic code and the problem I am getting is having the text box have wording when the program is ran.
I want the textbox to say "My name is John" and when you click the button It will then change to "and this is my first VB program".
Also here is the code I've made:
Public Class frmMain
Private Sub btnClickMe_Click(sender As System.Object, e As System.EventArgs)Handles btnClickMe.Click
txtOutPut.Text = "My name is John"
txtOutPut.Text = "and this is my first VB program"
End Sub
End Class
Yeah sorry with the faily simple question but thanks and I really appreciate it.
Try setting your text to "My name is John" outside of the button click, perhaps in a Form.Init handler, then removing txtOutPut.Text = "My name is John" from btnClickMe_Click1
What's happening here is the button click is changing the text first to "My name is John", then changing it to "and this is my first VB program" and the change happens too quickly for it to be visible.
Public Class frmMain
Private Sub btnClickMe_Click(sender As System.Object, e As System.EventArgs)Handles btnClickMe.Click
txtOutPut.Text = "My name is John" & VbCrLf & "and this is my first VB program"
End Sub
End Class
You need the txtOutPut.Text = "My name is John" when the form loads (Or straight during the design, once you place the textbox go to properties and put "My name is John" in the Text property), you have everything in the button, so when you press the button it first executes txtOutPut.Text = "My name is John" and then txtOutPut.Text = "and this is my first VB program", and it overwrites "My name is John", so you always see "and this is my first VB program" once you pressed the button.
Related
I need to create a button in Lotus Notes mail stationary which will insert a text and then the button is deleted from the message.
In the button I have:
res := #Prompt([OkCancelList]; "Is it OK?"; "Select result"; " ";"OK":"Failed":"");
#If(res ="OK";
#Command([EditGotoField]; "Body") + #Command([EditInsertText]; "Everything is fine);
#Command([EditGotoField]; "Body") + #Command([EditInsertText]; "Not so good mate"));
This part works fine, but I am not sure how to delete the button after click. Usually works #Command([EditClear]) but not in this case when I use #Command([EditGoToField]) in the formula.
I suppose i need to use GoToField again with the correct button identifier and then run EditClear, but I do not know where to find it, or if there is another way to do it... Ideas?
Thank you.
Assuming you have the button in field Body and nothing else that have to remain
then change your code to:
#Command([EditGotoField]; "Body");
#Command([EditSelectAll]);
res := #Prompt([OkCancelList]; "Is it OK?"; "Select result"; " ";"OK":"Failed":"");
#If(res ="OK";
#Command([EditInsertText]; "Everything is fine");
#Command([EditInsertText]; "Not so good mate"));
It selects the content of Body (including button) and replaces it by the new text.
Assuming your document is (or could be put into) edit mode, you could still have the button, but have the button in it's own paragraph (or table cell) with a hide-when formula of of MySpecialButtonPressed!="", and then include the line
FIELD MySpecialButtonPressed := #Now;
in the button code.
(Edit: changed test from =1 to !="", then changed the set value from 1 to #Now because Notes doesn't store Boolean values. Unless you're sending out millions of these, the cost of using dates instead of numbers less than the benefit of having more specific information in case you need it.)
I have one form with two fields called "Field 1" and "Field 2" and one action button called "check". On click of that action button, i want to open dialog box with three fields which should get auto populate based on Field 2 value. How to achieve it?
Appreciate if anyone helps me.
Yes, it is possible. There's a document parameter for NotesUIWorkspace.DialogBox(). Use this document to pass parameters to your dialog.
UPDATE
Assume you have a form with name "MyDialogForm" to represent your dialog.
It looks like that and contains 3 fields:
And you have a form with two fields and "Check" button:
Put the following code to the "Click" event handler of your "Check" button:
Sub Click(Source As Button)
Const DIALOG_FORM_NAME = "MyDialogForm"
Dim ws As New NotesUIWorkspace
Dim dialogBoxAccepted As Boolean
Dim dialogParamDoc As NotesDocument
Dim currentDocument As NotesDocument
Dim field2Value As String
Set currentDocument = ws.CurrentDocument.Document
field2Value = currentDocument.GetItemValue("Field2")(0)
'document created in-memory, but should not be saved
Set dialogParamDoc = New NotesDocument(currentDocument.ParentDatabase)
'populating dialog box fields
Call dialogParamDoc.ReplaceItemValue("DialogField1", "dialogField1 with: " + field2Value)
Call dialogParamDoc.ReplaceItemValue("DialogField2", "dialogField2 with: " + field2Value)
Call dialogParamDoc.ReplaceItemValue("DialogField3", "dialogField3 with: " + field2Value)
dialogBoxAccepted = ws.DialogBox(DIALOG_FORM_NAME,True , True, False, False , False , False, "My Dialog Title", dialogParamDoc, True)
If dialogBoxAccepted Then
'displaying values, entered/changed in dialog box
Msgbox dialogParamDoc.getItemValue("DialogField1")(0),,"DialogField1"
Msgbox dialogParamDoc.getItemValue("DialogField2")(0),,"DialogField2"
Msgbox dialogParamDoc.getItemValue("DialogField3")(0),,"DialogField3"
End If
End Sub
This code reads "Field2" and populates dialog fields based on its value. Then it shows the dialog where you can change these values.
If you pressed OK in your dialog (dialog accepted), the code will show the values you have altered in dialog box.
I want to add a button to my excel worksheet which should call a macro that can handle one agument (an integer value). Sadly when creating the button, I cannot link any macro that has arguments. Also just typing the macro and the argument does not work.
Is there any simple solution to pass an argument to a macro when a button is pressed?
Yes, you can assign a macro to a button (or other excel controls/menu actions) and pass constant OR variable arguments to it.
In the 'Assign Macro' window (right-click on object and select 'Assign Macro'):
Enclose the macro name in single quotes
e.g. to pass 2 constants: 'Button1_Click("A string!", 7)'
Select 'This Workbook' for the 'Macros in' field
If you wish to pass a variable (like the value of a cell), enclose the parameter in Evaluate()
For example, to pass the value of Sheet1!$A$1 to a button function, you would have the following text in the 'Macro name:' field:
Button1_Click(Evaluate("Sheet1!$A$1"))
If you don't enclose your variable argument with an 'Evaluate' function, excel returns the error 'Formula is too complex to be assigned to an object.'.
I would have included an image if this were allowed on my first post.
Suppose you have a public sub take 1 argument like below (just for explanation purposes.)
And you insert a button on Worksheet like below, and you can not find the macro name when you want to assign your sub to this button.
Now, you can type in your sub name + space + argument manually in single quotes, like below, click ok.
Then you see, problem solved.
Sub ert()
Call ert2(Cells(1,1).Value)
End Sub
Use an activeX control command button and in the button click method, call the sub and pass the argument:
Private Sub CommandButton_Click()
Dim x as Integer
x = 1
Call SomeSub(x)
End Sub
To call this Sub from a button :
Public Sub TestButton(strMessage As String)
MsgBox strMessage
End Sub
... be aware that the Sub won't be listed in the available macros, because it has a parameter. Just type in the call in single quotes : 'TestButton "Hello"'
Called from a regular "forms" button on a worksheet you can do something like this:
Sub TestMe()
Dim c, arr
c = Application.Caller
arr = Split(c, "_")
If UBound(arr) > 0 Then MsgBox "Got " & arr(1)
End Sub
Where the calling button is named (eg) "Button_3"
Or (simpler) right-click the button and enter 'TestMe2 5' (Including the single-quotes)
Sub TestMe2(i)
MsgBox "Got " & i
End Sub
See also: Excel 2010 - Error: Cannot run the macro SelectCell using .onAction
I had trouble with my version of Personal.xlsb!'testForXXXX("Test Test")'. I got an error when clicking the button containing the Macro.
However, I was able to fix it by removing the "(" and ")". So, Personal.xlsb!'testForXXXX "Test Test"' worked (notice the space between testForXXXX and "Test...").
In fact, I didn't need Personal.xlsb! and was just able to use 'testForXXXX "Test Test"'.
I hit the same issue with the assign button not being very useful until I realised that all the potential macros displayed were only the ones in my Personal.xlsb file that took no arguments. Then I typed Personal.xlsb!'macroNameWhichTakesArguments("arg1", ...)' and the sheet picked it up.
I.E. Personal.xlsb!'testForXXXX("Test Test")'
Where the macro testForXXXX take a string as input, then the sheet worked ok.
When you use the assign macro route for a button in excel 2007 at least testForXXXX will not show up in the list of potential macros if it takes args.
I suspect Aaron C got tripped up by this too. Maybe its best not to use a Personal.xlsb file?
I would have liked to comment the answer by QA Collective but I do not have enough reputation point yet. Previous solutions did not work for me, as my macros are in named modules in my VBA project.
With Excel 2013, the way to pass a parameter to a macro using a button that worked in my context is :
'<module name>.<macro name> <parameter>'
e.g
'DataProcessor.disle "myText"'
or
'DataProcessor.editWSProcess True'
(boolean do not need double quotes when passed as parameters)
Please note that single quotes are around the whole expression.
I try to print PDF with HyperLink, without succes
I have a lock field "etat" with data
Data are formatted like:
Code TAB Nom TAB Adress TAB Ville
56 Eric rue caboteur ST NAZAIRE
87 Franc rue Midin ST brevin
etc
the textStyle of item 3 "Adress" set to "Link and linktext set to ""http://maps.google.fr/maps?f=q&hl=fr&q=theadresse""
When i click on hyperlink item in field "etat" that work fine
Now i would like have the same result after printing this field in PDF
I use this code for printing
on mouseUp
local theResult,thepDF
ask file "" with type "PDF file|pdf|PDF "
if it = "" then
exit mouseUp
end if
put it into thePDF
put the htmltext of fld "etat" into theResult
--set the fileType to "revoPDF "
open printing to pdf thePDF
revPrintField the name of field "etat"
--revPrintText theResult,"<%pageNumber%> of <%numPages%>","<%pageNumber%> of <%numPages%>",the long id of field "etat" of stack "CDH"
close printing
end mouseUp
I have a nice PDF with clicked words, but the click don't launch google maps
The dictionary say for command "print link"
"When printing fields, any text that has its linkText property set together with the link textStyle is treated as if a print link command had been executed with the contents of the property as link, and the formattedRect of the text as rectangle."
But no work.... I have a big headache
Thank for yours help to achieve this
Eric
I am trying to understand your problem and reading through your code, I think maybe the link text…
"http://maps.google.fr/maps?f=q&hl=fr&q=theadresse"
should be…
"http://maps.google.fr/maps?f=q&hl=fr&q=" & theadresse
This is assuming theadresse is a variable containing a valid address to search in Google.
Is there a way to create a template in ReSharper that capitalizes a name?
For example I'd like to do something like this:
private $type$ _$name$;
public $type$ $uppercase_name$
{
get { return _$name$; }
set { _$name$ = value; }
}
So when I enter "city" for $name$, $uppercase_name$ should automatically be "City".
Ok I did it:
When adding a template, on the right there's a part where you can choose a macro. Click on "Choose Macro" for uppercase_name.
Go to the end of the list. There's a macro called "Value of another variable with the first character in upper case". Choose that.
The part "another variable" will be in red in the macro selection part. Click on that.
Choose name.
Enjoy!
P.S. I have ReSharper 7.1. This may not be applicable for earlier versions.