| Description:This exact code is for Saving and Loading 6 listboxes, but it can eaisly be modified to any amount you require. The codes is very well explained With alot tips. Could be useful to some programmers Public Sub Save6ListBoxes(Directory As String, ListA As ListBox, ListB As ListBox, ListC As ListBox, _ ListD As ListBox, ListE As ListBox, ListF As ListBox) Dim SaveLists As Long On Error Resume Next Open Directory$ For Output As #1 For SaveLists& = 0 To ListA.ListCount - 1 Print #1, ListA.List(SaveLists&) & "*" & _ ListB.List(SaveLists) & "*" & _ ListC.List(SaveLists) & "*" & _ ListD.List(SaveLists) & "*" & _ ListE.List(SaveLists) & "*" & _ ListF.List(SaveLists) Next SaveLists& Close #1 End Sub Public Sub Load6ListBoxes(Directory As String, ListA As ListBox, ListB As ListBox, _ ListC As ListBox, ListD As ListBox, ListE As ListBox, ListF As ListBox) 'What I am doing here is first loading the file to a temp string then I parse the data of every line and place them in a array. Next I got thru each line in the array and seperate the parts 'part1 for list1,part2 for list2 ... and so on. Once I got everything parsed I add them to the listbox. This would be accomplished easier if the listboxe's were in fact an array themselve's, but this works fine Dim sData As String, arrLineByLine(999) As String Dim iSpot As Integer, iCount As Integer, iI As Integer Dim iTemp As Integer ' always Declare variables Open Directory$ For Input As #1 ' open file sData$ = Input(LOF(1), #1) ' to temp String Close #1 ' close Do ' start a do/loop, this is where i Get each line iSpot% = InStr(sData$, vbCrLf) ' find chr(13) & chr(10) in the String DoEvents ' just to keep everything moving, you can remove If you like If iSpot% = 0 Then ' if chr(13) & chr(10) or vbcrlf is no longer there then we must have already gotten all the lines arrLineByLine$(iCount%) = sData$ ' add the final line to the array Exit Do ' exit the do/loop Else ' If vbcrlf does exist Then arrLineByLine$(iCount%) = Left$(sData$, iSpot% - 1) ' add each line to the array sData$ = Right$(sData$, Len(sData$) - iSpot% - 1) ' store the rest of the data minus one line each time End If iCount% = iCount% + 1 ' keeps a count For the array Loop For iI% = 0 To iCount% ' start a for/next/loop to go thru each array or line sData$ = arrLineByLine$(iI%) ' set the line to a temp String For iTemp% = 0 To 5 ' start another for/next/loop to parse between "*" DoEvents iSpot% = InStr(sData$, "*") If iSpot% = 0 Then Call ListA.AddItem(sData$) ' here we must have gotten all so we'll End this line and move to the Next Exit For Else ' down here i am just adding the item to the corrosponding lstbox If iTemp% = 0 Then Call ListB.AddItem(Left$(sData$, iSpot% - 1)) If iTemp% = 1 Then Call ListC.AddItem(Left$(sData$, iSpot% - 1)) If iTemp% = 2 Then Call ListD.AddItem(Left$(sData$, iSpot% - 1)) If iTemp% = 3 Then Call ListE.AddItem(Left$(sData$, iSpot% - 1)) If iTemp% = 4 Then Call ListF.AddItem(Left$(sData$, iSpot% - 1)) sData$ = Right$(sData$, Len(sData$) - iSpot%) End If Next iTemp% ' continue the loops until process is complete Next iI% ' and now you have loaded 6 listboxes End Sub I hope you'll take a look at the comments i added it will explain alot of the process and next time you should be able to complete a task like this easily,took me about 5 mins, hope that helps |
Save & Load Multi List Boxes |
Express News India | Freelance ecommerce web development India