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

Input Number return info for html display(in HTML forum too)

Status
Not open for further replies.

chaznbs

IS-IT--Management
Jun 5, 2015
23
US
I guess someone thinks this may belong here versus HTML forums. I highlight the section I am having trouble with

I have included my html code for many other eyes to help me figure this out.

Javascript works. One side by on_click and other side by on_change.

Issue is when calling my vbscript.

This is a modified version of a working script that just displayed some data a client wanted to see, but now they want to calculate it.

I think I am pretty close but my mind is just so burnt that I could you some helpful advise as to what I am missing.

Thank you
CHAZ



<HTML>
<HEAD><TITLE>Simple Validation</TITLE>
<style type="text/css">
input { float: center; }
</style>

<script type="text/javascript">

function Mcalc(){
PRC = 0
AVG = 0

if (document.MARGIN.PPrice.value > "")
{ PRC = document.MARGIN.PPrice.value };
document.MARGIN.PPrice.value = eval(PRC);

if (document.MARGIN.AvgCost.value > "")
{ AVG = document.MARGIN.AvgCost.value };
document.MARGIN.AvgCost.value = eval(AVG);

MRG = (PRC - AVG) / PRC * 100;

document.MARGIN.NMargin.value = dm(eval(MRG));
}

function Pcalc(){
MRG = 0
AVG = 0

if (document.MARGIN.PMargin.value > "")
{ MRG = document.MARGIN.PMargin.value };
document.MARGIN.PMargin.value = eval(MRG);

if (document.MARGIN.AvgCost.value > "")
{ AVG = document.MARGIN.AvgCost.value };
document.MARGIN.AvgCost.value = eval(AVG);

PRC = AVG/(1-MRG/100);

document.MARGIN.NPrice.value = dm(eval(PRC));
}

function dm(amount) {
string = "" + amount;
dec = string.length - string.indexOf('.');
if (string.indexOf('.') == -1)
return string + '.00';
if (dec == 1)
return string + '00';
if (dec == 2)
return string + '0';
if (dec > 3)
return string.substring(0,string.length-dec+3);
return string;
}
</script>


</HEAD>
<BODY onLoad="document.MARGIN.txtItem.focus()">

