Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Simple INI Files and VB Use of Them


Reply
 
Thread Tools Display Modes
  #1  
Old 04-17-2001, 12:23 PM
Brain_Drain
Guest
 
Posts: n/a
Default Simple INI Files and VB Use of Them


This is an open request for you VB gurus and such to provide me with some insight regarding the use of simple INI text files in order to make a VB application more portable and universal from platform to platform.

What I have been told is that INI files are used to store things which can change from system to system - things like directories and paths, different input and output filenames, user preferences, etc.

Could somebody simply include a small INI file to show me what one looks like and then attach some VB code which shows me where (under which control) and how the info in the INI file is extracted and used in the application? Thanks.

Reply With Quote
  #2  
Old 04-17-2001, 12:37 PM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default Re: Simple INI Files and VB Use of Them

Here is a sample of an INI file from an antivirus program:

<PRE>
[SERVICES]
NodeBrowser=0
Databases=0

[DATABASE]
DatabasePath=
DatabaseMappedPath=

[SCANOPTIONS]
BeepOnDetect=1
ScanExeOnly=0
ScanArchives=1
ScanLotusDatabases=1
ScanBoot=1
ScanFiles=1
InfctAct=3
ScanMode=1
AutoDisplay=1
IncrementalScan=0
NotifyOwner=1
NotifySender=0
bNotifyAdministrator=0
bAttachInfoFile=1
ScanAfter=0
ExtName=APP*BIN*COM*DLL*DOT*DOC*DRV*EXE*OVL*OVR*PRG*SYS*VXD*XLT*XLA*XL S*XLW*
SkipExtName=BTR*DBF*SBF*DB*MDB*MDX*NDX*
ArcExtName=ZIP*ARJ*LHA*LZH*MIM*UUE*CAB*
LotusNotesExtName=NSF*NTF*
ReNameExt=AVB
CopyBeforeCure=0
HeuristicScan=0
MacroCureOption=0
DontRenameWhenCureFails=0

[WINDOWSIZE]
Left=88
Top=88
Width=768
Height=558
State=1

[TOOLBAR]
ShowToolbar=1

[STATUSBAR]
ShowStatusbar=1

[QUICKACCESS]
ShowQuickAccess=1


</PRE>

The various parts are:
1) the section header, the part in square brackets. eg. [TOOLBAR] or [STATUSBAR]
2) the key, the part before the '=' sign. eg. ShowStatusBar
3) the value, the part after the '=' sign. eg 1

You can have keys with the same names under different sections.

To read and write INI files, you can use the API calls GetPrivateProfileString and WritePrivateProfileString. There are others, like GetPrivateProfileInt but the string ones are most useful.

Here are their function declarations:
Declare Function WritePrivateProfileString& Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKey As Any, ByVal lpString As String, ByVal lpFileName As String)
Declare Function GetPrivateProfileString& Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String)

You can use it like:

WritePrivateProfileString "STATUSBAR","ShowStatusBar","1","inoculan.ini"

Where "STATUSBAR" is the section name (note NO square brackets; the function adds that itself), "ShowStatusBar" is the key and "1" is the value. "inoculan.ini" is the name of the INI file. If it doesn't exist, it will be created.

"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #3  
Old 04-17-2001, 02:33 PM
usetheforce2's Avatar
usetheforce2 usetheforce2 is offline
Senior Contributor

Retired Moderator
* Expert *
 
Join Date: Jul 2000
Location: Toronto, Ontario, Canada
Posts: 1,410
Default Re: Simple INI Files and VB Use of Them

http://vbapi.com/ref/w/writeprofilestring.html

http://vbapi.com/ref/g/getprofilestring.html

as mentioned above by Billsoo you want to use the GetProfileString and WriteProfileString API functions with the INI files. I've placed the two links that open an example to these functions.
vbapi.com has a super reference to most of the api's available and that also have good examples

__________________
winsock siteHERE||EliteVBHERE||C++ & VB Markup UtilityHERE
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->