dimanche 8 mars 2015

VBScript read environment variable in if statement

What changes must I make for the if statement in my code extract below to work as expected?



dim warn, txtfilelocate, txtcontent, file, txtfile, content

call START
sub START
do while len(txtfilelocate) = 0
txtfilelocate = inputbox ("Please enter the full path of the text file containing your email content", "CDO Email Sender")
if isempty(txtfilelocate) then
wscript.quit()
end if
loop
end sub

txtcontent = DQ(txtfilelocate)
wscript.echo txtcontent

set file = createobject("scripting.filesystemobject")

if file.fileexists(txtcontent) then
set txtfile = file.opentextfile(txtcontent, 1)
content = txtfile.readall
wscript.echo content
txtfile.close
call HELLO
else
warn = msgbox(txtcontent & " was not found", 0, "CDO Email Sender")
call START
end if

sub HELLO
wscript.echo "hello"
end sub

function DQ(str)
DQ = chr(34) & str & chr(34)
end function


I suspect it has something to do with expanding environment variables, but as a novice I would appreciate clarification on what I'm doing wrong, and what I should be doing for this to work. Thanks.


Aucun commentaire:

Enregistrer un commentaire