Public variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joe donnelly
    New Member
    • Mar 2007
    • 5

    #1

    Public variables

    I can't seem to get a public variable to maintain the values it should throughout my Excel Visual basic routine. For example:

    public Bigg as integer ''declared the variable bigg


    Private sub x

    bigg=3

    end sub


    Private sub y

    bigg=bigg ''got bigg = 0 ...didn't carry the value 3 as assigned in sub x

    end sub

    So, do you see what I am doing wrong here? Any help would be appreciated.
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    If I take your version above to be accurate you should know that
    Bigg, bIgg, biGg, bigG and bigg are all different variable names.

    Comment

    • kscmjo
      New Member
      • Mar 2007
      • 13

      #3
      If you ensure that you always place

      Option Explicit - at the start of any module,
      (This means that all variables used MUST be declared)
      Any programmer that doesn't use this is asking for trouble.

      VB will convert the case to the original declared case automatically. This is a good way of checking. I always declare variables with upper and lower case ie txtMyString as string. so with Option Explicit VB will automatically change txtmystring to txtMyString unless I spell it wrong.

      Comment

      Working...