Not even sure if this is possible.....but

Results 1 to 2 of 2

Thread: Not even sure if this is possible.....but

  1. #1
    Join Date
    Dec 1969

    Default Not even sure if this is possible.....but

    I am parsing a text file that is composed of name value pairs, such as:<BR>Name: SomeName<BR>Age: SomeAge<BR>height: 5&#039;9"<BR>Is there anyway to automatically create variables as I parse the file, so that I could just access the value by doing something like:<BR>response.write age<BR>I am trying to avoid having to parse each line of the file with InStr and having to hardcode all the possible name/value pairs.....Or could I create some complex multi-dimensional array?<BR><BR>Thanks!

  2. #2
    Join Date
    Dec 1969

    Default Can be done but bad idea...

    You could look into using VBScrip&#039;s "EXECUTE" statement. (Or "Execute Global".)<BR><BR>But this is a VERY slow way of doing processing. Each EXECUTE has to drop you into a *new* instance of the VBScript compiler, compile to byte code, execute the byte code, and then return back to the context you were previously in. Shudder.<BR><BR>Better would be to use a Scripting.Dictionary object:<BR><BR>&#060;%<BR>Set info = Server.CreateObject("Scripting.Dictionary")<BR>Set FSO = Server.CreateObject("Scripting.FileSystemObject")< BR>Set infile = FSO.OpenTextFile( ... )<BR><BR>Do Until infile.AtEndOfStream<BR> pair = Split( infile.readLine, ":" )<BR> theKey = LCase( Trim( pair(0) ) )<BR> theValue = Trim( pair(1) )<BR> info.Add theKey, theValue<BR>Loop<BR>%&#062;<BR><BR>After that, you can get data from the "info" dictionary by doing<BR> Response.Write info("age")<BR> Response.Write info("height")<BR> etc.<BR><BR>Essentially, you end up treating the dictionary object just as you would a Request.Form or perhaps Recordset object.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts