|
-
July 22nd, 2008, 11:26 PM
#1
how to read text on text file and store to variable
I need to read a text from a text file and store it to variable and use it as a parameter to pass
rgds
cyrus
-
July 22nd, 2008, 11:57 PM
#2
Re: how to read text on text file and store to variable
This can be done by creating an instance of Scripting.FileSystemObject and using the methods that this object provides. I am attaching a link to the msdn library site for the FileSystemObject. This should point you in the right direction.
http://msdn.microsoft.com/en-us/libr...06(VS.60).aspx
Assigning to a variable and passing the value or reference as a parameter should be easy once you start using the FileSystemObject.
-
July 23rd, 2008, 12:13 AM
#3
Re: how to read text on text file and store to variable
It can be done several different ways. I generally do not use the scripting object. I prefer to use the standard i/o methods when they do the job. Using the standard functions you can read an item, a line, a record [in a fixed length file], x number of bytes starting at y position and of course the entire file.
Are you trying to read a line, a variable or the whole file?
-
July 23rd, 2008, 12:19 AM
#4
Re: how to read text on text file and store to variable
To open a text file and read up to the first crlf [e.g. the first line of text] you would use something like.
Code:
Dim LineFromFile as String
Dim FileHandle as Integer
FileHandle=FreeFile
Open "C:\MyFile.Txt" for input as #FileHandle
Line Input #FileHandle,LineFromFile
Close #FileHandle
-
July 23rd, 2008, 12:34 AM
#5
Re: how to read text on text file and store to variable
DataMiser - Have to agree the standard I/O are nice. I use them for binary/random file access. I just prefer to use the filesystemobject for text files since it provides nice ways of verifying the folder/file exists without getting into error handling routines.
I also find working with the filesystemobject makes my code more readable. But that my just be my experience since I have spent more time with text files then binary/random.
-
July 23rd, 2008, 01:25 AM
#6
Re: how to read text on text file and store to variable
I've been working with Basic since the C64 days and those standard i/o routines have always been there. To me it is the way to go in most cases. The scripting object I have used in web pages and embedded devices where the standard i/o was not available but imo the scripting object is very limiting and has a bit of unneeded overhead,
-
July 23rd, 2008, 10:12 AM
#7
Re: how to read text on text file and store to variable
That is it right there. I am a self taught programmer with about 2 yrs experience. I started with 6.0, so I've always had the object.
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
|