Load file into array

andy99
04-14-2003, 01:36 PM
I have a list box on my form and when an item is selected it shows certain text in the text box.
What I am not sure about doing is loading the file into an array first.
The file is as follows:
Line Of Text 1
Line Of Text 2
'
Line Of Text 3
Line Of Text 4

Line Of Text5
'
Line Of Text 6
etc

I want it so when the text is shown in the text box it still shows as 2 or 3 lines and the empty line is included in the string. All the data for each element of the array is seperated by an apostrophe.
I have worked out what I think I should be doing, but I'm not quite sure how to quite get there.

Open App.Path & "GradingAikido.txt" For Input As #filenum
'...load whole file into one long string
Strwords =

Do Until EOF(filenum)
'...split at each apostrophe
tmpstrwords =
'...load into array element
aikido(ctr) =
'...set new last position
lastpos =
'...empty temp string
tmpStrWords = ""
End

Close #filenum

Flyguy
04-14-2003, 03:22 PM
You can load the complete text file in a big string and by using the Split() function create an array of strings.

andy99
04-14-2003, 08:40 PM
You can load the complete text file in a big string and by using the Split() function create an array of strings.
How do I do this?
Is what I have above along the right lines?

starbitz
04-14-2003, 09:58 PM
How do I do this?
Is what I have above along the right lines?
Maybe you could use this:
Dim sFile as String
Dim aStrings() as string
Dim Filenum as integer
Filenum = Freefile
Open App.Path & "GradingAikido.txt" For Input As FileNum
sFile = Input(LOF(FileNum), FileNum) 'save the whole file to sFile
Close FileNum
aStrings = Split(sFile, " ") 'Split the contents of the file separated by space and saved each word to aString array
'You can then loop through aStrings.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum