Question

I have a Form created in Html and a VBScript to write a file to a Pickup folder for email to a certain address. I want to replace or add to the current fields in the write script with the form data as variables. What VBscript would I use to implement this? I also want the script to be called by a submit button how would I do this?

here is my Form HTML:

<!doctype=html>
<html>
</div>
    <body onload="window.resizeTo(750,800)">
      <div align="left">
<font face="calibri" size="4">
<p><b>Thank you!!</b> …For taking the time to offer your subjects to the senior management via this Stakeholder forum. Please fill out the required information on the front sheet below. Use as many additional sheets as necessary.</p>
<form>
<p>
<fieldset>
<font color="0000FF">1)</font > Date of your submission <font color="grey" size="3">(__/__/20__)</font>:<br> <input type="date" STYLE= "background-color: #FFFF00" name="__/__/20__"><br>
</fieldset>
</p>
<p>
<fieldset>
<font color="0000FF">2)</font> Give Your submission a name: <font color="grey" size="3"> (This can be any inoffensive word or phrase at all… even if it doesn’t relate to the nature of the subject) </font><br>
<input type="text" STYLE= "background-color: #FFFF00" name="Submission Name">
</fieldset>
</p>
<p> 
<fieldset>
<font color="0000FF">3)</font> This Submission includes:<br>
<select>
   <option value="Select..."STYLE= "background-color: #FFFF00">Select...</option>
   <option value="Polite and detailed rant (no proposed solution(s) )" STYLE= "background-color: #FFFF00">Polite and detailed rant (no proposed solution(s) )</option>
   <option value="Problem(s) / area(s) for improvement with proposed solution(s)" STYLE= "background-color: #FFFF00">Problem(s) / area(s) for improvement with proposed solution(s)</option>
   <option value="New Idea(s) / Resurrected old idea(s)" STYLE= "background-color: #FFFF00">New Idea(s) / Resurrected old idea(s)</option>
   <option value="Abstract / Other" STYLE= "background-color: #FFFF00">Abstract / Other</option>
 </select> 
</fieldset>
</p>
<p>
<fieldset>
<font color="0000FF">4)</font> Indicate which areas of our business this submission is connected with… <font color="grey" size="3"> (delete as applicable) </font><br>
<select>
   <option value="Select..."STYLE= "background-color: #FFFF00">Select...</option>
   <option value="Customer / Supplier Aspects"STYLE= "background-color: #FFFF00">Customer / Supplier Aspects</option>
   <option value="Financial Performance" STYLE= "background-color: #FFFF00">Financial Performance</option>
   <option value="Innovation and growth" STYLE= "background-color: #FFFF00">Innovation and growth</option>
   <option value="Internal Business/Systems" STYLE= "background-color: #FFFF00">Internal Business/Systems</option>
 </select> 
</fieldset>
</p>
<p>
<fieldset>
<font color="0000FF">5)</font> Personal Details:<font color="grey" size="3"> (optional) </font><br>
First name: <input type="text" STYLE= "background-color: #FFFF00" name="firstname"><br>
  Last name: <input type="text" STYLE= "background-color: #FFFF00" name="lastname"><br>
   Contact Number: <input type="text" STYLE= "background-color: #FFFF00" name="contactnumber">
</fieldset>
</p>
<p>
<fieldset>
<font color="#0000ff">6)</font> The details of your submission… remembering to avoid:<br>
<ul>
 <li>Cases that are associated with just one single individual. These type of subjects are best dealt with outside of this forum</li>
 <li>Vulgarities and or insults.</li>
 </ul> 
<textarea rows="10" cols="50" col width= "100" STYLE= "background-color: #FFFF00">Dear senior management...
</textarea>

and here is my VBscript for writing to a file:

Set objFSO=CreateObject("Scripting.FileSystemObject")

' How to write file
outFile="\\location\file.txt"
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write "to:email1@mail.com" & vbCrLf
objFile.Write "from:email2@mail.com" & vbCrLf
objFile.Write "subject:This is a test." & vbCrLf
objFile.Write ("") & vbCrLf
objFile.Write "This is the body of the email." & vbCrLf
objFile.Close
Was it helpful?

Solution

There is no simple way for creating multiline strings in VBScript. You have to use string concatenation for this:

form = "<!doctype=html>" & vbNewLine _
  & "<html>" & vbNewLine _
  & "</div>" & vbNewLine _
  & "    <body onload=""window.resizeTo(750,800)"">" & vbNewLine _
  & "      <div align=""left"">" & vbNewLine _
  & "<font face=""calibri"" size=""4"">" & vbNewLine _
  ...

Double quotes inside the strings must be escaped by doubling them (see above). However, this kind of escaping is quite error-prone in my experience. Since HTML allows single quotes around attribute values, using those would be a better option:

form = "<!doctype=html>" & vbNewLine _
  & "<html>" & vbNewLine _
  & "</div>" & vbNewLine _
  & "    <body onload='window.resizeTo(750,800)'>" & vbNewLine _
  & "      <div align='left'>" & vbNewLine _
  & "<font face='calibri' size='4'>" & vbNewLine _
  ...

Or you could read the form HTML code from a template file:

Set fso = CreateObject("Scripting.FileSystemObject")
form = fso.OpenTextFile("C:\path\to\form.txt").ReadAll

With that you can write the form to your output file like this:

objFile.WriteLine form

Side note: instead of using .Write "..." & vbCrLf you could simply use .WriteLine "...".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top