Login | |
|
 |
RE: passing variables - 9/17/2007 3:59:17 PM
|
|
 |
|
| |
sheepz
Posts: 247
Score: 2
Joined: 3/17/2006
From: Riverside the 909s
Status: offline
|
i'm not too familiar with Public Sub and it's behavior. could you use a function? something like this: <SCRIPT LANGUAGE="VBScript"> Function viewdata() Dim ts, tl Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile("C:/Documents and Settings/test.txt", ForReading) tl = objTextFile.Readall ts =split(tl, ",") viewdata = ts(0) '<--- Assign return value End Function </script> <table width="100%" border="3" cellspacing="0" cellpadding="0"> <tr> <td width="20%">month</td> <td width="20%">amount</td> <td> </td> <td width="20%">comments</td> <td width="20%"> </td> </tr> <tr> <td><script type="text/vbscript"> document.write viewdata() '<--- Function return value </script></td> <td></td> <td></td> <td> </td> <td> </td> </tr> </table> sounds like the Public Sub should work. i mean it's Public so it sounds like it should be able to pass variables, but maybe we're not passing it correctly... maybe someone can let us know are we using the Public Sub correctly? is it meant for a specific method/function? when would we use a Public Sub?
|
|
| |
|
|
|
 |
RE: passing variables - 9/18/2007 1:21:25 PM
|
|
 |
|
| |
Tin
Posts: 15
Score: 0
Joined: 8/30/2007
Status: offline
|
ok, I did get the function procedure working as well as putting variables outside the sub/function I got it working in both instances. I have been working on adding to the script it all day with many successes but I am stuck I am now reading the text file, and then finding a line in the file. The line of text has 4 words with a delimiter as "," After finding this particular line, place each of the 4 words into 4 different cells within the table. using sheepz example of re-writing the procedure to a function instead of sub, worked fine if I only wish to call the first word in the line of text "viewdata = ts(0)" if there are 4 words in the line of text I wish to call into the tables 4 cells, how would I do this?? here is my latest attempt: <SCRIPT LANGUAGE="VBScript"> ts = 0 Function viewdata(id, comment, month, cost) Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile("C:/Documents and Settings/test.txt", ForReading) Do Dim tl tl = objTextFile.ReadLine Dim ts ts =split(tl, ",") cur_num = ts(0) loop Until cur_num = "2" ts(0) = viewdata(id) ts(1) = viewdata(comment) ts(2) = viewdata(month) ts(1) = viewdata(cost) End Function objTextFile.Close </script> <table width="100%" border="3" cellspacing="0" cellpadding="0"> <tr> <td width="20%">Entry #</td> <td width="20%">month</td> <td width="20%">amount</td> <td width="20%">comments</td> </tr> <tr> <td> <script type="text/vbscript"> document.write viewdata(id) </script></td> <td><script type="text/vbscript"> document.write viewdata(comment) </script></td> <td><script type="text/vbscript"> document.write viewdata(month) </script></td> <td><script type="text/vbscript"> document.write viewdata(cost) </script></td> </tr> </table> <input type="button" id="viewbutton" value="View" name="viewbutton" onClick="viewdata(id, comment, month, cost)">
|
|
| |
|
|
|
 |
RE: passing variables - 9/18/2007 5:08:49 PM
|
|
 |
|
| |
sheepz
Posts: 247
Score: 2
Joined: 3/17/2006
From: Riverside the 909s
Status: offline
|
do you look for a specific line in the text file? or is there only one line? because you dont have a search method your just reading the line: tl = objTextFile.ReadLine Dim ts ts =split(tl, ",") cur_num = ts(0) i dont know how the text file looks like so i commented out the text parts and manually inserted four words with "," as delimiter: <SCRIPT LANGUAGE="VBScript"> Function viewdata() Dim ts, tl Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") 'Set objTextFile = objFSO.OpenTextFile("C:/Documents and Settings/test.txt", ForReading) 'tl = objTextFile.Readall 'ts =split(tl, ",") ts = "pizza,soda,fries,sandwich" '<---- Simulating text line viewdata = ts '<--- Assign return value to function before split End Function </script> <table width="100%" border="3" cellspacing="0" cellpadding="0"> <tr> <td width="20%">month</td> <td width="20%">amount</td> <td> </td> <td width="20%">comments</td> <td width="20%"> </td> </tr> <tr> <td><SCRIPT LANGUAGE="VBScript"> arrParts = Split(viewdata(), ",") '<--- Split Function value document.write arrParts(0) </script></td> <td><script type="text/vbscript"> document.write arrParts(1) '<--- Write split values </script></td> <td><script type="text/vbscript"> document.write arrParts(2) '<--- Write split values </script></td> <td><script type="text/vbscript"> document.write arrParts(3) '<--- Write split values </script></td> </tr> </table> i'm not sure if this is the proper way, just something i use. i'm positive you can do it with the dictionary object, im just not too sure how. hopefully someone can give us an example... hope this helps
|
|
| |
|
|
|
 |
RE: passing variables - 9/19/2007 1:00:57 PM
|
|
 |
