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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help saving settings from input.

Status
Not open for further replies.

TinkerBear

Programmer
Oct 1, 2001
8
US
Hello,
I am creating a program where the user may input values for cmd buttons and links.

I want it set up so when they start up the application those values are still there and not reset.

I dont know anything about database ini etc. Please help me, im fairly new to vb.

Thanks.

 
Dear tinkerbear,

an easy way to solve this is to save all those settings in a plain text file. and to have it read in when your programms load.

regards Astrid
 
I store my app startup values in the Registry using the SaveSetting and GetSetting statements. They are very easy to use.
 
Hey,

Um that would be nice, but how exactly do i get the program to look at the plain txt for the info. Never done that if you could give me some info on it, it would be greatly appreciated.

With the getsettings and savesettings i couldn't find anything good on them here (for win2k pro anyways)...maybe some info on that would be great too....

I love this site...so far it has helped me tremendously...any other sites you would recommend if i cannot find what i am looking for here?

Thanks :D
 
hi TinkerBear,
according to Sawatzky's suggestion you can save the info in an .ini file. Your program will read/write it whenever needed. To do this you need to use API function. Don't worry, it's easy;-)

put this code into General_Declarations section:
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long

Declare Function GetPrivateProfileStringByKeyName Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

this is code to write into .ini file:
Public Sub WriteAppINIFile(sSection As String, sKeyName As String, sValue As String, sFileName As String)

WritePrivateProfileString sSection, sKeyName, sValue, sFileName

End Sub

this is code to read from .ini file:
Public Function ReadAppINIFile(sSection As String, sKeyName As String, sDefaultValue As String, sFileName As String) As String

Dim sBufferINI As String
Dim xLong As Long
Dim lReturnVal As Long

sBufferINI = String$(128, 0)
xLong = 199

lReturnVal = GetPrivateProfileStringByKeyName(sSection, sKeyName, sDefaultValue, sBufferINI, xLong, sFileName)

If lReturnVal > 0 Then
ReadAppINIFile = Left$(sBufferINI, lReturnVal)
Else
ReadAppINIFile = sDefaultValue
End If
End Function

play with it and have fun.
Good luck :)

 
Well sorry to be such a newbie, but I did all that...(i think i got it right...dunno) i had a few errors and fixed em, but i dont know if i ruinied it in the process...for teh top 2 code u gave me to put in general_Declarations i had to add Private to the begining...will that ruin it?

Also for the input i will probably use input box...will that automatically save stuff...like for example

If i have the input box ask for "Your name.." and when you typed it in there it would put "Your name.." into a label...would "Your name.." still be in there when you restart the application?

Sorry to be such a bug :D
 
Dear tinkerbear,

for plaintext files you could use the createtextfile and opentextfile functions

have a look at them in the online-help,

regards Astrid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top