|
-
Feb 15th, 2001, 01:46 PM
#1
Thread Starter
Lively Member
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!!
-
Feb 15th, 2001, 03:19 PM
#2
Lively Member
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.
-
Feb 15th, 2001, 03:26 PM
#3
Thread Starter
Lively Member
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.
-
Feb 15th, 2001, 03:31 PM
#4
Fanatic Member
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}
-
Feb 15th, 2001, 03:31 PM
#5
Fanatic Member
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]
-
Feb 15th, 2001, 03:38 PM
#6
Fanatic Member
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
{;->
-
Feb 15th, 2001, 05:47 PM
#7
Thread Starter
Lively Member
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
-
Feb 15th, 2001, 05:51 PM
#8
Fanatic Member
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}
-
Feb 15th, 2001, 06:09 PM
#9
Thread Starter
Lively Member
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.
-
Feb 15th, 2001, 06:14 PM
#10
Fanatic Member
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}
-
Feb 15th, 2001, 06:27 PM
#11
Thread Starter
Lively Member
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.
-
Feb 15th, 2001, 06:40 PM
#12
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|