Writing Quotes in a variable

marcuscoker

Registered User.
Local time
Today, 07:01
Joined
Sep 28, 2005
Messages
49
Hi

I was wondering if anybody could help with this?

I am trying to create a textfile with code in it when a user clicks a button in an access form

Dim fso, myfile, fileText
Set fso = CreateObject("scripting.filesystemobject")
Set myfile = fso.createtextfile("c:\testfile.txt", True)
fileText = "@echo off
cls

echo Multi Asset Generator Script
echo.
echo You need to know the exact Marval Trakit asset classification
echo you will be using before you continue - you also need
echo to know the finance number detail. Ensure this information is
echo known before continuing.
echo ** Be careful typing - typos will cause the script to fail **
echo.

set /p repeats="How Many Assets to generate? >"
set /p category="Trakit Category? >"
set /p majortype="Trakit Major Type? >"
set /p minortype="Trakit Minor Type? >"
set /p startnum="Start Number Suffix From? (eg: for HF0001234 enter '1234') >"
set /p financeno="Finance Number to associate >"
set /p descrip="Description of Asset (eg: 'Dell PC') >"

echo PASS1 Start... (Generating %repeats% assets...)
set trakithome=c:\marvaltest\client
set /A repeats=%repeats%+%startnum%
for /L %%s IN (%startnum%,1,%repeats%) DO \\zurich\servicetest\timport asset /ini=\\zurich\servicetest\trakit.ini /user=system /asset=HF000%%s /description=xtag /category=%category% /major=%majortype% /minor=%minortype%
echo PASS1 Complete.

echo PASS2 Start .. Seeking 'xtag' marked assets and changing their description
echo and associating them with a Finance Record.
\\zurich\servicetest\cmdadmin /ini=\\zurich\servicetest\trakit.ini /update /db=trakit /table=asset /descrip=xtag descrip=#%descrip%# financeno=%financeno%
echo .. Done"
myfile.writeline (fileText)
myfile.Close


Because this code has line breaks and quotes in it, it does not work, but this is what i need to write to the file. Can anybody help?

Thanks

Marcus
 
Putting breaks into the code like you have it is only going to cause compiling errors as the compiler does not know to just automatically goto the next line. Putting quotes within a string expression is as easy as using chr(34) in place of any of your quotes. I would write something like this:

Code:
Dim fso, myfile
Set fso = CreateObject("Scripting.FileSystemObject")
Set myfile = fso.createtextfile("c:\testfile.txt", True)
myfile.writeline ("@echo off")
myfile.writeline ("cls")
myfile.writeline
myfile.writeline ("echo Multi Asset Generator Script")
myfile.writeline ("echo.")
myfile.writeline ("echo You need to know the exact Marval Trakit asset classification")
myfile.writeline ("echo you will be using before you continue - you also need")
myfile.writeline ("echo to know the finance number detail. Ensure this information is")
myfile.writeline ("echo known before continuing.")
myfile.writeline ("echo ** Be careful typing - typos will cause the script to fail **")
myfile.writeline ("echo.")
myfile.writeline
myfile.writeline ("set /p repeats=" & chr(34) & "How Many Assets to generate? >" & chr(34))
myfile.writeline ("set /p category=" & chr(34) & "Trakit Category? >" & chr(34))
myfile.writeline ("set /p majortype=" & chr(34) & "Trakit Major Type? >" & chr(34))
myfile.writeline ("set /p minortype=" & chr(34) & "Trakit Minor Type? >" & chr(34))
myfile.writeline ("set /p startnum=" & chr(34) & "Start Number Suffix From? (eg: for HF0001234 enter '1234') >" & chr(34))
myfile.writeline ("set /p financeno=" & chr(34) & "Finance Number to associate >" & chr(34))
myfile.writeline ("set /p descrip=" & chr(34) & "Description of Asset (eg: 'Dell PC') >" & chr(34))
myfile.Close

Notice that I replaced your double quotes within the strings by concatenating chr(34), which is the character " or double quote. Also notice that to create a line break simply call myfile.writeline without anything after it. That should help you get it straightened out.
 
Many thanks, will try this out
 

Users who are viewing this thread

Back
Top Bottom