×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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()">

<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>



<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>
<td align="left"><INPUT TYPE="BUTTON" VALUE="Retrieve Item" onclick ="call RETRIEVE()"></td>
<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>

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

Maybe I missed something ... but what isn't working?

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

(OP)
The highlighted.

For somereason I cannot get the on_click to run to the vbscript

Just using the vbscript grab database info to display it in the html window

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

In your code you have:
sqlrs.open "SELECT * FROM [VI_USR_MARGIN] where ITEM_NO = '"&Itemno&"' AND LOC_ID='MAIN'",

You cannot use an apostrophe in VBScript code as it creates a comment. So your line is actually interpreted as
sqlrs.open "SELECT * FROM [VI_USR_MARGIN] where ITEM_NO =

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER.

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

(OP)
That why they are inside the quotes. SQL needs them

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

Get rid of the "CALL":

CODE

onclick="RETRIEVE();" 

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

(OP)
Well, I am still trying different thing I find. No luck.

All this needs to do is connect this stand alone form to the clients sql database when the button is clicked to pull the item and display the info. if there is a better way please advise.

I am not a programmer and the parts that work are working well. And I have far exceeded the 5 hours my bosses allotted me for this job.

Took this on to help develop those skill alittle.

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

1) Are you using Internet Explorer?

2) Hit F12 (or go to Tools and click Developer tools). Click the "Script" tab, reload your page and click the "Retrieve Item" button again. Do you get any errors?

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

(OP)
That has been the biggest help so far.

It is the select statement.

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

Thank goodness. A new place to look

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

Before trying to open record set, you can write the select statement, to see if everything is ok:

CODE

...
Itemno = document.MARGIN.txtItem.value

sql_stmt="SELECT * FROM [VI_USR_MARGIN] where ITEM_NO = '" _
         & itemno&"' AND LOC_ID='MAIN'"

Wscript.echo sql_stmt 

sqlrs.open sql_stmt, CONNECT_STRING, 1, 3
... 

Btw I don't know what is the highligted item [VI_USR_MARGIN]. It's any convention I don't know ?
I'm using in the SQL always the convention MYSCHEMA.MYTABLE.

To see where is the error, you can try to run your VBscript outside of the webpage on the command line, like

CODE

C:\Work>cscript /NoLogo your_script_file.vbs 

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

(OP)
That was the name of the view it is pulling data from since it comes from 3 different tables

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

OK, but with view we use the same convention as with a table, i.e MYSCHEMA.MYVIEW.
Why are the brackets [] there? (I don't know ... myabe it's a convention od your DB)

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

(OP)
That was how my vbs code was written for another project that works fine.

This exploration into html and java with vbs has been an experience

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

RETRIEVE() is a function, so the CALL should not be used. If I remove it

CODE

<td align="left"><INPUT TYPE="BUTTON" VALUE="Retrieve Item" onclick =RETRIEVE()></td> 
and comment everything in the function except the instruction for creating and printing SQL statement

CODE

<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
sql_stmt = "SELECT * FROM [VI_USR_MARGIN] where ITEM_NO = '"&Itemno&"' AND LOC_ID='MAIN'"
MsgBox sql_stmt, 1, 3

'sqlrs.open , CONNECT_STRING, 1, 3

' 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> 
then when I write in the input box named Item Number: an value 123 and press the button Retrieve Item, then a message box works and shows the SQL statement which seems to be OK.

CODE

SELECT * FROM [VI_USR_MARGIN] where ITEM_NO = '123' AND LOC_ID='MAIN' 

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

mikrom:
1) the brackets [] escape non standard characters or reserved words in access, sql server etc
2) I already mentioned about removing "call"
3) OP is successfully executing the function, but has a specific error message now; "Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another", possibly due to ITEM_NO or LOC_ID not being text values

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

Sorry I did not notice that.
With the wrong type, IMO the solution would be to try to execute the sql statetemt directly on the database client and to look at the types of the affected fields.

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

Maybe the itemno should be without apostrophes, i.e 123 and not '123'

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

(OP)
Ugh... What a pain.

My test code for funtion work if run as a vbs file:

on error resume next

dim dbconnection, sqlrs, itemno, sqlrs2

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")
Set sqlrs2 = createobject("ADODB.Recordset")

dbconnection.Open CONNECT_STRING

itemno = "999999"

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
If sqlrs.EOF Then
Wscript.Echo "Invalid Item. Please Re-Enter."
Else
msgbox ("Item Description "&sqlrs2("DESCR")& vbCrLf & "Current Average Cost: $"& ROUND(sqlrs2("AVG_COST"),4)& vbCrLf & "Current Margin: "&ROUND(sqlrs2("MARGIN"),4)&"%"&""),0,"Item Number: "&sqlrs("ITEM_NO")
END IF

sqlrs.close
dbconnection.close

