Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ranfom txt file 1

Status
Not open for further replies.

philipad

Technical User
Feb 12, 2006
23
CY
hi all...

I have an image that is to be moved to a position according to
some values stored on a text file. The latter has the following form

var left top
1 280 540
2 320 260
3 . .
4 . .
.
.

depending on a variable received from the serial port (1,2,3,...), the program must take the corresping values for the left,top position so the image will move to that position. I don t know how to read this file...
Anyone can help me?

Thanks
 

Take a look at
A. the Open Statement
B. the Scripting FileSystemObject OpenTextFile Method which returns a TextStream object
 
I don't understand...what are this? where?

A. the Open Statement
B. the Scripting FileSystemObject OpenTextFile Method which returns a TextStream object
 
philipad

You do have help installed on your PC, correct?
Hit F1 key and on search tab type those, read carefully, write your code and post back if you find any errors or dead ends!
You could also do a search at Tek-Tips with those keywords. Lots of examples....
 
No I dont have the MSDN... I know how to do it,but I can't write exactly the command with the right format so I get the data in the wrong way. I am looking for someone to tell me the format excactly.
thanks anyway
 
Sub ReadFileToArray()
Dim fso As Object
Dim myFile As Object
Dim AllLines
Dim myFields
Fim lCount As Long

Set fso = CreateObject("Scripting.FileSystemObject")
Set myFile = fso_OpenTextFile("c:\testfile.txt", 1)
AllLines = Split(myFile.ReadAll, vbCrLf)
ReDim myFields(1 To Ubound(AllLines), 1 To 3)
For lCount = 1 To Ubound(AllLines)
ThisLine = Split(AllLines(lCount), vbTab)
myFields(lCount,1) = ThisLine(0)
myFields(lCount,2) = ThisLine(1)
myFields(lCount,3) = ThisLine(2)
Next lCount
myFile.Close
Set myFile = Nothing
Set fso = Nothing
.
.
.

End Sub

This code
Creates a File System Object
Opens the file ("c:\testfile.txt"), for reading
Reads the whole file to an array variable (AllLines) line by line using the CurriageReturnLineFeed for separating them
Creates an 2D array variable (myFields)
For every row of the array variable (AllLines) [line of file],
Cuts it to fields (ThisLine) using the Tab for separating
Passes the 3 fields to the 2D array variable (myFields)
Closes the file
Destroyes it from memory
Destroyes from memory the File System Object.
At that point you have the entire file in the 2D array myFields.

I hope you can go on from there.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top