Declaring a Global (Public) variable in VB - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Declaring a Global (Public) variable in VB

slamhoggslamhogg Posts: 7Member
Hello, I am new to VB, but have experience in a lot of other languages. I am having trouble correctly declaring a global variable in VB. I get a value in one form and i later want to use that same value in another form. I thought i could just use:
Public fullpath as String
at the top of the form page and then continue to use this variable anywhere else i wanted in the project, but that isn't the case. Does a global variable have to be declared in a module instead of a form? I know this is probably very easy to do, but i'm having trouble with it. Any help is greatly appreciated.
Thanks

Comments

  • JonathanJonathan Posts: 2,914Member
    : Hello, I am new to VB, but have experience in a lot of other languages. I am having trouble correctly declaring a global variable in VB. I get a value in one form and i later want to use that same value in another form. I thought i could just use:
    : Public fullpath as String
    : at the top of the form page and then continue to use this variable anywhere else i wanted in the project, but that isn't the case. Does a global variable have to be declared in a module instead of a form? I know this is probably very easy to do, but i'm having trouble with it. Any help is greatly appreciated.
    :

    Global variables have to be declared in BAS modules. Public variables are allowed in forms, but you have to accees them through the form, e.g. Form1.VariableName

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • slamhoggslamhogg Posts: 7Member
    : : Hello, I am new to VB, but have experience in a lot of other languages. I am having trouble correctly declaring a global variable in VB. I get a value in one form and i later want to use that same value in another form. I thought i could just use:
    : : Public fullpath as String
    : : at the top of the form page and then continue to use this variable anywhere else i wanted in the project, but that isn't the case. Does a global variable have to be declared in a module instead of a form? I know this is probably very easy to do, but i'm having trouble with it. Any help is greatly appreciated.
    : :
    :
    : Global variables have to be declared in BAS modules. Public variables are allowed in forms, but you have to accees them through the form, e.g. Form1.VariableName
    :
    : Jonathan
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    :

    Thanks i wasn't aware of the format you listed.
  • KDivad LeahcimKDivad Leahcim Posts: 3,948Member
    : Global variables have to be declared in BAS modules. Public variables are allowed in forms, but you have to accees them through the form, e.g. Form1.VariableName
    :

    A little more info:

    Public variables can be declared in any module and are always accessible by the format Module.Variable, although in most cases you'll need the name of the specific instance of the object instead of the object's "template" (MyObject instead of clsMyObject if MyObject is a valid instance of clsMyObject).

    In the case of variables declared in .bas modules, you can omit the name of the module if you prefer or include the name of the module if you need to for some reason.
Sign In or Register to comment.