Results 1 to 12 of 12

Thread: Basic Module Question

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    67
    Can I use a module to load registry settings and have them available at all times? I took a guess at this and did the following:

    Dim Y As Variant


    Y = GetSetting("Savetest", "Startup", "LastEntry", "0")

    That's what's in my module right now. With the intent on using "y" in the forms in my program to do equations.

    Obviously this guess was wrong 'cause I get the following error on load:

    Compile error:
    Invalid outside Procedure

    and it highlights the "Savetest" part of my module code.

    Is there a way to do this. I'd like to have the user set the "x" "y" "z" factors that can be used throughout the program without having to use getsetting procedures on all my forms.

    Please Help!

    Thanks in advance!!

  2. #2
    Lively Member
    Join Date
    Jul 2000
    Posts
    94

    Thumbs up You could try this... but its just a guess

    Public Sub GetSetting()
    Dim Y As Variant
    Y = GetSetting("Savetest", "Startup", "LastEntry", "0")
    End Sub

    From your form you could just call the GetSetting sub procedure

    i.e. just type GetSetting wherever you want the code to be done.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    67
    That's what I've been doing actually. But since I use the "y" in severla forms, I was wondering if there was a way to put the main "y" getsetting in a module that runs throughout the program. So that everytime I need to call "y" I don't have to put the getsetting solution. Maybe I'm going at this wrong. Thanks though.

  4. #4
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    in a .bas module

    Code:
    Public y
    
    Public Sub GetAllSettings()
    
    y = GetSetting("Savetest", "Startup", "LastEntry", "0")
    
    End Sub
    in a form module

    Code:
    Private Sub Form_Load()
     GetAllSettings
     
     MsgBox y
    End Sub
    works for me.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  5. #5
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    GetSetting can't be the name of a sub, because the name is already in use, so you must change the name, but beyond that:

    you have two options, Y has to be a global variable (Not the best idea), so you could do this:
    Code:
    Public Y As Variant
    Public Sub GetValue() 
    Y = GetSetting("Savetest", "Startup", "LastEntry", "0") 
    End Sub
    or turn getseeting in to a function(in this case, the registry is called every time:
    Code:
    Public Function GetValue() 
    GetValue = GetSetting("Savetest", "Startup", "LastEntry", "0") 
    End Function
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  6. #6
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    554
    I would have thought that if you want X, Y and Z to be accessible from all forms and modules in your application then your best declaring them as PUBLIC in a MODULE.


    Therefore giving those variables APPLICATION scope.
    and you can still GET(the)SETTING in your form load event.


    DocZaf
    {;->

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    67
    Using YoungBucks idea, say somone were too change the settings while using the program. What code would have to be added to change the global "y"?





    in a .bas module



    code:--------------------------------------------------------------------------------
    Public y

    Public Sub GetAllSettings()

    y = GetSetting("Savetest", "Startup", "LastEntry", "0")

    End Sub


    in a form module


    Private Sub Form_Load()
    GetAllSettings

    MsgBox y
    End Sub

  8. #8
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    just change the value of y...

    Code:
    y = Whatever the new value is
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    67
    right, that much i did with savesetting already.
    But with this system the "y" value gets aquired when the main form loads. So if the user goes and changes the value while the form is already loaded, how would I update everything without having to shut the form/(program) down and restart?

    Thanks.

  10. #10
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    I dont understand what you are trying to do, like I said above just change the value of y

    Code:
    y = 420 ' or whatever you want it to
    and just put a SaveSetting in the Form_Unload procedure and the next time the form is loaded the value will be retrieved.

    Code:
    Private Sub Form_Unload
    
     SaveSetting "Savetest", "Startup", "LastEntry", y
    
    End Sub
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    67
    ok, i'll walk ya through my little practice program.


    You start the program and there are 3 boxes. x, y, z
    the user puts a number in x. When you press the figure button it adds x plus the y which we've discussed, to get z.

    if the user wants to change the y value, he clicks the settings button which shows/opens the settings form. when he puts in the new y value and presses the save setting, y is now updated. The problem is, through out all this, the main form was still open, so it's still holding the y value that was apparent during it's load.

    Is there a way to update the y's value on the main form automatically without having to close and reopen the form?

    thanks for your patience.

  12. #12
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    As long as you have declared y public it doesn't matter what form or module changes the value of y it is changed for any form or module. So like I said just update the value as stated above.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

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