basic vba question (global variable?)

Discussion in 'OT Technology' started by GuOD, Apr 2, 2008.

  1. GuOD

    GuOD mcflurry diet

    Joined:
    May 19, 2003
    Messages:
    7,366
    Likes Received:
    0
    Location:
    Toronto
    hi guys,

    so this is probably a really basic thing but i'm not sure how to do it

    I want to do something as follows:

    dim variable1 as string
    variable1 = range("a1").value

    and then I want to be able to just use variable1 in 5-6 different macros without redefining it (since it'd always be the same). is this possible? :noes:


    i read something about making a public sub and defining it and calling it each time or something? :dunno:
     
  2. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    create a bas with:

    global varname1 As String = "value goes here"
    global varname2 As Integer = 23
    global varname3 As Double = 23.323


    so-on, and so-forth.
     
    Last edited: Apr 2, 2008
  3. GuOD

    GuOD mcflurry diet

    Joined:
    May 19, 2003
    Messages:
    7,366
    Likes Received:
    0
    Location:
    Toronto
    oh.. it's actually called a global variable? :o

    sorry - what's a bas?

    do the macros all need to be in the same module?
     
  4. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    bas == module

    I'm not sure what scope a global var exists in vba. In .Net it would have to be within the same assembly, so it could be in diff modules so long as they're within the same assembly.
     
  5. GuOD

    GuOD mcflurry diet

    Joined:
    May 19, 2003
    Messages:
    7,366
    Likes Received:
    0
    Location:
    Toronto
    thanks

    i dont think the line of code global varname1 As String = "value goes here"

    it higlights the = and says expected end of statement (its weird because i know i've seen vba in this format before with dim instead of global)
     
  6. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Global Stringname As String

    -- meanwhile, back in the GUI --

    Stringname = "whatever"
     

Share This Page