Results 1 to 5 of 5

Thread: Problem with public variable - Not possible to get its value

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    Problem with public variable - Not possible to get its value

    I have created a module where I declare a Public variable.
    Code:
    Public Const MyVariable = 5
    In another form I try to get its value and show it in a MsgBox
    Code:
    Msgbox MyVariable
    I get an empty Msgbox. I don't know why it happens and how I can solve it.

    I thought that I would get a Msgbox containing the value 5.

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Problem with public variable - Not possible to get its value

    You would unless you have another variable defined with the same name or you have a miss spelling on one of those.

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Problem with public variable - Not possible to get its value

    I have created a module where I declare a Public variable.
    if it is an object module, you will have to prepend the module name
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Problem with public variable - Not possible to get its value

    Also note that you should be using Option Explicit in your code to require variable definitions so that you get a compile error when a variable is accessed outside its scope.

  5. #5
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: Problem with public variable - Not possible to get its value

    Hey Data...long time, no hear (my fault, been busy doing other things). Don't know why people don't learn that basic, and I mean, BASIC, "trick" of using OE. Yeah, it took me some time to learn it, as well, but when I did.....NEVER WENT BACK.
    Jose, post your project (probably doesn't contain private info)....folks here can IMMEDIATELY identify your REAL issue.

    Sammi

Tags for this Thread

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