"Display Message" button

button for displaying input information

Page 1 of 1

13 Replies - 3732 Views - Last Post: 15 August 2008 - 05:01 PM Rate Topic: -----

#1 nvnorris  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-March 08

"Display Message" button

Post icon  Posted 13 August 2008 - 09:32 AM

I have not idea how to get started on this. I need to know how to display information that is entered into two text boxes using a "display message" button.
Is This A Good Question/Topic? 0
  • +

Replies To: "Display Message" button

#2 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 520
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: "Display Message" button

Posted 13 August 2008 - 10:24 AM

View Postnvnorris, on 13 Aug, 2008 - 09:32 AM, said:

I have not idea how to get started on this. I need to know how to display information that is entered into two text boxes using a "display message" button.


That's pretty easy, it's just accessing the textboxes text, which is also easy. :D

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! :D
Was This Post Helpful? 0
  • +
  • -

#3 cmount  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 41
  • Joined: 01-August 08

Re: "Display Message" button

Posted 13 August 2008 - 10:45 AM

View PostLocke37, on 13 Aug, 2008 - 10:24 AM, said:

View Postnvnorris, on 13 Aug, 2008 - 09:32 AM, said:

I have not idea how to get started on this. I need to know how to display information that is entered into two text boxes using a "display message" button.


That's pretty easy, it's just accessing the textboxes text, which is also easy. :D

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! :D


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?
Was This Post Helpful? 0
  • +
  • -

#4 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 520
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: "Display Message" button

Posted 13 August 2008 - 01:54 PM

View Postnvnorris, on 13 Aug, 2008 - 09:32 AM, said:

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?


vbCrLf inserts a line break. The CrLf part of it stands for Carriage Return Line Feed, basically, pushing the <Enter> or <Return> key.

:D

Example:

MsgBox("This is" & vbCrLf & "my message!")


That will output this...(in a message box of course)

Quote

This is
my message!

This post has been edited by Locke37: 13 August 2008 - 01:56 PM

Was This Post Helpful? 0
  • +
  • -

#5 Zhalix  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 260
  • Joined: 07-May 08

Re: "Display Message" button

Posted 13 August 2008 - 03:29 PM

Also, vbNewLine can be used in place of vbCrLf to create new lines. It's a few more characters long but I think it's easier to remember, especially when you're new to this type of stuff.

This post has been edited by Zhalix: 13 August 2008 - 03:30 PM

Was This Post Helpful? 0
  • +
  • -

#6 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 520
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: "Display Message" button

Posted 13 August 2008 - 04:07 PM

Ah, didn't know there was a vbNewLine. In my VB class, we always just used vbCrLf. :D
Was This Post Helpful? 0
  • +
  • -

#7 Zhalix  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 260
  • Joined: 07-May 08

Re: "Display Message" button

Posted 13 August 2008 - 06:17 PM

View PostLocke37, on 13 Aug, 2008 - 05:07 PM, said:

Ah, didn't know there was a vbNewLine. In my VB class, we always just used vbCrLf. :D


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. :rolleyes:
Was This Post Helpful? 0
  • +
  • -

#8 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 179
  • Posts: 1,599
  • Joined: 17-April 07

Re: "Display Message" button

Posted 13 August 2008 - 06:32 PM

hi also use

chr(13)

for new line
Was This Post Helpful? 0
  • +
  • -

#9 cmount  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 41
  • Joined: 01-August 08

Re: "Display Message" button

Posted 14 August 2008 - 06:05 AM

View Postthava, on 13 Aug, 2008 - 06:32 PM, said:

hi also use

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
Was This Post Helpful? 0
  • +
  • -

#10 Zhalix  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 260
  • Joined: 07-May 08

Re: "Display Message" button

Posted 14 August 2008 - 08:28 AM

You can change the buttons to some extent, by specifying one of the setups in the MsgBox function:

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
Was This Post Helpful? 0
  • +
  • -

#11 cmount  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 41
  • Joined: 01-August 08

Re: "Display Message" button

Posted 14 August 2008 - 09:56 AM

View PostZhalix, on 14 Aug, 2008 - 08:28 AM, said:

You can change the buttons to some extent, by specifying one of the setups in the MsgBox function:

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)


Was This Post Helpful? 0
  • +
  • -

#12 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 179
  • Posts: 1,599
  • Joined: 17-April 07

Re: "Display Message" button

Posted 14 August 2008 - 06:34 PM

hi buddy it is a too risky one if you want do this things then do it
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 :^:
Was This Post Helpful? 0
  • +
  • -

#13 cmount  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 41
  • Joined: 01-August 08

Re: "Display Message" button

Posted 15 August 2008 - 11:16 AM

You totally lost me...make a regular form? How can you do that? When I go to the Insert menu...the only options are: UserForm, Class Module, and Module--I don't see any option for a regular form

I'm using the VB Editor that comes with Microsoft Office (I'm working with VBA)--if that has anything to do with it.

View Postthava, on 14 Aug, 2008 - 06:34 PM, said:

hi buddy it is a too risky one if you want do this things then do it
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 :^:

Was This Post Helpful? 0
  • +
  • -

#14 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 179
  • Posts: 1,599
  • Joined: 17-April 07

Re: "Display Message" button

Posted 15 August 2008 - 05:01 PM

You totally lost me...
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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1