Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

variables in VB

  • 01-04-2000 12:19pm
    #1
    Registered Users, Registered Users 2 Posts: 4,676 ✭✭✭


    Hi,
    I have a form that takes input from a user and assigns it a variable. When i wish to access this variable from another form, it just appears as zero ? I have declared the variable as public and am lost !?!?! I am using VB6. Any ideas ?

    Gav


Comments

  • Business & Finance Moderators, Entertainment Moderators Posts: 32,387 Mod ✭✭✭✭DeVore


    You will have to declare the variable in a module not in the form declarations area.
    Also , try declaring it as Global so that all forms can see it.

    Also, consider using Option Explicit in your forms (in the general area I think) or setting it in the Options dialog (I dunno about VB6). That way instead of seeing "0" as the value you will get an error that the variable hasnt been declared (because its scope doesnt cover your second form).

    Hope this helps.
    DeV.


  • Registered Users, Registered Users 2 Posts: 2,494 ✭✭✭kayos


    Ok one or two things here what DeVore said is complety right you should put it into a module file and you should turn on the Option Explicit (in VB6 its Tools-> Options-> Editor -> Require Variablre Delcaration)
    But do you really want to use globals ??? These are never really a good idea they look harmless enough but once you strart doing bigger projects they are a no no. Try creating a class based on the USER and then assign the varibles you take in to that as you go along VB is an OO language (ok here come all the c++/java heads saying no to this) so use as such. If you need to read up try Business Objects in VB6 by Wrox Press.

    TypeOf Kayos is IUnkown


  • Registered Users, Registered Users 2 Posts: 16,414 ✭✭✭✭Trojan


    Hi guys,

    kinda OT, but I'm just interested in why there was ever an Option Explicit in the first place?

    The only thing this does is give the newbie somewhere else to introduce errors, and ever self-respecting VB programming [and there aren't many wink.gif ] that I know has this turned on.

    Just curious if there's a good reason!

    Al.


  • Moderators, Social & Fun Moderators Posts: 28,633 Mod ✭✭✭✭Shiminay


    I reckon it started out as an internal joke in Micro$uck and they never bothered fixing it smile.gif



    All the best,

    Dav
    @B^)
    http://homepage.eircom.net/~davitt


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Originally posted by Trojan:
    kinda OT, but I'm just interested in why there was ever an Option Explicit in the first place?

    GWBASIC didn't have it afaik.

    I'm pretty sure QBASIC 4.5 didn't have it either but QBASIC Professional did as did VBDOS.

    So it was probably left out to let legacy code be ported across without hassle.

    But they should set Option Explicit on by default otherwise you code becomes a complete mess.

    Nothing funnier then switching on Option Explicit and then telling a developer to fix thier code. biggrin.gif

    As mentioned eariler you should also not be using Globals unless it's absolutly nessary. Normally if I had to do that it would only apply to program defaults (which I would save out to an INI).


  • Advertisement
  • Closed Accounts Posts: 91 ✭✭koloth


    VB6: Tools | Options | Editor and check Requie Variable Definition to switch on option explicit


  • Registered Users, Registered Users 2 Posts: 2,494 ✭✭✭kayos


    koloth check out the third post its already in there thats not very OO of you cut and paste inhertance will not be acceptible biggrin.gif
    Just joking


    KaYoS


Advertisement