Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetSetting and SaveSetting 1

Status
Not open for further replies.

kaylabear

Programmer
Oct 23, 2002
59
CA
Hi, can someone please show me some code that contains an example of GetSetting() and SaveSetting().

Thank You.
 
VB's help file contains complete examples of both these calls.
 

[tt]
MyString = GetSetting((Appname as string), (Section as string), (Key as string), (Default as string))

MyNumber = Val(GetSetting((Appname as string), (Section as string), (Key as string), (Default as string)))

SaveSetting (Appname as string), (Section as string), (Key as string), (Setting as string)

SaveSetting (Appname as string), (Section as string), (Key as string), Trim(Str(Setting as Number)))

'Appname = App.EXEName

[/tt]

Good luck

 
hi there vb5prgrmr your reply offers a lot of insight, however I am a little unsure of what ((Appname as string), (Section as string), (Key as string), (Default as string)), each of these parameters means and how I go about using these options.

I am greatful for your help as my version of Visual Basic does not have working help files.

Thank you.
 
>my version of Visual Basic does not have working help files

Perhaps we can offer advice on fixing them
 

Basically, it can be viewed as a directory structure (its not I know but it is a good analogy). Where...

GetSetting

Appname is the root directory
Section is a sub folder
Key is a descriptive File (or another sub folder if you wish)
and...
Default is the contents of the file and if empty this is the default value

SaveSetting

Appname is the root directory to be created if necessary
Section is a subfolder to be created if necessary
Key is a descriptive file name to be created if necessary
and...
Setting is the contents you want to save in the file

So lets say you want to store a user name and password in the registry (if you do this I would suggest some type of encryption), you would do something like...

[tt]
SaveSetting App.EXEName, "LogonInfo", "Name", "George"
SaveSetting App.EXEName, "LogonInfo", "Pass", "Bush"
[/tt]

I hope this helps, Good Luck

 
Help for VB6 is also available from MSDN:
Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
Hi, everyone's tips are very insightfull, but I'm still having trouble understanding how it all comes together.

I have an example listed below, basically when the program starts, GetSetting is called to determine the value of trys. If this is the very first time the program is run than trys will not exist yet and an error will occur, so at this point the variable trys will be created and assigned a value of zero.
Next the value of trys will be incremented by one and SaveSetting will be called to save the value of trys.

PUESDO CODE:

Sub Form Load()
GetSetting(trys), the value of trys

OnError: Undefined Variable Type, trys
{
Dim trys as byte
trys = 0
}

trys = trys + 1
SaveSetting(trys), the value of trys

End Sub

How would I go about implementing this code?

Thank you in advance for all your help.
 

Do you mean something like...

[tt]
Dim NoTrys As Byte
NoTrys = Val(GetSetting(App.EXEName, "Number Of Trys", "Count", "0"))
NoTrys = NoTrys + 1
If NoTrys > maxamount Then
MsgBox "You have exceded the number of times that this program can be run!", vbOKOnly + vbCritical, "Program Will Now End!"
End
End If
SaveSetting App.EXEName, "Number Of Trys", "Count", Trim(Str(NoTrys))

[/tt]

Look it up at MSDN

Good Luck

 
Unfortunately strongm, so many things go so unnoticed and unappreciated
 
Yes Thank you vb5prgrmr, but how do I handle the ERROR. Because when trys or noTrys is called the first time it can't yet exist and if this is the case an error will occur.

It is only at this point that I want to create noTrys.

Otherwise every other time the program runs I want to increment noTrys without having to re-create it every time.

Thanks Again.
 

kaylabear,

You are going to have to declare a variable to recieve the value from getsetting or use a hidden control to store the value. If you have not yet declared a variable and then try to place that value in a variable that has not yet been declared you are going to run into problems. VB 6.0 does not let you do conditional declarations (VB.NET Does as do some other languages), you must declare the variable to use it or you will recieve errors. (Actually you could turn off Option Explicit by deleting it from the top of the form but this is definitly going to get you into more trouble than it is worth.)

So in short you are going to have to declare trys(notrys in my example as you can see in my example) to be able to use it without having any errors.

I would suggest at this time to surf over to borders.com or another web site and look for a visual basic 6.0 beginners book.

Good Luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top