"Display Message" buttonbutton for displaying input information
Page 1 of 1
13 Replies - 3271 Views - Last Post: 15 August 2008 - 05:01 PM
#1
"Display Message" button
Posted 13 August 2008 - 09:32 AM
Replies To: "Display Message" button
#2
Re: "Display Message" button
Posted 13 August 2008 - 10:24 AM
nvnorris, on 13 Aug, 2008 - 09:32 AM, said:
That's pretty easy, it's just accessing the textboxes text, which is also easy.
Private Sub Button1_Click()
Label1.Caption = TextBox1.Text & vbCrLf & TextBox2.Text
End Sub
You replace Button1, Label1, TextBox1, TextBox2 with your names for those things on your form.
Hope this helped!
#3
Re: "Display Message" button
Posted 13 August 2008 - 10:45 AM
Locke37, on 13 Aug, 2008 - 10:24 AM, said:
nvnorris, on 13 Aug, 2008 - 09:32 AM, said:
That's pretty easy, it's just accessing the textboxes text, which is also easy.
Private Sub Button1_Click()
Label1.Caption = TextBox1.Text & vbCrLf & TextBox2.Text
End Sub
You replace Button1, Label1, TextBox1, TextBox2 with your names for those things on your form.
Hope this helped!
Am I understanding this correctly: the goal is to make clickable buttons based on the text input from textboxes?
Basically customizing what the button says based on the input text? That's rather cool...I might look at implementing that rather than my vbRetryCancel button (It would be nice to have custom text buttons rather than retry & cancel)!
Another random, dumb question on this note. How do you denote line breaks in message boxes, and can you do this for buttons w/ multiple-lines of text?
#4
Re: "Display Message" button
Posted 13 August 2008 - 01:54 PM
nvnorris, on 13 Aug, 2008 - 09:32 AM, said:
vbCrLf inserts a line break. The CrLf part of it stands for Carriage Return Line Feed, basically, pushing the <Enter> or <Return> key.
Example:
MsgBox("This is" & vbCrLf & "my message!")
That will output this...(in a message box of course)
Quote
my message!
This post has been edited by Locke37: 13 August 2008 - 01:56 PM
#5
Re: "Display Message" button
Posted 13 August 2008 - 03:29 PM
This post has been edited by Zhalix: 13 August 2008 - 03:30 PM
#6
Re: "Display Message" button
Posted 13 August 2008 - 04:07 PM
#7
Re: "Display Message" button
Posted 13 August 2008 - 06:17 PM
Locke37, on 13 Aug, 2008 - 05:07 PM, said:
I didn't know about vbNewLine for a long time and I could never seem to remember the predefined constant vbCrLf for new lines, so every time I needed new lines I ended up using Google. Learning about vbNewLine was a blessing for me. Of course it was right after learning vbNewline that I memorized vbCrLf. Go figure.
#8
Re: "Display Message" button
Posted 13 August 2008 - 06:32 PM
chr(13)
for new line
#9
Re: "Display Message" button
Posted 14 August 2008 - 06:05 AM
thava, on 13 Aug, 2008 - 06:32 PM, said:
chr(13)
for new line
Is there any quick, easy way to quickly change the text & actions for the buttons in a MsgBox, or would it be easier to just create a UserForm to accomplish this?
I'm just trying to wrap my head around a possible new way to do something. The other thing I was wondering is where you should place the code to tell a UserForm what actions to take when the buttons are clicked---I want the buttons to GoTo a certain marker in my main code, but that obviously is separate from the UserForm...so just trying to figure that out (if that makes any sense)
If you want to see my existing code, look for the thread I wrote with a lot of bumps & new questions & no replies from anyone else. It's called something like incorporating .exe command prompt file into VB
#10
Re: "Display Message" button
Posted 14 August 2008 - 08:28 AM
MsgBox "Hey", vbYesNoCancel, "Lalala"
However if you need more than that, you will want to make your own MessageBox. It's pretty simple so don't be afraid to go that route.
To check what the result was, there are a few ways to go about it. If there's only two possible buttons, OR if you only have two possible actions and therefore two of the three buttons do the same thing, then you can use this approach:
If MsgBox("Are you male?", vbYesNoCancel, "Question") = vbYes Then
'Code
Else
'Code
End If
However if you wanted it to act differently for each of the three buttons, you'd have to switch to another approach. Declare an integer variable to hold the result, and then call the function, like this:
Dim intResult As Integer
intResult = MsgBox("Are you male?", vbYesNoCancel, "Question")
If intResult = vbYes Then
'Code
ElseIf intResult = vbNo Then
'Code
ElseIf intResult = vbCancel Then
'Code
End If
A list of most, if not all results from the MsgBox:
vbYes
vbNo
vbCancel
vbAbort
vbRetry
vbIgnore
vbOK
#11
Re: "Display Message" button
Posted 14 August 2008 - 09:56 AM
Zhalix, on 14 Aug, 2008 - 08:28 AM, said:
MsgBox "Hey", vbYesNoCancel, "Lalala"
However if you need more than that, you will want to make your own MessageBox. It's pretty simple so don't be afraid to go that route.
To check what the result was, there are a few ways to go about it. If there's only two possible buttons, OR if you only have two possible actions and therefore two of the three buttons do the same thing, then you can use this approach:
If MsgBox("Are you male?", vbYesNoCancel, "Question") = vbYes Then
'Code
Else
'Code
End If
However if you wanted it to act differently for each of the three buttons, you'd have to switch to another approach. Declare an integer variable to hold the result, and then call the function, like this:
Dim intResult As Integer
intResult = MsgBox("Are you male?", vbYesNoCancel, "Question")
If intResult = vbYes Then
'Code
ElseIf intResult = vbNo Then
'Code
ElseIf intResult = vbCancel Then
'Code
End If
A list of most, if not all results from the MsgBox:
vbYes
vbNo
vbCancel
vbAbort
vbRetry
vbIgnore
vbOK
I'm sorry I didn't specify exactly what I was trying to do. My message boxes currently already do this---I just am not entirely happy with the options of Yes No...forcing the user to read through my description when I'd really like the button to be more advanced & have a bit of a description in it...
Or have one button be something like "Start Over," and another be "Cancel" (note: my cancel button is a lot more complicated than just unloading the project/stopping the code. I have a routine it needs to run before it can actually stop (deleting the temp stuff it may have copied into the spreadsheet). For the full existing code, you can see my other post.
What I was thinking of doing was something like this userform (I really didn't want to go the userform route...but I want the custom buttons & to make it more visually friendly)
I attached a zip where I included the files that seemed to be generated when I used the File-->Export File thing in the microsoft VB thing when I had the form open. (one's a .frx, the other is a .frm)
This is just to give an idea what the thing's supposed to look like
I want the Yes: I want to cancel button on the userform to goto a certain line of code in my one module--the placeholder TempDelete
In my main module of my existing code (before I created the UserForm Cancelled_Prompt in an attempt to make the prompt a little more user friendly), I added:
Load Cancelled_Prompt ' to load the userform Cancelled_Prompt.Show ' to make it visible
I wasn't sure what code I needed to add to either the userform or the main module to get the userform's buttons to do what I want within the code of my main module
Attached File(s)
-
myform.zip (1.41K)
Number of downloads: 64
#12
Re: "Display Message" button
Posted 14 August 2008 - 06:34 PM
you need not specify your seperate user form
add a normal form and name if frmmsg
now disable the min max button
now add a button array this is because you create a new button on runtime easily
now make a cls file clsmsg
now make a method showmessage
add parameters what ever you want think dont make all the things are needed
make it optional
now declare a variable like htis
dim Fmsg as new frmmsg
write the code here
fmsg.show (vbapp..modal)
write the code here
now when you clck the button the form must unload
unload me
now you can use this class fille anywhere in your project
hope you understand good luck
#13
Re: "Display Message" button
Posted 15 August 2008 - 11:16 AM
I'm using the VB Editor that comes with Microsoft Office (I'm working with VBA)--if that has anything to do with it.
thava, on 14 Aug, 2008 - 06:34 PM, said:
you need not specify your seperate user form
add a normal form and name if frmmsg
now disable the min max button
now add a button array this is because you create a new button on runtime easily
now make a cls file clsmsg
now make a method showmessage
add parameters what ever you want think dont make all the things are needed
make it optional
now declare a variable like htis
dim Fmsg as new frmmsg
write the code here
fmsg.show (vbapp..modal)
write the code here
now when you clck the button the form must unload
unload me
now you can use this class fille anywhere in your project
hope you understand good luck
#14
Re: "Display Message" button
Posted 15 August 2008 - 05:01 PM
Cool!
I don't think so
here some code for you
this is module code
Dim cls As Class1 Sub main() checkpositive 10 End Sub Public Sub checkpositive(ByVal num As Integer) Set cls = New Class1 If num > 0 Then cls.ShowMessage "Greater than Zero" Else cls.ShowMessage "less than Zero" End If End Sub
this is the class module code
Dim frm As UserForm1 Public Sub ShowMessage(Messagestring As String) Set frm = New UserForm1 frm.Label1.Caption = Messagestring frm.Show (vbApplicationModal) End Sub
this is userform1 code
Private Sub CommandButton1_Click() 'code here Unload Me End Sub Private Sub CommandButton2_Click() 'code here Unload Me End Sub
This post has been edited by thava: 15 August 2008 - 05:03 PM
|
|

New Topic/Question
Reply




MultiQuote




|