-
May 1st, 2012, 04:09 PM
#1
Thread Starter
Addicted Member
[RESOLVED] clock work code =D
Right first of all I hardly use VB and in fact hardly program anymore so excuse me for being, terrible. i will explain what I need to accomplish, might need pen and paper for this one lol. good luck!
There are 4 folders all with 4 .txt documents inside.
Each .txt document has 100 lines.
Each line has 5 separate strings (string,string,string,string,string) hence the
"input #1, URL, Contact, no, no, no".
I need to input all 1600 strings into the program
4 listboxes lstCat1, 2, 3 and 4, these list boxes represent the 4 .txt files in one of the 4 folders. the folder that it reads from will be predetermine by a previous form.
Code:
Dim i As Integer, ii As Integer, iii As Integer
Code:
i = 1
ii = 1
iii = 0
Open (App.Path & "\Company " & i & "\BLCat" & ii & ".txt") For Input As #1
Do
Input #1, URL(iii), CONTACT(iii), SENT(iii), REPLY(iii), BACKLINK(iii)
Me.Controls("lstCat" & ii).AddItem URL(iii)
iii = iii + 1
If iii = 100 Then
iii = 0
ii = ii + 1
End If
If ii = 5 Then
ii = 0
i = i + 1
End If
Loop Until i = 6
Close #1
sorry if i am being vague or none of this makes any sense what so ever but i am very tired typing this please help me!!!!!!
are try to type more sense tomorrow and hopefully code more sense
A subtle thought that is in error may yet give rise to fruitful inquiry that can establish truths of great value. - Isaac Asimov
-
May 1st, 2012, 05:15 PM
#2
Re: clock work code =D
Real quick, assuming each line has five fields separated by four commas
Code:
Dim i As Integer, ii As Integer, iii As Integer
Dim strLine As String
Dim arrSplit() As String
Code:
i = 1
ii = 1
iii = 0
Open (App.Path & "\Company " & i & "\BLCat" & ii & ".txt") For Input As #1
Do
Line Input #1, strLine
arrSplit = Split(strLine, ",")
URL(iii) = arrSplit(0)
CONTACT(iii) = arrSplit(1)
SENT(iii) = arrSplit(2)
REPLY(iii) = arrSplit(3)
BACKLINK(iii) = arrSplit(4)
Me.Controls("lstCat" & ii).AddItem URL(iii)
iii = iii + 1
If iii = 100 Then
iii = 0
ii = ii + 1
End If
If ii = 5 Then
ii = 0
i = i + 1
End If
Loop Until i = 6
Close #1
-
May 2nd, 2012, 01:23 AM
#3
Re: clock work code =D
Shouldn't the Open and Close statements go INSIDE the loop? This way it will open each of the documents in each of the folders.
-
May 2nd, 2012, 01:36 AM
#4
Re: clock work code =D
What about using a couple of For / Next loops ?
Code:
Dim iCompany As Integer
Dim iCat As Integer
Dim iItem As Integer
Dim intFile As Integer
For iCompany = 1 To 4
For iCat = 1 To 4
intFile = FreeFile()
Open (App.Path & "\Company " & iCompany & "\BLCat" & iCat & ".txt") For Input As intFile
Do Until EOF(intFile)
Input #intFile, URL(iItem), CONTACT(iItem), SENT(iItem), REPLY(iItem), BACKLINK(iItem)
Me.Controls("lstCat" & iCat).AddItem URL(iItem)
iItem = iItem + 1
Loop
Close intFile
Next iCat
Next iCompany
Note: This assumes that you've defined URL, CONTACT, SENT, REPLY and BACKLINK as Arrays with 1600 elements ( 0 to 1599)
Last edited by Doogle; May 2nd, 2012 at 01:58 AM.
-
May 5th, 2012, 05:51 AM
#5
Thread Starter
Addicted Member
Re: clock work code =D
Sorry for the late reply I have only just had the time to get back to you guys.
I think its best I start again because I have just realized what I put in the last post and most of it is wrong and not explaining what I need to do, I have also deleted all of the old code just to be sure but as I am now fully alert and not half asleep I might be able to get somewhere with this thing. Forget what I have said in the last post and i will explain again because I tried both of your code snippets and they didn't work. I hope this is much more clear.
Outside the program:
5 folders with a name of ("company name " & number)
Each folder has 4 .txt files called ("BLCat " & number)
In each file is 100 lines of infomation
Each line has 5 separate strings "string1","string2","string3","string4","string5"
What I have on the form (that's important to this):
4 listboxes (lstCat 1, 2, 3 and 4)
So I need VB6 code that will do this on form load:
1) go into folder 1 open BLCat1 input all the strings then BLCat2 do the same.........all the way to folder 5, BLCat4 making 10000 strings inputted into the program, but as there are 4 listboxes representing just 1 folder (each list box being 1 of the .txt files) at some point in the loop the information will be flowing directly into these list boxes, I just want the URL (the first string of each line) to be added to the correct list so lstCat1 = BLCat1, lstCat2 = BLCat2 and so on.
I hope that I have now fully explained my situation please get back to me when you can and if you write code snippets can you please put comments on so that I can better understand what they are doing, like I said I hardly use VB6 or program at all and therefore I am not really good with the syntax but I will understand the logic behind it
A subtle thought that is in error may yet give rise to fruitful inquiry that can establish truths of great value. - Isaac Asimov
-
May 5th, 2012, 12:08 PM
#6
Re: clock work code =D
The code in Post#4 does exactly what you're asking for. Just change the first For loop to
Code:
For iCompany = 1 To 5
And make sure that you've defined the arrays appropriately.
-
May 6th, 2012, 01:47 PM
#7
Thread Starter
Addicted Member
Re: clock work code =D
sorry doogle just being lazy lol. I got it to work perfectly now thank you for the help are make sure to rate ! =]
A subtle thought that is in error may yet give rise to fruitful inquiry that can establish truths of great value. - Isaac Asimov
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
|