Results 1 to 8 of 8

Thread: Keeping a Sequential INI File

  1. #1

    Thread Starter
    Hyperactive Member JazzBass's Avatar
    Join Date
    Jun 1999
    Posts
    393

    Post

    Hi gang,
    I have a INI file that I use to store registered users. The format is like this:

    [Users]
    user1=Name
    user2=Name
    user3=Name
    user4=Name
    and so on....

    I use a loop to get all the names and loads them into a combo box.
    Now here's the problem. I give the user a option to delete their name. I tried deleting the entire key (user2) and now my loop will stop at user1 and not read the rest of the names.

    I can get the default string to come up as "user deleted" or even write that out to the ini file and it works fine, but I would prefer not to see that in the combo box.

    I downloaded a zip file from Ken Whiteman and he has a routine to delete the null value. I don't quite understand it.

    Could someone please give me some sort of example how I can do what I'm trying to do or if anyone has downloaded that example, could someone explain to me the logic behind it.

    Sorry for the long post. Just wanted to be as clear as possible.

    Thanks,
    JazzBass


    ------------------
    21 yr old beginner VB Programmer
    VB 6 Professional @ Home
    VB 3 Professional @ the Office

  2. #2
    Lively Member
    Join Date
    Jan 1999
    Location
    Lincolnshire, UK
    Posts
    111

    Post

    When you delete a user, instead of removing the entry, try changing the username to something like *DELETED*. When you load the values in to your combo box, add an if statement like
    line input #1,tempstring
    If not (instr(tempstring,"*DELETED*")) then
    combo1.additem tempstring
    end if

    Hope this helps

    Chris

  3. #3

    Thread Starter
    Hyperactive Member JazzBass's Avatar
    Join Date
    Jun 1999
    Posts
    393

    Post

    Chris,
    Thanks a lot. I understand what you mean. One question. Since I'm using the INI API's, I would put the code you suggested in my routine that includes the GetPrivateProfileString without the
    'line input #1'. Is this correct or would I use that also?
    Just making sure.

    Thanks again Chris,
    JazzBass

    If anyone has any other input, please don't hold back.




    [This message has been edited by JazzBass (edited 11-22-1999).]

  4. #4

    Thread Starter
    Hyperactive Member JazzBass's Avatar
    Join Date
    Jun 1999
    Posts
    393

    Post

    Hi gang,

    I've been trying to figure out how to not show "Deleted" in my combo box but I haven't been successful. I'm trying what Chris suggested.

    Here is my code to input all values from my ini file:


    Code:

    Dim lRet As Long
    Dim strbuffer As String
    Dim i As Integer

    i = 1
    Do
    strbuffer = Space(255)
    lRet = GetPrivateProfileString("Users", "user" & CStr(i), "", strbuffer, Len(strbuffer), "C:\MyFile.ini")

    If lRet Then

    user = strbuffer

    cmbCheck.AddItem user


    End If
    i = i + 1
    Loop While lRet > 0

    end sub


    What do I need to add to this code to not add "Deleted" to the combo box?
    Please help.

    Thanks,
    JazzBass

    ------------------
    21 yr old beginner VB Programmer
    VB 6 Professional @ Home
    VB 3 Professional @ the Office

  5. #5
    Guest

    Post

    Instead of deleting the value overwrite it with *deleted*.



    ------------------

    Vincent van den Braken
    EMail: [email protected]
    ICQ: 15440110
    Homepage: http://www.azzmodan.demon.nl




  6. #6

    Thread Starter
    Hyperactive Member JazzBass's Avatar
    Join Date
    Jun 1999
    Posts
    393

    Post

    Azzmodan,
    Thanks. Yeah, that's what I've been doing, but if I can help it, I don't want to display "Deleted" in my combo box.

    How can I delete a combo box value (Possible multiple occurances if more than one user is deleted) if I know what the string is, but don't know the list index?

    Please keep the suggestions coming.

    Thanks,
    JazzBass

  7. #7
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Try:
    Code:
    Private Sub Command1_Click()
        Dim lRet As Long
        Dim sBuff As String * 255
        Dim sUser As String
        Dim I As Integer
        
        While GetPrivateProfileString("Users", "user" & CStr(I + 1), "", sBuff, 255, "C:\MyFile.ini")
            sUser = Left(sBuff, InStr(sBuff, Chr(0)) - 1)
            If sUser <> "Deleted" Then cmbCheck.AddItem sUser
            I = I + 1
        Wend
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  8. #8

    Thread Starter
    Hyperactive Member JazzBass's Avatar
    Join Date
    Jun 1999
    Posts
    393

    Post

    Aaron,
    Thanks so much. That's exactly what I needed. I'm glad it works because it puts and smile on my face and it got me in a better mode from yesterday (wound up changing a flat tire in the snow. Not fun )
    Anyway, thanks again Aaron and all who offered suggestions.
    Now I need to spend some time figuring out how the code works. Can we say research?
    Thanks,
    JazzBass

    [This message has been edited by JazzBass (edited 11-23-1999).]

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