Text File to Variable....? 
Author Message
 Text File to Variable....?

Hi I need to pass the entire contents of a text file to a variable.  Will I
have to use FileSystemObject or is there an easier way, say a client side
include to variable?  I can't use ASP tags for this.  It has to be run on
the client.

Thanks in Advance!

Paul Robinson

Tue, 16 Jul 2002 03:00:00 GMT  
 Text File to Variable....?
Hi Paul, try this tiny script.

    Rem ----------------------------------------------------
    Rem asciiwrite.vbs
    Rem VB6-Notation
    Rem Option Explicit, Option Base 1, Option Compare
    Rem DefInt  I, DefLng  L, DefSng S, DefDbl  D, (DefDec
E), DefCur M, DefByte Y
    Rem DefStr  C, DefDate J, DefVar V, DefBool B, DefObj O
 '  Options
    Option Explicit

 '  Declarations
OWSHobj1                                          ' Object-
    Private Const Ofso1
= "Scripting.FileSystemObject"          ' WSH-Class

 '  Declarations for the textfile to be read
    Private Const Cfsoname1 = "d:\vbsprogramme1
\vbsapi\adr1a.txt"   ' FileSpec
Ofile1                                            ' Object-
    Private Const Iread1    =
1                                     ' ForReading
    Private Const Istate1   =
0                                     ' TriStateFalse
    Private       Cline1
    Rem ----------------------------------------------------
 '  Main BEG
read_ascii1                                              '
Sub 1
delete_objects1                                          '
Sub 2
 '  Main END
    Rem ----------------------------------------------------
    Private Sub read_ascii1()
      Set OWSHobj1          = CreateObject
 '    Creating and opening an ASCII-file in one step
      Set Ofile1            = OWSHobj1.OpenTextFile
(Cfsoname1, Iread1, Istate1)
        Cline1              = Cline1 & Ofile1.ReadLine()
      Loop Until Ofile1.atEndofStream
    End sub
    Msgbox Cline1
    Rem ----------------------------------------------------
    Private Sub delete_objects1()
      Set Ofile1            = Nothing
      Set OWSHobj1          = Nothing
    End sub
    Rem ----------------------------------------------------

* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping.  Smart is Beautiful

Tue, 16 Jul 2002 03:00:00 GMT  
 [ 2 post ] 

 Relevant Pages 

1. load contents of remote text file into variable

2. Set a text file as variable value

3. Read lines from a text file into variables

4. Better Way to Read Text File into Variables?

5. Is it possible to read a text file with variable number of columns ?

6. Reading text from a text file into a variable

7. ** File I/O ** Need help reading text file into String variable

8. Storing content from an external text file in a variable

9. How to assign variables to a text file?

10. Writing Variable Values to Text Files

11. TextStream Object, passing an opened text file to a variable

12. How Do I Read a Text File into a Variable


Powered by phpBB® Forum Software