[highlight #FCAF3E]<script language="vbscript" type="text/vbscript">
Function RETRIEVE()

dim dbconnection, sqlrs, itemno, ITEM

Const CONNECT_STRING = "provider=SQLOLEDB.1;Presist Security info=True;User ID=sa;Initial Catalog=DEMODATA;Data Source=SERVER;password=PASSWORD"

Set WshShell = WScript.CreateObject("WScript.Shell")
set objFSO = CreateObject("Scripting.FileSystemObject")
Set dbconnection = createobject("ADODB.connection")
Set sqlrs = createobject("ADODB.Recordset")

dbconnection.open CONNECT_STRING

Itemno = document.MARGIN.txtItem.value

sqlrs.open "SELECT * FROM [VI_USR_MARGIN] where ITEM_NO = '"&Itemno&"' AND LOC_ID='MAIN'", CONNECT_STRING
If sqlrs.EOF Then
Wscript.Echo "Invalid Item. Please Re-Enter."
Else
document.MARGIN.Description.value = sqlrs("DESCR")
document.MARGIN.AvgCost.value = sqlrs("AVG_COST")
document.MARGIN.Price.value = sqlrs("PRC_1")
document.MARGIN.Margin.value = sqlrs("MARGIN")
END IF

sqlrs.close
dbconnection.close

End Function
</script>[/highlight]


<H3>Margin Calculator</H3><HR>
<FORM method=post action='' NAME="MARGIN">
<table>
<tr>
<td align="left">Item Number:</td>
<td align="left"><INPUT NAME="txtItem" TYPE="TEXT" SIZE="10" autofocus></td>
<td align="left">Item Description: </td>
<td align="left"><INPUT NAME="DESCRIPTION" TYPE="TEXT" SIZE="30" readonly tabindex="-1"></td>
</tr>

<tr>
[highlight #FCAF3E]<td align="left"><INPUT TYPE="BUTTON" VALUE="Retrieve Item" onclick ="call RETRIEVE()"></td>[/highlight]
<td align="left"> </td>
<td align="left">Average Cost: </td>
<!-- <td align="left"><INPUT NAME="AvgCost" TYPE="TEXT" SIZE="10" readonly tabindex="-1" ></td> -->
<td align="left"><INPUT NAME="AvgCost" TYPE="TEXT" SIZE="10"></td>
</tr>

<tr>
<td align="left"><BR> </td>
</tr>

<tr>
<td align="left">Current Price: </td>
<td align="left"><INPUT NAME="Price" TYPE="TEXT" SIZE="10" readonly tabindex="-1"></td>
<td align="left">Current Margin: </td>
<td align="left"><INPUT NAME="Margin" TYPE="TEXT" SIZE="10" readonly tabindex="-1"></td>
</tr>

<tr>
<td align="left"><BR> </td>
</tr>

<tr>
<td align="left">Proposed Price: </td>
<td align="left"><INPUT NAME="PPrice" TYPE="TEXT" SIZE="10" onchange="Mcalc()"></td>
<td align="left">Proposed Margin: </td>
<td align="left"><INPUT NAME="PMargin" TYPE="TEXT" SIZE="10"></td>
</tr>

<tr>
<td align="left"></td>
<td align="left"><INPUT TYPE="BUTTON" VALUE="Calc New Margin" onclick ="Mcalc()" ></td>
<td align="left"></td>
<td align="left"><INPUT TYPE="BUTTON" VALUE="Calc New Price" onclick ="Pcalc()" ></td>
</tr>

<tr>
<td align="left"><BR> <BR></td>
</tr>

<tr>
<td align="left">New Margin: </td>
<td align="left"><INPUT NAME="NMargin" TYPE="TEXT" SIZE="10" readonly tabindex="-1"></td>
<td align="left">New Price: </td>
<td align="left"><INPUT NAME="NPrice" TYPE="TEXT" SIZE="10" readonly tabindex="-1"></td>
</tr>

<tr>
<td align="left"><BR> <BR><BR></td>
</tr>

<tr>
<td align="left"><INPUT TYPE="RESET" STYLE="width:100" VALUE="Clear Form" onclick="document.MARGIN.txtItem.focus()"></td>
<td align="left"><INPUT TYPE="BUTTON" STYLE="width:100" VALUE="Copy Data" onclick="document.MARGIN.txtNPrice.select()"></td>
<td align="left">&nbsp; </td>
<td align="left">&nbsp; </td>
<td align="left"><INPUT TYPE="BUTTON" STYLE="width:100" VALUE="Exit" onclick="self.close()"></td>
</tr>
</table>


</FORM>
</BODY>
</HTML>
 
What exactly are you trying to do?

Because you have a mish-mash of incompatible script languages.

vBScript can only run as a script language (<script type="text/vbscript> ... </script> ) in Internet Explorer (upto IE10), no other browsers support vbscript.

.vbs script files only be run in the desktop context, it can connect to local or remote database servers, provided the appropriate drivers are installed on the machine.

javascript runs in a HTTP: (browser) context only and cannot connect directly to database servers.

Beither javascript or vbscript running in a HTTP context in a client browser can access the local filing system or local database servers.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Ugh the horror story...

I work on POS systems and a client is asking for a margin calc so his sales people can find current margin and determine new prices and margins within limits.

So my first go'round was easy. I wrote a quick vbsscript to pull the data from sql but they wanted it to calculate on the fly and be easier to read.

Thinking, thinking... Ahh HTML to enter and display everything. Mind you I know nothing of html but that was my thought. Created basic form in a couple hours till I liked it.

That is when the programming issues started. Our HTML "expert" said just drop your vbs code into the script tags. BOOM!!!! Then he said rewrite in Javascript. HUH? I am a hardware networking guy, not a programmers

So I didnt give up on trying to get this to work even thought I knew nothing about these languages. I have tried just haven't found good solution on the net so I can here to the brains.

Today I started alittle re-writing. I took vbs out of the html after what you posted last nite. so the vbs runs in file form and it works for reading input file and creating results file from sql data. Thank you.

Now the rest of it is javascript issues to write the file based on item number and read the results to display in fixed fields on the html form.
 
Off the top of my head, you could probably use VBScript to create a htm or HTA document with the javascript values added to a template file then pass the path to a browser using the file://// protocol.



Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
chaznbs said:
My test code for funtion work if run as a vbs file
...
As soon as I use it inside the html file I get nothing. No error in IE either when I f12 it.
Alhough, I have long experience working with databases using several scripting languages (like Perl, Python, Rexx, Ruby, Tcl, Lua, VbScript), but everytime I have only done it as a standalone script, not in a web in browser.
Therefore, I couldn't imagine how it's possible that in your case the Vbscript runs succesfull as a standalone script, but fails inside of a html page. Maybe I could try an similar example at my work and report here later ...

 
Maybe I could try an similar example at my work and report here later ...
We can save you the trouble there;

Browsers only have a javascript engine, ONLY Internet Explorer pre v11 has a script engine that has a basic interpreter.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
ok, how about this then...

I modified my script to read from for input and create an output file for results.

Is there script that will work in the html form to create the input file(only needs to contain the txtItem field) and then read the results file to input into my description, average cost, price and margin fields?

This way I can pass the data I need instead of trying to do it right in the html form. Should I be asking this part on the html forum?

 
chaznbs said:
I know its a VBS forum but is there a way to get it to work in javascript?
Yes it will work with JScript only on Windows.

Look, I have in my DB/2 on IBM iSeries (ak AS/400) a table IBPDDB.R000270V and want to get a field AKTSALDDAT.

First I created a little Jscript example:

aktsalddat.js
Code:
[COLOR=#0000ff]//#########################################[/color]
[COLOR=#0000ff]// Reading records and fields from database[/color]
[COLOR=#0000ff]//#########################################[/color]

[COLOR=#0000ff]//## Enter Login-Data[/color]
csebk=[COLOR=#ff00ff]"MYAS400"[/color];
userid=[COLOR=#ff00ff]"MYUSER"[/color];
pwd=[COLOR=#ff00ff]"test"[/color];

[COLOR=#0000ff]//## using ADO[/color]
[COLOR=#0000ff]//Connection String[/color]
connection_string =  [COLOR=#ff00ff]"PROVIDER=IBMDA400;DATA SOURCE="[/color] + csebk +
                     [COLOR=#ff00ff]"; USER ID="[/color] + userid + [COLOR=#ff00ff]"; PASSWORD="[/color] + pwd;

[COLOR=#0000ff]// Open ADO connection [/color]
[COLOR=#008080]var[/color] connection = [COLOR=#804040][b]new[/b][/color] ActiveXObject([COLOR=#ff00ff]"ADODB.Connection"[/color]);
connection.Open(connection_string) 

[COLOR=#0000ff]// Create an instance of an ADO Recordset[/color]
[COLOR=#008080]var[/color] recordset = [COLOR=#804040][b]new[/b][/color] ActiveXObject([COLOR=#ff00ff]"ADODB.Recordset"[/color]);
sql_stmt =  [COLOR=#ff00ff]"select * from IBPDDB.R000270V "[/color];
[COLOR=#0000ff]// Open the recordset, using an SQL statement and the existing ADO connection[/color]
recordset.Open(sql_stmt, connection, 1, 3)

[COLOR=#0000ff]// Retrieve Data [/color]
[COLOR=#804040][b]while[/b][/color] (!recordset.EOF) [COLOR=#008080]{[/color]
  aktsalddat = recordset.Fields([COLOR=#ff00ff]"AKTSALDDAT"[/color]).Value;
  recordset.MoveNext;
[COLOR=#008080]}[/color]

WScript.StdOut.writeline([COLOR=#ff00ff]"* AKTSALDDAT = "[/color] + aktsalddat)

[COLOR=#0000ff]// Close RecordSet[/color]
recordset.close();

[COLOR=#0000ff]// Close Connection[/color]
connection.close();

Now the script runs on command line and I get the output:
Code:
C:\_mikrom\Work>cscript /NoLogo aktsalddat.js
* AKTSALDDAT = 20150731

 
Now when it runs without problems on the command line
I can embed it into HTML page - so:

db_example.html
Code:
[COLOR=#008080]<[/color][COLOR=#804040][b]HTML[/b][/color][COLOR=#008080]>[/color]
 [COLOR=#008080]<[/color][COLOR=#804040][b]HEAD[/b][/color][COLOR=#008080]><[/color][COLOR=#804040][b]TITLE[/b][/color][COLOR=#008080]>[/color][COLOR=#ff00ff][b]EXAMPLE[/b][/color][COLOR=#008080]</[/color][COLOR=#804040][b]TITLE[/b][/color][COLOR=#008080]>[/color]
[COLOR=#a020f0] [/color]
[COLOR=#008080]<[/color][COLOR=#804040][b]script[/b][/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]language[/b][/color][COLOR=#008080] [/color][COLOR=#ff00ff]"javascript"[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]type[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"text/javascript"[/color][COLOR=#008080]>[/color]
[COLOR=#008080]function[/color][COLOR=#6a5acd] get_aktsalddat[/color]()[COLOR=#008080]{[/color][COLOR=#6a5acd] [/color]
[COLOR=#6a5acd]  [/color][COLOR=#804040][b]document[/b][/color][COLOR=#6a5acd].MYDATA.datum.value = [/color][COLOR=#ff00ff]"FOOBAR"[/color][COLOR=#6a5acd]; [/color]
[COLOR=#008080]}[/color]

[COLOR=#008080]function[/color][COLOR=#6a5acd] get_aktsalddat_from_DB[/color]()[COLOR=#008080]{[/color][COLOR=#6a5acd]   [/color]
[COLOR=#0000ff]//#########################################[/color]
[COLOR=#0000ff]// Reading records and fields from database[/color]
[COLOR=#0000ff]//#########################################[/color]

[COLOR=#0000ff]//## Enter Login-Data[/color]
[COLOR=#6a5acd]csebk=[/color][COLOR=#ff00ff]"MYAS400"[/color][COLOR=#6a5acd];[/color]
[COLOR=#6a5acd]userid=[/color][COLOR=#ff00ff]"MYUSER"[/color][COLOR=#6a5acd];[/color]
[COLOR=#6a5acd]pwd=[/color][COLOR=#ff00ff]"test"[/color][COLOR=#6a5acd];[/color]

[COLOR=#0000ff]//## using ADO[/color]
[COLOR=#0000ff]//Connection String[/color]
[COLOR=#6a5acd]connection_string =  [/color][COLOR=#ff00ff]"PROVIDER=IBMDA400;DATA SOURCE="[/color][COLOR=#6a5acd] + csebk +[/color]
[COLOR=#6a5acd]                     [/color][COLOR=#ff00ff]"; USER ID="[/color][COLOR=#6a5acd] + userid + [/color][COLOR=#ff00ff]"; PASSWORD="[/color][COLOR=#6a5acd] + pwd;[/color]

[COLOR=#0000ff]// Open ADO connection [/color]
[COLOR=#008080]var[/color][COLOR=#6a5acd] connection = [/color][COLOR=#804040][b]new[/b][/color][COLOR=#6a5acd] ActiveXObject[/color]([COLOR=#ff00ff]"ADODB.Connection"[/color])[COLOR=#6a5acd];[/color]
[COLOR=#6a5acd]connection.Open[/color]([COLOR=#6a5acd]connection_string[/color])[COLOR=#6a5acd] [/color]

[COLOR=#0000ff]// Create an instance of an ADO Recordset[/color]
[COLOR=#008080]var[/color][COLOR=#6a5acd] recordset = [/color][COLOR=#804040][b]new[/b][/color][COLOR=#6a5acd] ActiveXObject[/color]([COLOR=#ff00ff]"ADODB.Recordset"[/color])[COLOR=#6a5acd];[/color]
[COLOR=#6a5acd]sql_stmt =  [/color][COLOR=#ff00ff]"select * from IBPDDB.R000270V "[/color][COLOR=#6a5acd];[/color]
[COLOR=#0000ff]// Open the recordset, using an SQL statement and the existing ADO connection[/color]
[COLOR=#6a5acd]recordset.Open[/color]([COLOR=#6a5acd]sql_stmt, connection, [/color]1[COLOR=#6a5acd], [/color]3)

[COLOR=#0000ff]// Retrieve Data [/color]
[COLOR=#804040][b]while[/b][/color][COLOR=#6a5acd] [/color]([COLOR=#6a5acd]!recordset.EOF[/color])[COLOR=#6a5acd] [/color][COLOR=#008080]{[/color]
[COLOR=#6a5acd]  aktsalddat = recordset.Fields[/color]([COLOR=#ff00ff]"AKTSALDDAT"[/color])[COLOR=#6a5acd].Value;[/color]
[COLOR=#6a5acd]  recordset.MoveNext;[/color]
[COLOR=#008080]}[/color]

[COLOR=#0000ff]//WScript.StdOut.writeline("* AKTSALDDAT = " + aktsalddat)[/color]

[COLOR=#0000ff]// Close RecordSet[/color]
[COLOR=#6a5acd]recordset.close[/color]()[COLOR=#6a5acd];[/color]

[COLOR=#0000ff]// Close Connection[/color]
[COLOR=#6a5acd]connection.close[/color]()[COLOR=#6a5acd];[/color]

[COLOR=#0000ff]//#########################################[/color]
[COLOR=#0000ff]// fill value into document[/color]
[COLOR=#804040][b]document[/b][/color][COLOR=#6a5acd].MYDATA.datum.value = aktsalddat; [/color]
[COLOR=#008080]}[/color]
[COLOR=#008080]</[/color][COLOR=#804040][b]script[/b][/color][COLOR=#008080]>[/color]
[COLOR=#008080]</[/color][COLOR=#804040][b]HEAD[/b][/color][COLOR=#008080]>[/color]

[COLOR=#008080]<[/color][COLOR=#804040][b]BODY[/b][/color][COLOR=#008080]>[/color]
[COLOR=#008080]<[/color][COLOR=#804040][b]H3[/b][/color][COLOR=#008080]>[/color][COLOR=#ff00ff][b]DB Example[/b][/color][COLOR=#008080]</[/color][COLOR=#804040][b]H3[/b][/color][COLOR=#008080]>[/color][COLOR=#008080]<[/color][COLOR=#804040][b]HR[/b][/color][COLOR=#008080]>[/color]
[COLOR=#008080]<[/color][COLOR=#804040][b]FORM[/b][/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]method[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]post[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]action[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]''[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]NAME[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"MYDATA"[/color][COLOR=#008080]>[/color]
 [COLOR=#008080]<[/color][COLOR=#804040][b]table[/b][/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]BORDER[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"1"[/color][COLOR=#008080]>[/color] 
 [COLOR=#008080]<[/color][COLOR=#804040][b]tr[/b][/color][COLOR=#008080]>[/color]
   [COLOR=#008080]<[/color][COLOR=#804040][b]td[/b][/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]align[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"left"[/color][COLOR=#008080]>[/color]AKTSALDDAT: [COLOR=#008080]</[/color][COLOR=#804040][b]td[/b][/color][COLOR=#008080]>[/color]
   [COLOR=#008080]<[/color][COLOR=#804040][b]td[/b][/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]align[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"left"[/color][COLOR=#008080]><[/color][COLOR=#804040][b]INPUT[/b][/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]NAME[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"datum"[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]TYPE[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"TEXT"[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]SIZE[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"10"[/color][COLOR=#008080]>[/color][COLOR=#008080]</[/color][COLOR=#804040][b]td[/b][/color][COLOR=#008080]>[/color]
 [COLOR=#008080]</[/color][COLOR=#804040][b]tr[/b][/color][COLOR=#008080]>[/color]
 [COLOR=#008080]<[/color][COLOR=#804040][b]tr[/b][/color][COLOR=#008080]>[/color]
   [COLOR=#008080]<[/color][COLOR=#804040][b]td[/b][/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]align[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"left"[/color][COLOR=#008080]><[/color][COLOR=#804040][b]INPUT[/b][/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]TYPE[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"RESET"[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]VALUE[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"Clear Form"[/color][COLOR=#008080]>[/color][COLOR=#008080]</[/color][COLOR=#804040][b]td[/b][/color][COLOR=#008080]>[/color]
   [COLOR=#008080]<[/color][COLOR=#804040][b]td[/b][/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]align[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"left"[/color][COLOR=#008080]><[/color][COLOR=#804040][b]INPUT[/b][/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]TYPE[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"BUTTON"[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]VALUE[/b][/color][COLOR=#008080]=[/color][COLOR=#ff00ff]"get AKTSALDDAT"[/color][COLOR=#008080] [/color][COLOR=#6a5acd]onclick ="[/color][COLOR=#6a5acd]get_aktsalddat_from_DB[/color]()[COLOR=#6a5acd]"[/color][COLOR=#008080]>[/color][COLOR=#008080]</[/color][COLOR=#804040][b]td[/b][/color][COLOR=#008080]>[/color]
 [COLOR=#008080]</[/color][COLOR=#804040][b]tr[/b][/color][COLOR=#008080]>[/color]
[COLOR=#008080]</[/color][COLOR=#804040][b]FORM[/b][/color][COLOR=#008080]>[/color]
[COLOR=#008080]</[/color][COLOR=#804040][b]BODY[/b][/color][COLOR=#008080]>[/color]
[COLOR=#008080]</[/color][COLOR=#804040][b]HTML[/b][/color][COLOR=#008080]>[/color]

On the Webpage it works for me too.
When I click on the button "get AKTSALDDAT" the date is retrieved and written into the field labeled "AKTSALDDAT
 
Well, almost there.

I have gotten this dang thing to create an input file for the item number using javascript, then in vbscript I am able to read that file and display the returned data back to the html form.

Only hiccup it creating he correct results file.

I run the vbscript on its own and it works great, run it through the hta and no sql data appears.

Strange thing is I could have sworn that the correct results file was being created last week. But maybe that was just from running the vbscript manually.

Ideas...?
 
I thought that you want to get data from the database using ADO and now you want to do it more complicated: First, write the data from the database into a text file (with Jscript), and then read the data from the textfile with Vbscript? Why you want to combine Jscript and Vbscript? What can you do in Jscript ťhat can you do in VBscript. Of course, everything works only in Windows with Internet Explorer.

I thought that you don't want to use Vbscript (for some reason), but rather Jscript, so I posted above the solution getting data from database using Jscript. You only need to change a few little things: login data, connection string, the SQL statement ... Are you not able to get this script working in your nevironment?
I have tried the same example in VBscript too and it works fine.


 
Sorry, I thought I had explained that I was using both. Depending one how quick I could get ones way or the other programmed.

Here is my vbs file that gets called. It works fine when run on its own to read and create input and results files. The sql doesnt seem to execute when run through the form


VBS FILE CODE:
on error resume next

dim dbconnection, sqlrs, itemno, sqlrs2
dim DES,AC,MR,PR,objFSO,resultfile,dict,input,file,strpath,objfile,strfile

const CONNECT_STRING = "provider=SQLOLEDB.1;Presist Security info=True;User ID=sa;Initial Catalog=DEMODATA;Data Source=SERVER;password=PASSWORD"

set objFSO = CreateObject("Scripting.FileSystemObject")

Set dbconnection = createobject("ADODB.connection")
Set sqlrs = createobject("ADODB.Recordset")
Set sqlrs2 = createobject("ADODB.Recordset")

dbconnection.Open CONNECT_STRING

strFile = "C:\Program Files (x86)\CHAZTEST\TopLevel\DemoGolf\Configuration\Actions\MARG_OVR_AVG_CST\input.txt"
Set objFile = objFSO.OpenTextFile(strfile)

itemno = objFile.ReadLine


objFile.Close

sqlrs.open "SELECT * FROM [IM_INV] where ITEM_NO = '"&itemno&"' AND LOC_ID='MAIN'", CONNECT_STRING
sqlrs2.open "SELECT * FROM [VI_USR_MARGIN] where ITEM_NO = '"&itemno&"'", CONNECT_STRING

resultfile="C:\Program Files (x86)\CHAZTEST\TopLevel\DemoGolf\Configuration\Actions\MARG_OVR_AVG_CST\results.txt"

IF sqlrs.EOF Then

Set objFileOut = objFSO.CreateTextFile(resultfile,True)

objFileOut.writeline"Invalid Item. Please Re-Enter."
objFileOut.writeline"INVALID"
objFileOut.writeline"INVALID"
objFileOut.writeline"INVALID"

ELSE

Set objFileOut = objFSO.CreateTextFile(resultfile,True)
objFileOut.writeline(sqlrs2("DESCR"))
objFileOut.writeline(ROUND(sqlrs("AVG_COST"),4))
objFileOut.writeline(sqlrs2("PRC_1"))
objFileOut.writeline(ROUND(sqlrs2("MARGIN"),4))

END IF
objFileOut.close

sqlrs.close
dbconnection.close



FORM Functions/Sub CODE:

//--------------------------------------------------------------------------------------------
//-----------START OF FUNCTION TO CREATE ITEM NUMBER FILE FROM HTML FORM----------------------
//--------------------------------------------------------------------------------------------
function SEARCH(MARGIN) {

var infile = "C:\\Program Files (x86)\\Radiant Systems\\CounterPoint\\CHAZTEST\\TopLevel\\DemoGolf\\Configuration\\Actions\\MARG_OVR_AVG_CST\\input.txt";
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fh = fso.CreateTextFile(infile, true);
fh.WriteLine(document.MARGIN.txtItem.value);
fh.Close();
Call_Script();
}
//--------------------------------------------------------------------------------------------
//-----------END OF FUNCTION TO CREATE ITEM NUMBER FILE FROM HTML FORM------------------------
//--------------------------------------------------------------------------------------------
</script>


<script type="text/vbscript">
'--------------------------------------------------------------------------------------------
'------------START OF SUB TO RUN VBSCRIPT FOR INPUT INTO SQL---------------------------------
'--------------------------------------------------------------------------------------------
Sub Call_Script()
Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile("\\server\CHAZTEST\TopLevel\DemoGolf\Configuration\Actions\MARG_OVR_AVG_CST\MARGIN.vbs")
body = ts.ReadAll
ts.Close
Execute body
ENTER_HTML()
End Sub
'--------------------------------------------------------------------------------------------
'------------END OF SUB TO RUN VBSCRIPT FOR INPUT INTO SQL-----------------------------------
'--------------------------------------------------------------------------------------------
'--------------------------------------------------------------------------------------------
'--------------------------------------------------------------------------------------------
'------------START OF SUB TO INPUT RESULTS FILE INTO HTML FORM-------------------------------
'--------------------------------------------------------------------------------------------
Sub ENTER_HTML()

Dim hold(4)

strFile = "\\server\CHAZTEST\TopLevel\DemoGolf\Configuration\Actions\MARG_OVR_AVG_CST\results.txt"
x=0

set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile(strfile,1)

do until objFile.AtEndOfStream
hold(i) = objFile.readline
i=i+1
loop

objFile.Close
document.MARGIN.DESC.value = hold(0)
document.MARGIN.AvgCost.value = hold(1)
document.MARGIN.Price.value = hold(2)
document.MARGIN.Margin.value = hold(3)
End Sub
'--------------------------------------------------------------------------------------------
'------------END OF SUB TO INPUT RESULTS FILE INTO HTML FORM---------------------------------
'--------------------------------------------------------------------------------------------

 
Nothing like learning on the fly.

I am starting to get the code cleaned up in both files.

I really am sorry for any confusion about what I was doing to get this to work.

Sooooo not a programmer.
 
chaznbs said:
Here is my vbs file that gets called. It works fine when run on its own to read and create input and results files. The sql doesnt seem to execute when run through the form
I don't believe. If it would be OK it must execute in HTML form too.
If it doesn't execute you have elsewhere an error in it.
Most common is the error somewhere between the chair and the keyboard :)

What you posted above will not run ...
on the first Jscript function you have only the end tag </script>
and on the seocnd Vbscript function only beginning tag <script type="text/vbscript">

Next time, you should post your code between
[pre]
Code:
[/pre]
and
[pre]
[/pre]
tags.

If you try to learn something, first try a very basic examples. In a simple example it's simpler to find a bug. And if it works then it's easy to enhance it...
On the other hand it's very difficult to find a bug in a complex example.
 
Well I finally got it working.

Main form is an HTA and to grab info from SQL it call an exe.

Had to convert my vbs to exe to get it to work.

Seems to run pretty good. Bosses like it and the client likes it.

Thank for the guidance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top