|
-
Dec 3rd, 2005, 06:45 PM
#1
Thread Starter
Addicted Member
ini file and listbox
i have 3 textboxes and a listbox, i can write to an ini file with the textbox information. Now i need to know how i can write the the same ini file with the listbox data. So in the end, on the ini file, there should be the 3 textboxes' data and after that data, there should be the listbox data. Then i would also need to know how to display all the info when the program is ran again.
thanx all
-
Dec 3rd, 2005, 07:49 PM
#2
Re: ini file and listbox
Write the data to the ini file
VB Code:
Dim lngIndex As Long
Dim strData As String
For lngIndex = 0 To List1.ListCount - 1
' If a semicolon can be in the data then use a different character or characters
strData = strData & ";" & List1.List(lngIndex)
Next
' get rid of the 1st semicolon
strData = Mid$(strData, 2)
Get it back
VB Code:
Dim strParts() As String
Dim lngIndex As Long
Dim strData As String
strParts = Split(strData, ";")
For lngIndex = 0 To UBound(strParts)
List1.AddItem strParts(lngIndex)
Next
-
Dec 3rd, 2005, 10:31 PM
#3
Thread Starter
Addicted Member
Re: ini file and listbox
i got it working and there are no errors, but, it doesnt seem to want to put all the data in the listbox, sumtimes 3 lines, sumtimes 2.
Last edited by Ch4s3t0ph3r; Dec 10th, 2006 at 01:13 PM.
-
Dec 3rd, 2005, 11:00 PM
#4
Re: ini file and listbox
Can you post the code you are using to write the data to the ini file and to get it back?
-
Dec 3rd, 2005, 11:08 PM
#5
Thread Starter
Addicted Member
Re: ini file and listbox
VB Code:
Sub ReadIni()
Dim strParts() As String
Dim lngIndex As Long
Dim strData As String
inifile = "C:\file\" & Text18.Text & ".ini"
strData = GetIni("Items", "#18")
strParts = Split(strData, ";")
For lngIndex = 0 To UBound(strParts)
List1.AddItem strParts(lngIndex)
Next
End Sub
VB Code:
Private Sub Command1_Click()
ReadIni
End Sub
Last edited by Ch4s3t0ph3r; Dec 10th, 2006 at 01:13 PM.
-
Dec 3rd, 2005, 11:18 PM
#6
Re: ini file and listbox
What about to write the data?
-
Dec 3rd, 2005, 11:50 PM
#7
Thread Starter
Addicted Member
Re: ini file and listbox
VB Code:
Private Sub mnuSave_Click()
Open "C:\file\" & Text27.Text & ".ini" For Output As #1
Dim lngIndex As Long
Dim strData As String
For lngIndex = 0 To List1.ListCount - 1
' If a semicolon can be in the data then use a different character or characters
strData = strData & ";" & List1.List(lngIndex)
Next
' get rid of the 1st semicolon
strData = Mid$(strData, 2)
Print #1, "[Items]"
Print #1, "#18 ="; strData
Close #1
End Sub
and there are no other semicolons in the data im using
Last edited by Ch4s3t0ph3r; Dec 10th, 2006 at 01:13 PM.
-
Dec 3rd, 2005, 11:57 PM
#8
Re: ini file and listbox
It looks like you are reading from and writing to different files.
-
Dec 4th, 2005, 12:04 AM
#9
Re: ini file and listbox
Use this to get rid of the last semicolon:
VB Code:
strData = Left(strData, Len(strData) - 1)
The MID() statement is deleting most of the data
VB Code:
Option Explicit
Private Sub Form_Load()
Dim x As Integer, str$
For x = 0 To 3
List1.AddItem x * 7
Next x
For x = 0 To List1.ListCount - 1
str = str & List1.List(x) & ";"
Next x
MsgBox str
str = Left(str, Len(str) - 1)
MsgBox str
End Sub
Last edited by dglienna; Dec 4th, 2005 at 12:07 AM.
-
Dec 4th, 2005, 12:34 AM
#10
Thread Starter
Addicted Member
Re: ini file and listbox
 Originally Posted by dglienna
VB Code:
Option Explicit
Private Sub Form_Load()
Dim x As Integer, str$
For x = 0 To 3
List1.AddItem x * 7
Next x
For x = 0 To List1.ListCount - 1
str = str & List1.List(x) & ";"
Next x
MsgBox str
str = Left(str, Len(str) - 1)
MsgBox str
End Sub
im not understanding what that is for or where to put it, i did for forget to mention that i am taking info from one form and this is saved to the ini, then it can only be viewable on form2 which has the same setup and it all works but the only thing is that the listbox doesnt recieve all the info that is in the ini file
-
Dec 4th, 2005, 12:44 AM
#11
Re: ini file and listbox
 Originally Posted by dglienna
Use this to get rid of the last semicolon:
VB Code:
strData = Left(strData, Len(strData) - 1)
The MID() statement is deleting most of the data
VB Code:
Option Explicit
Private Sub Form_Load()
Dim x As Integer, str$
For x = 0 To 3
List1.AddItem x * 7
Next x
For x = 0 To List1.ListCount - 1
str = str & List1.List(x) & ";"
Next x
MsgBox str
str = Left(str, Len(str) - 1)
MsgBox str
End Sub
In my code and the code that Ch4s3t0ph3r showed that he was using the "extra" semicolon is placed first, not last, and the Mid statement grabs everything except the first character (the "extra" semicolon).
-
Dec 4th, 2005, 12:45 AM
#12
Re: ini file and listbox
That's just the sample that I whipped up, which cut off a lot of the information when I used the MID() statement that you had, so I changed it around, then added the correction for your form.
If you paste that code into a new project, and run it, you will see that it works correctly. All items are displayed.
You can use Form2.Text1.text from Form1 to get the value.
-
Dec 4th, 2005, 12:46 AM
#13
Re: ini file and listbox
 Originally Posted by dglienna
That's just the sample that I whipped up, which cut off a lot of the information when I used the MID() statement that you had, so I changed it around, then added the correction for your form.
If you paste that code into a new project, and run it, you will see that it works correctly. All items are displayed.
You can use Form2.Text1.text from Form1 to get the value.
So does mine if you had bothered to try it.
-
Dec 4th, 2005, 12:58 AM
#14
Re: ini file and listbox
I typed it in wrong. When I tried the mid statement, it messed up my data, so I used left. I added the ";" to the end, and removed it. You added ";" at the beginning of the data, and the Mid() would have worked.
I assumed that Ch4s3t0ph3r did try it, though.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|