|
-
Sep 10th, 2000, 12:58 AM
#1
Thread Starter
Frenzied Member
Say I have a text file with the following contents:
George::John::Megan
Bridget::Mike::Chris
The :: is obviously the delimiter.
I would then want to store each name into an array such
as:
Array(0)
Array(1)
Array(2)
any help would be appreciated..
Dan
-
Sep 10th, 2000, 01:05 AM
#2
Addicted Member
I can help you for the first part:
dim input1 as string
open "c:\windows\file.txt" for input as #1
inputline #1,temp$
input1=temp$
close#1
text1.text=replace(input1,"::",vbcrlf)
now, you have all your stuff in a text box, one name per line..
You juste need to know how to separate the name by line and put in a array...
-
Sep 10th, 2000, 01:33 PM
#3
Lively Member
This will solve your problem....
Code:
Dim arr() As String
Dim strTmp As String
Open "Testfile.txt" For Input As #1
While Not EOF(1)
Line Input #1, strTmp
arr = Split(strTmp, "::")
'Do something about arr array here....
'......
Loop
Close #1
-
Sep 10th, 2000, 02:32 PM
#4
_______
<?>
same as above uses split to build the array
but reads the complete file and not line by line
as the above with line input is only reading one
line and then creating the array.It will continually
overwrite itself.
[code]
'your file must be amended to add :: after each name
George::John::Megan::
Bridget::Mike::Chris::
'
saved as C:\my documents\mytext.txt
'read the complete file instead of line by line
'faster and cleaner
Option Explicit
Private Sub Command1_Click()
Dim sResult as variant 'must be variant
Dim myVar as string
Dim sfile As String, intNum As Integer
intNum = FreeFile
sfile = "C:\my Documents\myfile.txt"
Open sfile For Input As intNum
myVar = StrConv(InputB(LOF(intNum), intNum), vbUnicode)
Close intNum
'
sResult = Split(myVar,"::")
'you now have an array sResult
'
'to check it out
Dim i as Integer
For i = lbound(sResult) to (uBound(sResult)- 1)
Msgbox sResult(i)
Next i
'
End Sub
[/code}
[Edited by HeSaidJoe on 09-10-2000 at 03:43 PM]
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
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
|