|
| |
sheepz
Posts: 247
Score: 2
Joined: 3/17/2006
From: Riverside the 909s
Status: offline
|
okie, i'm not good at hta's at all so here's what i use... it's NOT the correct way, hopefully someone could show us both how to do it properly, but here goes: <SCRIPT LANGUAGE="VBScript"> Function viewdata() Dim ts, tl Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") 'Set objTextFile = objFSO.OpenTextFile("C:/Documents and Settings/test.txt", ForReading) 'tl = objTextFile.Readall 'ts =split(tl, ",") ts = "pizza,soda,fries,sandwich" viewdata = ts '<--- Assign return value to function before split End Function </script> <table width="100%" border="3" cellspacing="0" cellpadding="0"> <tr> <td width="20%">month</td> <td width="20%">amount</td> <td> </td> <td width="20%">comments</td> <td width="20%"> </td> </tr> <tr> <td><SCRIPT LANGUAGE="VBScript"> Sub BtnStart '<--- When user clicks Start, activate split arrParts = Split(viewdata(), ",") '<--- Split Function value HTML = "<table width='100%' border='1'><tr>" & _ '<--- create variable with html table "<td width='20'>" & arrParts(0) & "</td>" & _ "<td width='20'>" & arrParts(1) & "</td>" & _ "<td width='20'>" & arrParts(2) & "</td>" & _ "<td width='20'>" & arrParts(3) & "</td>" & _ "<td width='20'> Empty </td>" window.document.getElementById("dispstatus").innerHTML = HTML & "</table>" '<--- tell it to append to the end of the html End Sub </script></td></tr> <!-- Submit button --> <input type="button" value="Start" onClick="BtnStart"> '<--- Start button that calls Sub BtnStart </table> <span id="dispstatus"></span> '<--- getElementById("dispstatus") needs this, not sure how it works i'm very new to hta's not sure how all the commands work
|
|
| |
|
|
|
 |
RE: passing variables - 9/20/2007 3:39:31 PM
|
|
 |
|
| |
sheepz
Posts: 247
Score: 2
Joined: 3/17/2006
From: Riverside the 909s
Status: offline
|
sorry been really busy at work... theres a way to use the Dictionary Object to display results when user hits the submit button i'm just not sure how... it just occurred to me but is this an .HTML file with vbscript embedded or is this an .HTA? because the syntax will be different... my examples are in HTA, let me know if your using .HTML file... here is a sample of grabbing user input, a string and a number: <html> <head> <title>Grab user input</title> <script language="vbscript"> Sub strOutput Text = window.document.getElementById("strText").value 'Grab text field value MsgBox Text End Sub Sub numOutput Num = cint(window.document.getElementById("iNum").value) 'Grab number field value MsgBox Num End Sub </script> <table> <tr><td> Sample String input <input type="text" id="strText" size="15"></td> <!-- text field --> <td> <input type="button" value="Display Text" onClick="strOutput"></td> </tr> <tr><td> Sample Number input <input type="text" id="iNum" size="15"></td> <!-- number field --> <td> <input type="button" value="Display Number" onClick="numOutput"></td> </tr> </table> </html>
< Message edited by sheepz -- 9/21/2007 12:01:51 PM >
|
|
| |
|
|
|
 |
RE: passing variables - 9/21/2007 2:43:22 PM
|
|
 |
