Results 1 to 4 of 4

Thread: how to use this public sub

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    157

    how to use this public sub

    i am starting to get the hang of vb6, but are stuck trying to use this public sub in a class from a form. I am trying to search for a key. i have been able to save to the ini file, but do not know how to use this:
    Code:
    Public Sub EnumerateCurrentSection(ByRef sKey() As String, ByRef iCount As Long)
            Dim sSection As String
            Dim iPos     As Long
            Dim iNextPos As Long
            Dim sCur     As String
       
        iCount = 0
        Erase sKey
        sSection = INISection
        If (Len(sSection) > 0) Then
            iPos = 1
            iNextPos = InStr(iPos, sSection, Chr$(0))
            Do While iNextPos <> 0
                sCur = Mid$(sSection, iPos, (iNextPos - iPos))
                If (sCur <> Chr$(0)) Then
                    iCount = iCount + 1
                    ReDim Preserve sKey(1 To iCount) As String
                    sKey(iCount) = Mid$(sSection, iPos, (iNextPos - iPos))
                    iPos = iNextPos + 1
                    iNextPos = InStr(iPos, sSection, Chr$(0))
                End If
            Loop
        End If
     
    End Sub

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: how to use this public sub

    That sub looks like part of a module or class. Can't really answer your question because that sub depends on some other information. The INISection variable for example appears to be a module-level or public variable that is populated elsewhere.

    I also think that the code may be used for a custom INI file. I say that because the code is looking for Chr$(0) as a delimiter where [ ] symbols would be expected. But of course those could have been replaced with Chr$(0) elsewhere in the original code. Otherwise, you'd have to know the structure of the custom INI to guarantee you understand the routine. And if using APIs to read/write INIs, you don't need manual parsing routines.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: how to use this public sub

    i am using the same ini class I use it like this to get all the keys in a section:
    Code:
    Public Sub EnumerateCurrentSection(ByRef sKey() As String, ByRef iCount As Long)
            Dim sSection As String
            Dim iPos     As Long
            Dim iNextPos As Long
            Dim sCur     As String
        
        iCount = 0
        Erase sKey
        sSection = INISection
        If (Len(sSection) > 0) Then
            iPos = 1
            iNextPos = InStr(iPos, sSection, Chr$(0))
            Do While iNextPos <> 0
                sCur = Mid$(sSection, iPos, (iNextPos - iPos))
                If (sCur <> Chr$(0)) Then
                    iCount = iCount + 1
                    ReDim Preserve sKey(1 To iCount) As String
                    sKey(iCount) = Mid$(sSection, iPos, (iNextPos - iPos))
                    iPos = iNextPos + 1
                    iNextPos = InStr(iPos, sSection, Chr$(0))
                End If
            Loop
        End If
    
    End Sub
    Last edited by isnoend07; Aug 25th, 2009 at 01:10 PM. Reason: posted wrong code
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  4. #4
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: how to use this public sub

    The class also contains this to put the section titles in a combo box
    Code:
    Private Sub FillTemplatesInCombo()  
      Dim asSections() As String, lNoofSections As Long, lIndex As Long
        clsINIFile.EnumerateAllSections asSections, lNoofSections
    
        CboTemplates.Clear
        For lIndex = 1 To lNoofSections
            CboTemplates.AddItem asSections(lIndex)
        Next lIndex
        
    End Sub
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width