Results 1 to 8 of 8
  1. #1
    Lounger
    Join Date
    Nov 2007
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    .ini Files problem (Excel 03(VBA))

    Hi All,
    I have another problem, I have a vba program that read and save to an .ini files. When the program launch, it will read from the previous .ini files that has been saved.
    I have added some new textbox in my form. When it reads from a older .ini files, half of the information that was in the form disappear and require input. If i open those files after the upgrade
    it works just fine.
    What can i do to enable the new upgrade and read the old .ini files as well?
    Please advise

    Private Declare Function GetPrivateProfileStringA Lib "Kernel32" (ByVal strSection As String, ByVal strKey As String, ByVal strDefault As String, ByVal strReturnedString As String, ByVal lngSize As Long, ByVal strFileNameName As String) As Long
    Private Declare Function WritePrivateProfileStringA Lib "Kernel32" (ByVal strSection As String, ByVal strKey As String, ByVal strString As String, ByVal strFileNameName As String) As Long

    (here is the get code)
    Public Function GetPrivateProfileString32(ByVal strFileName As String, ByVal strSection As String, ByVal strKey As String, Optional strDefault) As String
    Dim strReturnString As String, lngSize As Long, lngValid As Long
    On Error Resume Next
    If IsMissing(strDefault) Then strDefault = "0"
    strReturnString = Space(1024)
    lngSize = Len(strReturnString)
    lngValid = GetPrivateProfileStringA(strSection, strKey, strDefault, strReturnString, lngSize, strFileName)
    GetPrivateProfileString32 = Left(strReturnString, lngValid)
    On Error GoTo 0
    End Function

    (here is the write code)

    Public Function WritePrivateProfileString32(ByVal strFileName As String, ByVal strSection As String, ByVal strKey As String, ByVal strValue As String) As Boolean
    Dim lngValid As Long
    On Error Resume Next
    lngValid = WritePrivateProfileStringA(strSection, strKey, strValue, strFileName)
    If lngValid > 0 Then WritePrivateProfileString32 = True
    On Error GoTo 0
    End Function

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: .ini Files problem (Excel 03(VBA))

    Those functions do not show how you are populating your UserForm, so this is just a guess. Did you change the sequence of fields in your INI file between the "old" and "new"? Does your code rely on numerically indexed arrays rather than collections with named keys? If so, your code may need to be adapted to the new sequence of fields, or you will get missing or unexpected data.

  3. #3
    Lounger
    Join Date
    Nov 2007
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: .ini Files problem (Excel 03(VBA))

    Hi, I do not have a numbering system going.
    I have naming convention for all the different items.
    I just have named keys for all those.
    when i compared the .ini files (new and old), those 2 looks almost the same. but the new one have 4 extra item in the middle of the file
    and the items after the new items won't show up in the user form.
    Please Advise
    Thanks

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: .ini Files problem (Excel 03(VBA))

    The code that you posted is just the generic code for reading and writing .ini files. You haven't told us how you actually use this, and what the .ini files look like. This makes it impossible (for me at least) to know what causes the problem <img src=/S/sad.gif border=0 alt=sad width=15 height=15>

  5. #5
    Lounger
    Join Date
    Nov 2007
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: .ini Files problem (Excel 03(VBA))

    Thank Hans,
    I guess the question is, Is .ini files reading affected by the position of the text?
    Does the reading of it get effected if the sequence is out of order?
    For example,
    in the .ini files
    [fruit]
    apple = 2
    orange = 4

    to
    [fruit]
    orange= 4
    banana = 1
    apple = 2

    will this affect the reading?

    Thanks

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: .ini Files problem (Excel 03(VBA))

    You still haven't told us how you use the .ini files.

  7. #7
    Lounger
    Join Date
    Nov 2007
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: .ini Files problem (Excel 03(VBA))

    Sorry Hans,
    The ini files is called as soon as the userform is load,
    for example
    (Read)
    TextBoxThcknessatLength.Text = Data.GetPrivateProfileString32(fileName, "secondary", " thickness at length of clip")
    (Write)
    Data.WritePrivateProfileString32 fileName, "secondary", "thickness at length of clip", TextBoxThcknessatLength.Text

    and write when the save button is clicked in the userform

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: .ini Files problem (Excel 03(VBA))

    The order of items within a section doesn't matter when you use an .ini file like this.

Posting Permissions

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