|
-
Oct 7th, 2000, 02:23 PM
#1
Thread Starter
Frenzied Member
Hi,
I know how to open a text file for input but I don't know how to do the following:
I have a text file named data.txt. It is not delimited except for CRLFs at the end of each line.
The start of each line has a number such as:
907
908
909
etc...
What I need to be able to do is to read the complete line in to a variable that starts with 907.
Any help would be appreciated..
DAn
-
Oct 7th, 2000, 02:36 PM
#2
Ex-Super Mod'rater
I don't know!!
I am just putting this here cos I also need to know how to do this.
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Oct 7th, 2000, 04:59 PM
#3
Hyperactive Member
I don't think it's possible to generate a variable at run time after you read it from the file.
Why would you want to do that, anyway?
-
Oct 7th, 2000, 05:12 PM
#4
Addicted Member
Maybe try someting like this:
Private Sub Command1_Click()
Dim tmpVar as String
Open “pathname” For Input As #1
Line Input #1, tmpVar
If LOF(#1) = 193 Then
Text1.text = tmpVar
Else
End Sub
or something to that matter.
-
Oct 8th, 2000, 06:42 AM
#5
Frenzied Member
? it's not that hard at all mateys!!!
Code:
Private Sub Form_Load()
Dim filename As String, fn As Integer, tmp As String
filename = "c:\MYFILE.txt"
fn = FreeFile
'Open the specified file
Open filename For Input As #fn
'Loop it while not end of file
Do While Not (EOF(fn))
'Get the next line
Line Input #fn, tmp
'strip the first 3 characters of it
tmp = Left(tmp, 3)
'Show it in a msgbox
MsgBox tmp
Loop
'Close the specified file
Close
End Sub
But this will only work if the number always consist of 3 numbers.
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Oct 8th, 2000, 07:17 AM
#6
Have a look at this code:
Code:
Dim TheStringArray(1000)
Dim T As Integer
Dim Pos As Integer
Dim TheTestString(1) As String
TheTestString(0) = "907 Hello this is line 907"
TheTestString(1) = "104 Hello this is line onehundred and four"
For T = 0 To UBound(TheTestString)
' Process the line
Pos = Val(Left(TheTestString(T), InStr(TheTestString(T), " ")))
TheStringArray(Pos) = TheTestString(T)
Next T
MsgBox TheStringArray(104)
MsgBox TheStringArray(907)
It ain't that hard, is it?
-
Oct 8th, 2000, 08:14 AM
#7
_______
<?>
[b]RobIII :It ain't that hard, is it?
Jop ? it's not that hard at all mateys!!! [b]
It's no big deal to extract the first number, the split function will do that quite easily. However, none of the above have answered the question.
My answer:
I don't think it is possible to decalare a variable at run time using the extracted string from another variable.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Oct 8th, 2000, 08:19 AM
#8
Frenzied Member
I admit I overlooked that part, in that case HeSaidJoe is right, it's impossible to declare variables at runtime
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Oct 9th, 2000, 09:50 AM
#9
Hyperactive Member
Re: <?>
Originally posted by HeSaidJoe
RobIII :It ain't that hard, is it?
Jop ? it's not that hard at all mateys!!!
It's no big deal to extract the first number, the split function will do that quite easily. However, none of the above have answered the question.
My answer:
I don't think it is possible to decalare a variable at run time using the extracted string from another variable.
I said it first! Though, I may be wrong! (I thought I was wrong once, but I was mistaken.)
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
|