Results 1 to 7 of 7

Thread: [RESOLVED] VB6 Global variables

  1. #1

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Resolved [RESOLVED] VB6 Global variables

    How can i set a value of a global variable declared on Form1 from Form2?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB6 Global variables

    Code:
    Form1.MyGlobalVarible = Whatever

  3. #3

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: VB6 Global variables

    It doesn work
    How must the variable be declared?

    I got an error saying Method or data member not found

  4. #4
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: VB6 Global variables

    You have to declare as a DIM


    DIM myVariableName as String (shared with other forms tooo)

    and use

    Public myVariableName as String (needs to be in a MODULE)

    Private myVariableName as String (shared with the current form only)
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  5. #5
    Hyperactive Member
    Join Date
    Jan 2006
    Location
    Pakistan
    Posts
    388

    Re: VB6 Global variables

    Declare the global variable in a module with this command at the top of your code below the "Option Explicit"

    Global MyValue as Integer

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB6 Global variables

    You can declare a public variable in a form, and call it from another form.
    Code:
    'on form1
    
    Option Explicit
    
    Public strString As String
    
    'on form2
    Private Sub Form_Load()
    Form1.strString = "Hack"
    End Sub

  7. #7

    Thread Starter
    Fanatic Member Dungeon Keeper's Avatar
    Join Date
    Mar 2008
    Posts
    590

    Re: VB6 Global variables

    thanx guys, it works now

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