Pegasus [MVP] wrote:
> "James" <jwand
...@lycos.com> wrote in message
>
news:G_Dum.40$3G7.34@newsfe03.iad...
>> With previous help from here I have this script that splits each line into
>> text components using an array. I want to modify the script so it assigns
>> variables to the first text item in the line then assigns variables to the
>> third and following text items. Each line is of variable length like this
>> for example:
>> 123 text 10/23 3/21 5/14
>> 234 txt 01/31
>> 543 text 02/28 05/15
>> I then want the variables inserted into a statement. So for the first
>> line of text there would be three statements:
>> upload data set date=aItem2 where id=aItem1
>> upload data set date=aItem3 where id=aItem1
>> upload data set date=aItem4 where id=aItem1
>> For the second line of text there would be only one statement:
>> upload data set date=aItem2 where id=aItem1
>> I guess I need some looping structure that just picks out the first item
>> in the line, skips the second, then picks the third and more items if
>> there are any. This is my old script:
>> Const csDlm = ","
>> Dim oFS : Set oFS = CreateObject(
>> "Scripting.FileSystemObject" )
>> DIM aComponents
>> DIM aItem1
>> DIM aItem2
>> ' Check that a parameter was given:
>> ' --------------------------------
>> if wscript.arguments.count < 1 then
>> wscript.echo "This script requires 1 filename parameter"
>> wscript.quit 1
>> end if
>> ' Make sure the named file exists:
>> ' -------------------------------
>> strOrigName = wscript.arguments(0)
>> if oFS.FileExists( strOrigName ) = False then
>> wscript.echo "File " & strOrigName & " does not exist!"
>> wscript.quit 2
>> end if
>> ' Construct a copy of the source file name
>> ' --------------------------------------
>> strFolder = oFS.GetParentFolderName( strOrigName )
>> strFileName = oFS.GetFileName( strOrigName )
>> sSrcFSpec = strFolder & "/" & strFileName
>> 'Construct a copy of the destination files
>> '----------------------------------------
>> sDstFSpec = strFolder & "/" & "updateQuery.txt"
>> Set tsDst = oFS.CreateTextFile( sDstFSpec, True )
>> 'Open new temporary text file for processing
>> '--------------------------------------------
>> Set tsSrc = oFS.OpenTextFile(sSrcFSpec)
>> 'Loop through file line by line
>> '-------------------------------
>> Do Until tsSrc.AtEndOfStream
>> Dim sLine : sLine = Trim( tsSrc.ReadLine() )
>> aComponents=split(sLine, csDlm )
>> aItem1=aComponents(0)
>> aItem2=aComponents(1)
>> wscript.echo "String 1 = " & aItem1
>> wscript.echo "String 2 = " & aItem2
>> tsDst.writeline "update employee set employeeid=" & aItem2 & " where id="
>> & aItem2
>> Loop
>> tsSrc.close
>> tsDst.close
> Further to Ekkehard's comments, there are a few minor problems that you need
> to fix, e.g.
> - You specify a comma as a delimiter but your data sample uses spaces.
> - You use forward slashes when constructing your file/folder names but
> Windows requires backslashes.
> - If your data file happens to be in the root of a partition (e.g.
> c:\MyData.txt) then sSrcFSpec and sDstFSpec will end up with two slashes
> like so: \\.
Thanks for the advice. I meant to reply to this earlier. With your
third bit of advice can you suggest how I can modify sSrcFSpec and
sDstFSpec so they don't end up with two slashes ('\\') if the data file
is in the root folder? I explicitly put a slash ('\') in the variables
but is there a way around that?