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

Trouble with variables and Modules in Visual Basic

  • 01-01-2005 1:07pm
    #1
    Registered Users, Registered Users 2 Posts: 36


    People, i am new to boards, and you have already helped me, and i have learnt to asked clearly and specifically, here goes....

    I am using Visual Basic 6. I have a few different forms. I have a frmMain form and there is a value in a text field in it that i want to update. The value is meant to come from another form different to the frmMain (but of course still in the same project).

    Now i am sure i have to use a Module and declare the variable in the in the module, then it would be global and i could use the variable in different forms. But it isn't working out... Any help....

    So, if i have
    txtSumOfMoney.Text = Amount
    in frmMain and in lets say
    Amount = Amount + 500 in frmCashUpDate
    How do i get this to work? I have made a module and in it written the following
    Global Amount As Integer

    Could someone please help? Should i be more specific?


Comments

  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Create a public sub called Main in your module that simply shows whatever your default form should be. Then under project properties have it start using the sub main rather than automatically loading a form.


  • Closed Accounts Posts: 8,264 ✭✭✭RicardoSmith


    I'm not sure what you are asking. But as a variation on Corinthians post.

    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Load subMain (Start Application)
    (Main routine load all frms and sub routines from here)
    Declare/Initialise global variables

    Load frmMain

    Load frmCashUpDate
    Update global variable
    Close frmCashUpDate

    Reload/refresh values in frmMain from global variable.
    Close frmMain

    (insert error handler here to catch all errors from all sub routines within subMain)
    Close subMain (end application)
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


    A lot of this depends on what kind of application it is and if you open and close from or have them all open and child forms etc. But it generally good practise to have one main routine that everything runs from. Run subRoutines, functions and forms from this main routine. In that way you have one "master" routine" where you can see the overall flow and logic of the application.


  • Registered Users, Registered Users 2 Posts: 2,781 ✭✭✭amen


    have a look at property Get/Set in VB
    you can declare a local variable on the form and the
    define a Get/Set property that will that value to be set
    on frmMain
    its been a long time since I did this so the syntax is probally wrong
    Declare dAmount as double
    property set Amount(value as double)
    dAmount = value)
    end property

    then in frmCashUpdate
    frmMain.Amount = 500


  • Closed Accounts Posts: 8,264 ✭✭✭RicardoSmith


    You could use property bags either. But unless its a complex app I wouldn't bother.


Advertisement