#Edit it no longer overflows, but now it stops saving after it gets to 3, and it skips 2.
Public Sub Save()
Dim cat As String
Dim l As Integer
Dim j As String
cat = "Information"
l = 1
j = ReadPro("Name(" & l & ")")
Do While j <> ""
j = ReadPro("Name(" & l & ")")
l = l + 1
Loop
With Form1
WritePro "Name(" & l & ")", .txtName.Text
WritePro "Home Phone(" & l & ")", .txtHome.Text
WritePro "Cell Phone(" & l & ")", .txtCell.Text
WritePro "E-mail(" & l & ")", .txtEmail.Text
WritePro "Apt/House Number(" & l & ")", .txtApt.Text
WritePro "Street Name(" & l & ")", .txtStreet.Text
WritePro "City(" & l & ")", .txtCity.Text
WritePro "State(" & l & ")", .txtST.Text
WritePro "Area Code(" & l & ")", .txtCode.Text
End With
End Sub
What are you trying to do...
Shouldn't the With Form1....etc be inside the Loop?
I want it to check and see if an entry exist, and if not I want it to create said entry. So no with form1 does not need to be in the loop.
What type of file are you trying to read/write from/to?
And is there any chance you could post your ReadPro function?
[edit]
oops i think i miss read the question, sorry.
Are you trying to carry on checking entrys after you have wrote to an empty one?
(Sorry if im still miss reading it)
I'll try to explain it better since my explination is kind of shitty.
I am making an address book, when I add an entry I want it to add as Username(#) =
this way everytime they add a new entry it doesn't overwrite the origional entry. So I created a loop that checks to see if username(#) exist before writing to it. however when I run my save function this is all that happens
Quote
Name(1)=a
Home Phone(1)=fdg
Cell Phone(1)=dfg
E-mail(1)=fdg
Apt/House Number(1)=dfg
Street Name(1)=fdg
City(1)=fdg
State(1)=fdg
Area Code(1)=dfg
Name(3)=b
Home Phone(3)=fdg
Cell Phone(3)=dfg
E-mail(3)=fdg
Apt/House Number(3)=dfg
Street Name(3)=fdg
City(3)=fdg
State(3)=fdg
Area Code(3)=dfg
#Edit
You asked for the readpro function
Public Function ReadPro(key As String) As String
Dim g As Long
Dim sdefault As String
Dim sdir As String
Dim sUser As String
Dim sname As String
sname = "Information"
sUser = Space$(128)
sdir = App.Path & "\users.ini"
lSize = Len(sUser)
sdefault = ""
g = GetPrivateProfileString(sname, key, sdefault, sUser, lSize, sdir)
sUser = Mid(sUser, 1, InStr(sUser, Chr(0)) - 1)
ReadPro = sUser
End Function
Quote from: Forged on June 20, 2005, 01:44 AM
l = 1
j = ReadPro("Name(" & l & ")")
Do While j <> ""
j = ReadPro("Name(" & l & ")")
l = l + 1
Loop
...
WritePro "Name(" & l & ")", .txtName.Text
Your problem is the l = l + 1.
Enters function: l is 1.
Enters while loop: l is 1.
Continues loop: l is 2.
2 doesn't exist, j is NULL.
Finishes loop: l is 3.
Exits loop with l being 3.
This explains why it keeps stopping on 3, also. Because 2 never exists, it will always exit the loop with l equaling 3.
Edit: On a side note, this could have been solved quickly and simply with some simple debugging skills. Place a breakpoint on the While loop and watch the way L (eww at using l >:() increments. See if you can spot the problem.
Hmm, i think that method for storeing phone book infomation in a ini file would lead to alot of debugging later on.
You could always base a loop on the number of people you have stored in your phone book, wiping out the problem your having at the moment all together.
Somthing abit like this:
Public Function Save(Byval CheckName as string)
Dim Pages as Integer, i as Integer, Checking as String, WroteStuff as Boolean
Pages = ReadPro("Book Size", "TotalPages")
for i = 1 to Pages
Checking = ReadPro("Book Page " & i, "Name")
if Checking = CheckName then
'rewrite this persions info?
'WroteStuff = true?
else
if Checking = "" then 'This space is empty
'save persions info
WroteStuff = true
end if
end if
next i
if WroteStuff = false then
'add persion to existing list
Dim NewWrite as string: NewWrite = "Book Page " & pages + 1
'Add 1 to totalpages for the new entry being added
WritePro "Book Size", "TotalPages", pages + 1
WritePro NewWrite, "Name", Object.text
WritePro NewWrite, "Home Phone", Object.text
'....
End if
end Function
Then in your ini it would be layed out somthing like this:
[Book Size]
TotalPages=5
[Book Page 1]
Name=PersionsName1
Home Phone=fdg
Cell Phone=dfg
E-mail=fdg
Apt/House Number=dfg
Street Name=fdg
City=fdg
State=fdg
Area Code=dfg
[Book Page 2]
Name=PersionsName2
Home Phone=fdg
Cell Phone=dfg
E-mail=fdg
Apt/House Number=dfg
Street Name=fdg
City=fdg
State=fdg
Area Code=dfg
[Book Page 3]
Name=PersionsName3
Home Phone=fdg
Cell Phone=dfg
E-mail=fdg
Apt/House Number=dfg
Street Name=fdg
City=fdg
State=fdg
Area Code=dfg
[Book Page 4]
Name=PersionsName4
Home Phone=fdg
Cell Phone=dfg
E-mail=fdg
Apt/House Number=dfg
Street Name=fdg
City=fdg
State=fdg
Area Code=dfg
[Book Page 5]
Name=PersionsName5
Home Phone=fdg
Cell Phone=dfg
E-mail=fdg
Apt/House Number=dfg
Street Name=fdg
City=fdg
State=fdg
Area Code=dfg
I Expect that would also make it easyer when it comes to removing somone and refreshing the asigned page numbers, or listing them alphbeticly etc.
I typed the above code up in this post, so i havent tested it, it was just to give u an idea of another possible method, altho your current method would probly best sute a txt file.
Thanks a lot both of you.