Results 1 to 6 of 6

Thread: Help With Variables

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    13

    Arrow

    I am making a little program that requires a variable from one form to end up on another. I use that Public statement but when I compile or run the program, I get an erro message saying the variable is not defined. any inference into what the problem is would be greatly appreciated.
    Thank You Much
    Pie, I'm just going to go like this and if you get eaten, it's your own fault.- Homer Simpson

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    what kind of variable is it, because some kinds can't be declared as Public variables

  3. #3
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    If you need the variable from one form to appear on the other, you need to access the object followed by the variable.

    For instance

    Form1:
    Public Happy As String

    Form2:
    Dim MyNews

    Private Sub Form_Load()
    MyNews = Form1.Happy
    Msgbox MyNews
    End Sub

    Hope this helps
    -Excalibur

  4. #4
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    Actually, let me put up some working code so you get a better idea.

    Form1 (put a command button on form1):
    Code:
    Public Happy As String
    
    Private Sub Command1_Click()
        Form2.Show
    End Sub
    
    Private Sub Form_Load()
        Happy = "Happy"
    End Sub
    Form2:
    Code:
    Private Sub Form_Load()
        MsgBox Form1.Happy
    End Sub
    Hope that will clear things up. There are some things which cannot be declared public on a form, but at the moment, I'm reletively unsure what they are. The above example does, however, work

    -Excalibur

  5. #5
    Guest
    Dim it.

    Code:
    INTEGER
    
    Dim myINT As Integer 
    
    Private Sub Form_Load()
    myINT = 0
    End Sub
    
    Private Sub Command1_Click()
    myINT = myINT + 1
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    Msgbox myINT
    End Sub
    Code:
    STRING
    
    Dim myString As String
    
    Private Sub Form_Load()
    myString = "Hello"
    Msgbox myString
    myString = "Good bye"
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    Msgbox myString
    End Sub

    You should also remove Option Explicit, it's not needed.

    Pretty easy to understand .

  6. #6
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    I may be wrong, but using dim won't allow another form to grab the information from that variable, will it?

    >I am making a little program that requires a variable from
    >one form to end up on another.

    That requires the use of Public and accessing that variable through:

    object.XXX (XXX can be an object, variable, sub, function, control, or property as long as
    it's been declared as public.)

    I could be wrong about the Dim statement, but I do know that I was able to access the variable from one form on another using public and the above syntax.
    -Excalibur

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