Using SaveSetting in 16 Bit Environment

Question:
I have problem with the statement “SaveSetting” in VB 4.0 16 bit.

Answer:
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 declareDeclare Function GetPrivateProfileString% Lib “Kernel” (ByVal lpAppName$, ByVal lpKeyName$, ByVal lpDefault$, ByVal lpReturnedString$, ByVal nSize%, ByVal lpFileName$)’second declareDeclare 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 FunctionSub 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

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: