Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Oct 1, 1996



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Using SaveSetting in 16 Bit Environment

I have problem with the statement "SaveSetting" in VB 4.0 16 bit.

SaveSetting writes entries to the Registry, which is a Win95 32-bit feature. Under 16-bit VB and Window 3.x, SaveSetting's first argument can be replaced with the name of the INI file you wish to write to. In the case of a 16-bit app (especially if it's targeted at Win3.x) I would strongly recommend using a private ini file rather than writing to WIN.INI file. All too many Win3.x programs blithely write to WIN.INI with no way for the user to know it is being done. In the case of ShareWare that you've tried and then uninstalled, this leaves lots of extra baggage in WIN.INI, which slows the loading of Windows quite a bit and can eventually bog it down to the point that it won't load at all. Polite coding practice is to use a private ini file that lives in the same directory as the program itself. If you code something in VB3.0 you can use the following to read and write private ini files. Make sure that the two declares go on a single line for each of them:

'first declare
Declare Function GetPrivateProfileString% Lib "Kernel" (ByVal lpAppName$, ByVal lpKeyName$, ByVal lpDefault$, ByVal lpReturnedString$, ByVal nSize%, ByVal lpFileName$)

'second declare
Declare Function WritePrivateProfileString% Lib "Kernel" (ByVal lpAppName$, ByVal lpKeyName$, ByVal lpString$, ByVal lpFileName$)

Function GetPrivIni (AppName As String, KeyWord As String, IniFile As String)
Dim Returned$
Returned$ = Space$(128)

Valid% = GetPrivateProfileString(AppName, KeyWord, "", Returned$, Len(Returned$), IniFile)
GetPrivIni = Left$(Returned$, Valid%)

End Function

Sub SetPrivIni (AppName As String, KeyWord As String, KeyVal As String, IniFile As String)

Valid% = WritePrivateProfileString(AppName, KeyWord, KeyVal, IniFile)

If Valid% = False Then MsgBox "Can't Write to IniFile"

End Sub
DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date