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

IniFile , IniSection, IniItem does not exist?

Status
Not open for further replies.

Karl Blessing

Programmer
Feb 25, 2000
2,936
US
I am reading an article over at <br><A HREF=" TARGET="_new"> has three types in there that concern me, IniFile, IniSection, IniItem, none of these show up in the MSDN help, wne when I search online MSDN only points to that Article, nor is it even show in the API Text Viewer, I have no idea how to declare these types or use them, yet I was able to get back the section names through the command. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML,Visual InterDev 6, ASP(WebProgramming), QBasic(least i didnt start with COBOL)
 
I managed to get all the section names as well as the items under them using this that I wrote when I payed attention to how the SectionName API command was being used.<br><br><FONT FACE=monospace><br>Public Sub ReadData()<br>&nbsp;&nbsp;Dim strSections As String<br>&nbsp;&nbsp;Dim lngSize As Long<br>&nbsp;&nbsp;Dim astrSections As Variant<br>&nbsp;&nbsp;Dim astrItems As Variant<br>&nbsp;&nbsp;Dim i As Integer<br>&nbsp;&nbsp;Dim Items As Variant<br><br>&nbsp;&nbsp;On Error GoTo HandleErrors<br>&nbsp;&nbsp;&nbsp;Form1.Label1.Caption = &quot;&quot;<br>&nbsp;&nbsp;' In most cases, 1024 characters is enough, but if it's<br>&nbsp;&nbsp;' not, the code will double that and try again.<br>&nbsp;&nbsp;lngSize = 1024<br>&nbsp;&nbsp;Do<br>&nbsp;&nbsp;&nbsp;&nbsp;strSections = Space$(lngSize)<br>&nbsp;&nbsp;&nbsp;&nbsp;lngSize = GetPrivateProfileSectionNames(strSections, lngSize, &quot;C:\kbstuff\inistuff\Test.ini&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;If lngSize = 0 Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' No sections, so get out of here!<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GoTo ExitHere<br>&nbsp;&nbsp;&nbsp;&nbsp;ElseIf lngSize = Len(strSections) - 2 Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' That's how the API indicates you didn't allow<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' enough space, but returning the size you originally<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' specified, less 2. In that case, just double the<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' buffer, and try again.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lngSize = lngSize * 2<br>&nbsp;&nbsp;&nbsp;&nbsp;Else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' Trim the extra stuff. Use lngSize - 1 because<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' there's an extra vbNullChar at the end of this<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' string.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strSections = Left$(strSections, lngSize - 1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit Do<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;Loop<br>&nbsp;&nbsp;' Now strSections contains the section names, separated<br>&nbsp;&nbsp;' with vbNullChar.<br>&nbsp;&nbsp;astrSections = Split(strSections, vbNullChar)<br>&nbsp;&nbsp;For i = LBound(astrSections) To UBound(astrSections) - 1<br>&nbsp;&nbsp;&nbsp;&nbsp;' Add the section to the collection, indicating that<br>&nbsp;&nbsp;&nbsp;&nbsp;' it's not a NEW section. That is, it's not being added<br>&nbsp;&nbsp;&nbsp;&nbsp;' after the file was read. That way, the code there can<br>&nbsp;&nbsp;&nbsp;&nbsp;' know to not bother looking for items when being added<br>&nbsp;&nbsp;&nbsp;&nbsp;' by code later.<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Form1.Label1.Caption = Form1.Label1.Caption & astrSections(i) & vbCrLf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;astrItems = GetValues(astrSections(i))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;For Each Items In astrItems<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Form1.Label1.Caption = Form1.Label1.Caption & &quot;&nbsp;&nbsp;&quot; & Items & vbCrLf<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Next<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;'Call AddSection(astrSections(i), False)<br>&nbsp;&nbsp;Next i<br><br>ExitHere:<br>&nbsp;&nbsp;Exit Sub<br><br>HandleErrors:<br>&nbsp;&nbsp;Err.Raise Err.Number, Err.Source, Err.Description<br>End Sub<br><br><br>Public Function GetValues(section As Variant) As Variant<br>&nbsp;&nbsp;Dim strSections As String<br>&nbsp;&nbsp;Dim lngSize As Long<br>&nbsp;&nbsp;Dim astrSections As Variant<br>&nbsp;&nbsp;Dim i As Integer<br><br>&nbsp;&nbsp;On Error GoTo HandleErrors<br><br>&nbsp;&nbsp;' In most cases, 1024 characters is enough, but if it's<br>&nbsp;&nbsp;' not, the code will double that and try again.<br>&nbsp;&nbsp;lngSize = 1024<br>&nbsp;&nbsp;Do<br>&nbsp;&nbsp;&nbsp;&nbsp;strSections = Space$(lngSize)<br>&nbsp;&nbsp;&nbsp;&nbsp;lngSize = GetPrivateProfileSection(section, strSections, lngSize, &quot;C:\kbstuff\inistuff\Test.ini&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;If lngSize = 0 Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' No sections, so get out of here!<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GoTo ExitHere<br>&nbsp;&nbsp;&nbsp;&nbsp;ElseIf lngSize = Len(strSections) - 2 Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' That's how the API indicates you didn't allow<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' enough space, but returning the size you originally<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' specified, less 2. In that case, just double the<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' buffer, and try again.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lngSize = lngSize * 2<br>&nbsp;&nbsp;&nbsp;&nbsp;Else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' Trim the extra stuff. Use lngSize - 1 because<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' there's an extra vbNullChar at the end of this<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' string.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strSections = Left$(strSections, lngSize - 1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit Do<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;Loop<br>&nbsp;&nbsp;' Now strSections contains the section names, separated<br>&nbsp;&nbsp;' with vbNullChar.<br>&nbsp;&nbsp;astrSections = Split(strSections, vbNullChar)<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;GetValues = astrSections<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>ExitHere:<br>&nbsp;&nbsp;Exit Function<br><br>HandleErrors:<br>&nbsp;&nbsp;Err.Raise Err.Number, Err.Source, Err.Description<br>End Function<br><br></font> <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML,Visual InterDev 6, ASP(WebProgramming), QBasic(least i didnt start with COBOL)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top