As soon as I use it inside the html file I get nothing. No error in IE either when I f12 it.

Is there some other way to run?

I know its a VBS forum but is there a way to get it to work in javascript?

Anything will help.

html file is being stored on a separate computer but it does not get called up in web format. HTML file get call up directly.

I will provide whatever info I can for the use of the extra brainpower. I am so far from being a programmer and my mind is fried.

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

VBScript/WScript .vbs files run in a Windows Script Host (WSH) context not in a browser.

( Windows key + R or Start -> Run )


Quote:

but is there a way to get it to work in javascript?
Nope, javascript cannot connect directly to a database, and a remote javascript is not allowed to access anything on the local computer other than cookies and history locations.

Chris.

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

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

(OP)
Ok that is why the box doesn't popup. But that was only for testing anyways.

Is that also why it wont read into SQL and fill the variables?

Would doing something like writing to a text file and read it into vbscript work better then read the results into another text file to go to html through javascript?

Again I am so not a programmer. Just trying to find a way

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

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

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

(OP)
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.

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

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

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

Quote (chaznbs)


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 ...

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

Quote:

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

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

(OP)
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?

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

Quote (chaznbs)


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

//#########################################
// Reading records and fields from database
//#########################################

//## Enter Login-Data
csebk="MYAS400";
userid="MYUSER";
pwd="test";

//## using ADO
//Connection String
connection_string =  "PROVIDER=IBMDA400;DATA SOURCE=" + csebk +
                     "; USER ID=" + userid + "; PASSWORD=" + pwd;

// Open ADO connection 
var connection = new ActiveXObject("ADODB.Connection");
connection.Open(connection_string) 

// Create an instance of an ADO Recordset
var recordset = new ActiveXObject("ADODB.Recordset");
sql_stmt =  "select * from IBPDDB.R000270V ";
// Open the recordset, using an SQL statement and the existing ADO connection
recordset.Open(sql_stmt, connection, 1, 3)

// Retrieve Data 
while (!recordset.EOF) {
  aktsalddat = recordset.Fields("AKTSALDDAT").Value;
  recordset.MoveNext;
}

WScript.StdOut.writeline("* AKTSALDDAT = " + aktsalddat)

// Close RecordSet
recordset.close();

// Close Connection
connection.close(); 

Now the script runs on command line and I get the output:

CODE

C:\_mikrom\Work>cscript /NoLogo aktsalddat.js
* AKTSALDDAT = 20150731 

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

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

db_example.html

CODE

<HTML>
 <HEAD><TITLE>EXAMPLE</TITLE>
 
<script language "javascript" type="text/javascript">
function get_aktsalddat(){ 
  document.MYDATA.datum.value = "FOOBAR"; 
}

function get_aktsalddat_from_DB(){   
//#########################################
// Reading records and fields from database
//#########################################

//## Enter Login-Data
csebk="MYAS400";
userid="MYUSER";
pwd="test";

//## using ADO
//Connection String
connection_string =  "PROVIDER=IBMDA400;DATA SOURCE=" + csebk +
                     "; USER ID=" + userid + "; PASSWORD=" + pwd;

// Open ADO connection 
var connection = new ActiveXObject("ADODB.Connection");
connection.Open(connection_string) 

// Create an instance of an ADO Recordset
var recordset = new ActiveXObject("ADODB.Recordset");
sql_stmt =  "select * from IBPDDB.R000270V ";
// Open the recordset, using an SQL statement and the existing ADO connection
recordset.Open(sql_stmt, connection, 1, 3)

// Retrieve Data 
while (!recordset.EOF) {
  aktsalddat = recordset.Fields("AKTSALDDAT").Value;
  recordset.MoveNext;
}

//WScript.StdOut.writeline("* AKTSALDDAT = " + aktsalddat)

// Close RecordSet
recordset.close();

// Close Connection
connection.close();

//#########################################
// fill value into document
document.MYDATA.datum.value = aktsalddat; 
}
</script>
</HEAD>

<BODY>
<H3>DB Example</H3><HR>
<FORM method=post action='' NAME="MYDATA">
 <table BORDER="1"> 
 <tr>
   <td align="left">AKTSALDDAT: </td>
   <td align="left"><INPUT NAME="datum" TYPE="TEXT" SIZE="10"></td>
 </tr>
 <tr>
   <td align="left"><INPUT TYPE="RESET" VALUE="Clear Form"></td>
   <td align="left"><INPUT TYPE="BUTTON" VALUE="get AKTSALDDAT" onclick ="get_aktsalddat_from_DB()"></td>
 </tr>
</FORM>
</BODY>
</HTML> 

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"

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

(OP)
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...?

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

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.


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

(OP)
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---------------------------------
'--------------------------------------------------------------------------------------------

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

(OP)
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.

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

Quote (chaznbs)


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 smile

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
[CODE] 
and
[/CODE] 
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.

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

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close