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

How do u pass a variable(not just a value) to a file ??

Status
Not open for further replies.

mijulie

Programmer
Jun 21, 2001
36
0
0
IE
This is my page below. I want the value entered for Binary to show up in the text file but when i hit the Save button, the only thing that shows up is this;

[object]

Does anybody know the correct syntax or have any idea what i'm doing wrong?

<HTML>
<HEAD>
<H1><CENTER>BUILD VALIDATION</CENTER></H1>
</HEAD>
<BODY>
<P>


<CENTER>Please provide the following information, then click Save: </CENTER>
<P>
<B>Binary: </B><INPUT NAME=&quot;strBinary&quot; SIZE=&quot;12&quot;> &nbsp;<B>Build No: </B><INPUT NAME=&quot;Build&quot;

SIZE=&quot;10&quot;>

<P>
<B>Test A/C: </B><INPUT NAME=&quot;Test&quot; SIZE=&quot;10&quot;> &nbsp;<B>Date: </B><INPUT NAME=&quot;Date&quot; SIZE=&quot;12&quot;>
<P>
<script language=vbscript>


Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
sub b1_onclick
set f1=fso.CreateTextFile(&quot;c:\new.txt&quot;,true)
f1.WriteLine strBinary
f1.close
end sub
</script>
<INPUT type=&quot;button&quot; value=&quot;SAVE&quot; id=b1 name=b1>
</BODY>
</HTML>
 
f1.WriteLine document.all.strBinary.value

or

.text

Is going to be the IE solution. And since you are using client side vbscript, I think it's safe to assume that this doesn't need to work in NS.

You can also refer to it like this:

document.formName.strBinary.value or .text

Replacing formName with the actual name of the form that the element is a member of. Now by me saying .value or .text, I'm not saying that both will work, I'm saying I don't use client side vbscript, so I'm not sure which it is, but I am sure it's one of them. ;-)

good luck
Paul Prewett
penny.gif
penny.gif
 
Thanks for that, i think i figured it out. I got it to output Binary and Build values one line after another. I now want to be able to append to the file so that when the Form is filled again and again it won't erase the previous results. Is there much of a differencce in the command(s)?
Once i have this sorted i will be very happy. It'll be a load off my mind!!
 
I should have included this code to show u exactly what i have done

<HTML>
<HEAD>
<H1>Build Validation</H1>
<SCRIPT LANGUAGE=&quot;VBSCRIPT&quot;>
<!--
Function BuildForm_OnSubmit()
Dim BadData
'copy bad data to hidden objects
If BuildForm.TheBinary.Value = &quot; &quot; Then BadData = True
If BuildForm.TheBuild.Value = &quot; &quot; Then BadData = True
If BadData Then
MsgBox &quot;Bad data&quot;
BuildForm_OnSubmit = False
Else
MsgBox &quot;Thanks for submitting the correct data&quot;
BuildForm_OnSubmit = True
End If
End Function
Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
sub b1_onclick
set f1=fso.CreateTextFile(&quot;c:\new.txt&quot;,true)
f1.WriteLine BuildForm.TheBinary.Value
f1.WriteLine BuildForm.TheBuild.Value
f1.close
end sub


-->
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME=BuildForm>
Binary:
<BR>
<INPUT TYPE = TEXT
Name=Thebinary SIZE=15>
<BR>
Build:
<BR>
<INPUT TYPE = TEXT
Name=TheBuild SIZE=15>
<BR>
<INPUT type=&quot;button&quot; value=&quot;SAVE&quot; id=b1 name=b1>
</FORM>
</BODY>
</HTML>

Mijulie
 
Not much difference. Mostly, it's in the way that you open the file (i.e. for writing, appending, etc...)

If you haven't already seen it, check this site out:

and specifically:


is their vbscript quick reference guide. I must recommend this site five times a week. ;-) It's the best quick ref site out there. Look at their fileSystemObject part in the index for vbscript, and it will have all the information you need about working with text files.

:)
Paul Prewett
penny.gif
penny.gif
 
Thanks for all your help. It's working perfectly now, i can append to an existing file no problem!! Won't be bothering you anymore, much appreciated!!

Mijulie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top