PDA

Click to See Complete Forum and Search --> : Keeping a Sequential INI File


JazzBass
Nov 21st, 1999, 06:22 PM
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

chrisfricke
Nov 21st, 1999, 06:41 PM
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

JazzBass
Nov 21st, 1999, 07:29 PM
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).]

JazzBass
Nov 21st, 1999, 09:32 PM
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

Nov 21st, 1999, 09:46 PM
Instead of deleting the value overwrite it with *deleted*.



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

Vincent van den Braken
EMail: azzmodan@azzmodan.demon.nl
ICQ: 15440110 (http://www.icq.com/15440110)
Homepage: http://www.azzmodan.demon.nl

JazzBass
Nov 22nd, 1999, 11:22 AM
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

Aaron Young
Nov 22nd, 1999, 11:26 AM
Try:

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
aarony@redwingsoftware.com
adyoung@win.bright.net

JazzBass
Nov 22nd, 1999, 04:36 PM
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).]