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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Correct syntax for using a variable to contain a TXT file name

Status
Not open for further replies.

kdjonesmtb2

Technical User
Nov 19, 2012
93
US
I want to use a variable to contain a text file name. I want to be able to use multiple table names in a test script

The DataTable is an excel like table that contains parameters that can be utilized in the vbscript

I tried to use the X as a alias for the Datatable - but the txt file is produced with a name of 'X' rather than "qtptestfile2.txt"

Thanks


Dim S1' Variable for custom spacing 1
Dim X 'Variable for Txt file names
S1=Space((DataTable.Value("Custom_spacing1",dtLocalSheet))) ' variable that insert spacing on loop
X= DataTable.Value("TxtFileName",dtGlobalSheet)
ISA_I01_Author_Info_Qualifier = DataTable.Value("ISA_I01_Author_Info_Qualifier", dtGlobalSheet)
Set fso=createobject("Scripting.FileSystemObject")
'Create a non existing file "qtptest.txt " with overwrite option as True
'Set qfile1=fso.CreateTextFile("\\ikanas267\Documents\kgittensjones\My Documents\QTP Test 834\Text files\qtptest1.txt",true,False) ' textname could become a variable so that many could be generated
'Set qfile1=fso.CreateTextFile("\\ikanas267\Documents\kgittensjones\My Documents\QTP Test 834\Text files\ X",true,False) 'this line works but file name is X rather than the assigned Data Table name of QTPTestfile2.txt
Set qfile1=fso.CreateTextFile("\\ikanas267\Documents\kgittensjones\My Documents\QTP Test 834\Text files\ &(DataTable.Value("TxtFileName",dtGlobalSheet)",true,False) ' syntax on this line is giving an error expected ')' added several parenthesis with no luck
qfile1.Write((DataTable.Value("ISA_I01_Author_Info_Qualifier",dtGlobalSheet)
qfile1.Write("*") ' Hardcoded dellimiter
qfile1.Write(S1) & vbcrlf ' carriage return after ISA01 101 line is complete otherwise continue Write statements
qfile1.Writeline((DataTable.Value("Test2",dtGlobalSheet))) 'New line generated - repeat for each new line in 834





















 
What about this?
Set qfile1=fso.CreateTextFile("\\ikanas267\Documents\kgittensjones\My Documents\QTP Test 834\Text files\" & X,true,False)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top