Results 1 to 13 of 13

Thread: changing label text with multi use buttons

  1. #1

    Thread Starter
    New Member sonyc's Avatar
    Join Date
    Nov 2002
    Location
    Standing Behind You
    Posts
    11

    changing label text with multi use buttons

    is there a way to change text in a label using a button that set it as one thing?

    i.e.:
    Button_Click()
    label.caption = "blah" & form1.text1.text & "blah"

    what i want to do is make it so that when i change the text in the box the caption changes.

    from: blah hi blah
    to blah bye blah

    using the same buton

    how do i do that?

    please respond asap!!
    Johnny Tsunami

  2. #2
    Member
    Join Date
    Sep 2002
    Location
    Miami, FL
    Posts
    35

    Change event

    Use the Text box's change event "Text1_Change()" instead of the Button's click event. This event occurs every time the text is changed in the text box
    Rich Stern
    http://www.AcidPlanet.com/Jasp182
    http://www.InsomniacRecords.com
    http://www.mp3.com/Jasp182

  3. #3

    Thread Starter
    New Member sonyc's Avatar
    Join Date
    Nov 2002
    Location
    Standing Behind You
    Posts
    11
    i tried that. it didnt work. does anyone have a different sugestion? i would like to get the project done today or tomorrow so the more help i get the sooner the better. thanks for the help if you can offer some, if not thats ok too
    peace out

    go big or dont go at all
    Last edited by sonyc; Nov 27th, 2002 at 11:33 AM.
    Johnny Tsunami

  4. #4
    Fanatic Member laserman's Avatar
    Join Date
    Jan 2002
    Location
    Wales U.K
    Posts
    775

    LABEL

    IS THIS WHAT YOU WANT?

    LASERMAN
    Attached Files Attached Files

  5. #5
    Fanatic Member laserman's Avatar
    Join Date
    Jan 2002
    Location
    Wales U.K
    Posts
    775

    FORGOT FORM

    SORRY
    Attached Files Attached Files

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: changing label text with multi use buttons

    Originally posted by sonyc
    is there a way to change text in a label using a button that set it as one thing?

    i.e.:
    Button_Click()
    label.caption = "blah" & form1.text1.text & "blah"

    what i want to do is make it so that when i change the text in the box the caption changes.

    from: blah hi blah
    to blah bye blah

    using the same buton

    how do i do that?

    please respond asap!!

    I'm not sure I get it.
    You want to type text into a text box. Click a button and have the caption of a label change to include the text you typed.
    Is that right?

    If so, then you got the code right, in the click event of the button, add the codeto change the caption of the label.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Originally posted by sonyc
    i tried that. it didnt work.
    It didn't work> Or it didn't do what you want? Big diff.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    New Member sonyc's Avatar
    Join Date
    Nov 2002
    Location
    Standing Behind You
    Posts
    11

    didnt do what i wanted to do

    the code that you gave me did what i had done before.

    the file is exactly what i want to do except that i am using 2 forms, not one
    Johnny Tsunami

  9. #9

    Thread Starter
    New Member sonyc's Avatar
    Join Date
    Nov 2002
    Location
    Standing Behind You
    Posts
    11

    oh well

    hey guys.

    thanks for trying to help me with this. even though i have not figured it out yet and it is past when i preferred to have the code by, i am still trying to get the code to complete the project. if you guys havent posted and know the code or have a different sugestion on how to do it then please tell me.

    thanks for your help on getting this project done.
    Johnny Tsunami

  10. #10
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    im prety confused... do you mean

    button.caption = "blah" & form1.text1.text & "blah"
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  11. #11

    Thread Starter
    New Member sonyc's Avatar
    Join Date
    Nov 2002
    Location
    Standing Behind You
    Posts
    11
    ummmm................no

    what i am doing is making a program that you fill in a text box on one form, click a button causing the form to hide, a different form to show, and the text from the box appears in the caption of the second form and in a label. that i have working, the part that i am stuck on is when the user clicks on a menu option, the forms switch back, you can change the text, re-click the button and the label and caption change. the caption has changed but not the label.



    the code that i am using is:
    form1
    Private Sub Command1_Click()
    Form2.Caption = "Happy Thanksgiving, " & Text1.Text & "!"
    Form1.Hide
    Form2.Show
    End Sub

    Private Sub Form_Load()
    Form1.Caption = "Happy Thanksgiving!"
    End Sub

    Private Sub Text1_Change()
    Form2.Refresh
    Form2.Label2.Refresh
    End Sub


    Form2

    Private Sub Command1_Click()
    End
    End Sub

    Private Sub Form_Load()
    Label2.Caption = "To, " & Form1.Text1.Text & ","
    End Sub

    Private Sub Form_LostFocus()
    End
    End Sub

    Private Sub mnuDisclaimer_Click()
    MsgBox ("This image is from Killfrog.com's Fix-A-Turkey game.")
    End Sub

    Private Sub mnuFDiff_Click()
    Form1.Show
    Form2.Hide
    End Sub

    Private Sub mnuFExit_Click()
    End
    End Sub

    Private Sub mnuHelp_Click()
    MsgBox ("This project was made by Johnny Tsunami.")
    End Sub


    if you can tell me why i cant get the label to change i would greatly appreciate it.

    thanks for your help
    Johnny Tsunami

  12. #12
    Frenzied Member John McKernan's Avatar
    Join Date
    Jan 2002
    Location
    SE PA
    Posts
    1,295
    The reason the Form2.Label2.Caption is not changing is because you are setting the value only in the Form_Load event of Form2.
    In mnuFDiff_Click you call Form2.Hide. This does not unload the form, merely hides it. So when you again call Form2.Show from Form1.Command1_Click, the Form_Load event of Form2 is not called, since it is already loaded.

    You could either Unload the forms rather than hiding them, or change this code:
    VB Code:
    1. Private Sub Command1_Click()
    2.    Form2.Caption = "Happy Thanksgiving, " & Text1.Text & "!"
    3.    Form2.Label2.Caption = "To, " & Text1.Text & ","
    4.    Form1.Hide
    5.    Form2.Show
    6. End Sub

    BTW: setting the value of Form2.Caption or any controls on Form2 causes Form2 to be loaded. This could cause problems depending on what you are doing in the Load event of Form2.

    Also, I would advise not using the End statement. This is not the best way to stop your program.

  13. #13

    Thread Starter
    New Member sonyc's Avatar
    Join Date
    Nov 2002
    Location
    Standing Behind You
    Posts
    11
    thanks john

    that does exactly what i wanted to do
    Johnny Tsunami

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width