Results 1 to 4 of 4

Thread: VB Newbie question...

  1. #1
    Cheeko
    Guest
    Ok, so I'm new to VB.
    I have VB 5.0 Professional Edition.

    What I want is quite simple, just to chnage the caption of a form in run time.
    So, on form 1, there is a text box and a command button, when the button is pressed, it assigns the text in the text box to a variable, then hides the current form and shows another form.
    On the new form, when it loads, I have it so the caption is changed to the variable...
    However, in run time, it stays blank.

    I'm presuming it's cos the variable isn't global?
    It's defined in a 'private' sub, so I when I call it in other places it isnt recognized?

    Im not sure, new to VB as I say

    To change screen do I have to go to a new form?
    Or could I put two layouts on there, and when I push the button, it makes certain controls visable property to false and opther to true?
    But that seems teidious if Im gunna need several screens?

    Any ideas?

  2. #2
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Add a Command Button control and paste this code into your Form will do.

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        Dim F As Form1
        
        Set F = New Form1
        Load F
        F.Caption = Text1.Text
        F.Show
    End Sub
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        Dim F As Form
        For Each F In Forms
            Unload F
            Set F = Nothing
        Next
        End
    End Sub
    
    'Code improved by vBulletin Tool (Save as...)

  3. #3
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    ???

    Code:
    'Form1
    Private Sub Command1_Click()
      Load Form2
      Form2.Caption = Text1.Text
    
      Form2.Show
    End Sub
    does that work?
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  4. #4
    Cheeko
    Guest
    Both ways work!!

    Thanks alot

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