|
| |
Tin
Posts: 15
Score: 0
Joined: 8/30/2007
Status: offline
|
Hi sheepz It's an html file, to answer your question. Would you mind showing me your example in .html I would like to see what it looks like since I am not very familiar with .hta's I also would like to thank you for all your help. You have been the only one who has tried to help me out of several forums. I appreciate it. I find I get the most out of learning by playing with real examples of what I have learned. I have done a lot of reading about vbs, done lots of online walk throughs, but I think it's time to buy a book. Anyway, I did manage to figure out how to get it working, I had to re-write it, but that's fine, it didn't take too long hehe. So here it is, and now I get to expand on it and learn some more. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <body> <script type="text/vbscript"> Sub ctc_onclick Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile("C:/Documents and Settings/test.txt", ForReading) Do Dim ab, sel_line, enterquery, test ab = objTextFile.readLine sel_line = split(ab, ",") test = sel_line(0) enterquery = Document.output_line.whichrecord.value Loop until test = enterquery query_line = sel_line Document.output_line.lineid.Caption = query_line(0) Document.output_line.month.Caption = query_line(2) Document.output_line.amount.Caption = query_line(3) Document.output_line.comments.Caption = query_line(1) objTextFile.Close End Sub </script> <p> </p> <form name="output_line"> <table width="100%" border="3" cellspacing="0" cellpadding="0"> <tr> <td width="20%">Entry #</td> <td width="20%">month</td> <td width="20%">amount</td> <td width="20%">comments</td> </tr> <tr> <td> <OBJECT ID="lineid" WIDTH=100 HEIGHT=24 CLASSID="CLSID:978C9E23-D4B0-11CE-BF2D-00AA003F40D0"> <PARAM NAME="ForeColor" VALUE="0"> <PARAM NAME="BackColor" VALUE="16777215"> <PARAM NAME="Caption" VALUE=""> <PARAM NAME="Size" VALUE="1582;635"> <PARAM NAME="SpecialEffect" VALUE="2"> <PARAM NAME="FontHeight" VALUE="200"> <PARAM NAME="FontCharSet" VALUE="0"> <PARAM NAME="FontPitchAndFamily" VALUE="2"> <PARAM NAME="ParagraphAlign" VALUE="2"> <PARAM NAME="FontWeight" VALUE="0"> </OBJECT></td> <td><OBJECT ID="month" WIDTH=100 HEIGHT=24 CLASSID="CLSID:978C9E23-D4B0-11CE-BF2D-00AA003F40D0"> <PARAM NAME="ForeColor" VALUE="0"> <PARAM NAME="BackColor" VALUE="16777215"> <PARAM NAME="Caption" VALUE=""> <PARAM NAME="Size" VALUE="1582;635"> <PARAM NAME="SpecialEffect" VALUE="2"> <PARAM NAME="FontHeight" VALUE="200"> <PARAM NAME="FontCharSet" VALUE="0"> <PARAM NAME="FontPitchAndFamily" VALUE="2"> <PARAM NAME="ParagraphAlign" VALUE="2"> <PARAM NAME="FontWeight" VALUE="0"> </OBJECT> </td> <td><OBJECT ID="amount" WIDTH=100 HEIGHT=24 CLASSID="CLSID:978C9E23-D4B0-11CE-BF2D-00AA003F40D0"> <PARAM NAME="ForeColor" VALUE="0"> <PARAM NAME="BackColor" VALUE="16777215"> <PARAM NAME="Caption" VALUE=""> <PARAM NAME="Size" VALUE="1582;635"> <PARAM NAME="SpecialEffect" VALUE="2"> <PARAM NAME="FontHeight" VALUE="200"> <PARAM NAME="FontCharSet" VALUE="0"> <PARAM NAME="FontPitchAndFamily" VALUE="2"> <PARAM NAME="ParagraphAlign" VALUE="2"> <PARAM NAME="FontWeight" VALUE="0"> </OBJECT> </td> <td>OBJECT ID="comments" WIDTH=100 HEIGHT=24 CLASSID="CLSID:978C9E23-D4B0-11CE-BF2D-00AA003F40D0"> <PARAM NAME="ForeColor" VALUE="0"> <PARAM NAME="BackColor" VALUE="16777215"> <PARAM NAME="Caption" VALUE=""> <PARAM NAME="Size" VALUE="1582;635"> <PARAM NAME="SpecialEffect" VALUE="2"> <PARAM NAME="FontHeight" VALUE="200"> <PARAM NAME="FontCharSet" VALUE="0"> <PARAM NAME="FontPitchAndFamily" VALUE="2"> <PARAM NAME="ParagraphAlign" VALUE="2"> <PARAM NAME="FontWeight" VALUE="0"> </OBJECT> </td> </tr> </table> <input type="text" name="whichrecord" size="5"> <input type="button" id="viewbutton" value="view" name="ctc" > </form> </body> </html>
|
|
| |
|
|
|
 |
RE: passing variables - 9/21/2007 8:20:59 PM
|
|
 |
|
| |
sheepz
Posts: 247
Score: 2
Joined: 3/17/2006
From: Riverside the 909s
Status: offline
|
yeah i know it's really hard when your just stuck on something and just need a little help. i'm still very new myself, learned a lot from all the admins and members here. they always seem to find time to help others so people like us can learn and grow. thanks to those folks that always help and support. okie we established that your using an .HTML heres a sample for grabbing user input of string and number: <HTML> <HEAD> <TITLE>Grab user input</TITLE> <SCRIPT LANGUAGE="vbscript"> Sub strOutput_OnClick sValue = frmOutput.strText.Value frmOutput.strValue.Value = sValue '<--- pass value into html MsgBox sValue '<--- Sample msg End Sub Sub numOutput_OnClick nValue = cint(frmOutput.iNum.Value) '<--- Cint() to ensure input is numeric frmOutput.numValue.Value = nValue '<--- pass value into html MsgBox nValue '<--- Sample msg End Sub </SCRIPT> </HEAD> <H3>Grab user input</H3> <FORM NAME="frmOutput"> <!-- Name of FORM, used in reference in vbscript above --> <table> <tr><td> Sample String input <input type="text" id="strText" size="15"></td> <!-- text field --> <td> <input type="button" value="Display Text" Name="strOutput"></td> </tr> <tr><td> Sample Number input <input type="text" id="iNum" size="15"></td> <!-- number field --> <td> <input type="button" value="Display Number" Name="numOutput"></td> </tr> </table><br> Textbox for user string input <INPUT TYPE="text" NAME="strValue"><br> <!-- Display STRING field --> Textbox for user number input <INPUT TYPE="text" NAME="numValue"> <!-- Display NUM field --> </FORM> </BODY> </HTML>
|
|
| |
|
|
|
|
|