-
Aug 20th, 2000, 11:17 AM
#1
Thread Starter
New Member
I ahve recenlty downloaded an sample project to read ini files.
What I would like to be able to do is populate various list boxes or combo boxes with the various oprions in the ini file.
for example I would firstly like to get a list of the sections in brackets, then after selecting this a list of the parameter under that section.
Is this at all possible.
Thnx for any help you can extend.
~qb~
-
Aug 20th, 2000, 11:32 AM
#2
Monday Morning Lunatic
If you're going to do it that way, it's probably easier to read in the whole file and parse it yourself, that way you can instantly get a tree-based structure representing the file.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 20th, 2000, 02:36 PM
#3
As parksie suggested, that is probably a faster way to do it and here's how:
Code:
Public Sub List_Add(List As ComboBox, txt As String)
List.AddItem txt
End Sub
Public Sub List_Load(TheList As ListBox, FileName As String)
On Error Resume Next
Dim TheContents As String
Dim fFile As Integer
fFile = FreeFile
Open FileName For Input As fFile
Do
Line Input #fFile, TheContents$
Call List_Add(TheList, TheContents$)
Loop Until EOF(fFile)
Close fFile
End Sub
Public Sub List_Save(TheList As ListBox, FileName As String)
On Error Resume Next
Dim Save As Long
Dim fFile As Integer
fFile = FreeFile
Open FileName For Output As fFile
For Save = 0 To TheList.ListCount - 1
Print #fFile, TheList.List(Save)
Next Save
Close fFile
End Sub
But here is how to read an ini file anyway.
Code:
Public 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) As Long
Public Function ReadINI(strsection As String, strkey As String, strfullpath As String) As String
Dim strbuffer As String
Let strbuffer$ = String$(750, Chr$(0&))
Let ReadINI$ = Left$(strbuffer$, GetPrivateProfileString(strsection$, ByVal LCase$(strkey$), "", strbuffer, Len(strbuffer), strfullpath$))
End Function
Usage:
'x = readini("test.ini", "test", "C:\test.ini")
'List1.Additem x
-
Aug 20th, 2000, 02:50 PM
#4
-
Aug 21st, 2000, 04:12 AM
#5
Hyperactive Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|