Link to home
Start Free TrialLog in
Avatar of nomoslogos
nomoslogos

asked on

Accessing the Values Returned by a Database Results Region

I have a Database Results Region that is succesfully returning the values I want. Now I need to do VBScript math calculations with them. Are they not directly accessible to VB? When I reference one in VBS by its field-name it says it isn't defined.

If not,

FP closes the recordsource after it retrieves the data so I don't think I can access the original recordsource. Do I have to recreate a database connection/recordsource? That would make the Database Results Region a very limited tool.

How do I access the values in the actual Database Results Region cells to assign them to VBScript variables. Since it is not a form I don't know its name to reference them.
Avatar of hhammash
hhammash

Hi,

First open your DRW page in HTML view.
Put the code to Spooky Diet.  http://www.outfront.net/spooky/adv_drw_diet.htm
Save the page

Now the DRW becomes ready for any code that you would like to put and use.

Regards
hhammash
Avatar of nomoslogos

ASKER

Spooky diet didn't make any difference.

I need to know how to use the results values in VBScript.

I can see the TABLE of the DRW with the values I want (and in the browser they return actual values):

      <td>
      <%=FP_FieldVal(fp_rs,"BC")%>&nbsp;</td>
      <td>
      <%=FP_FieldVal(fp_rs,"BD")%>&nbsp;</td>
      <td>
      <%=FP_FieldVal(fp_rs,"ED")%>&nbsp;</td>

But how do I use the value of BC, or BD, or ED to do a calculation in VBScript.
If I just say

<SCRIPT LANGUAGE="VBScript">
X = BC*BD+ED
</SCRIPT>

I get X = ""

Do I need to assign these values to a VBScript variable to use them? If so what it the format? I have tried:

BC = fp_rs("BC")
or
BC = FP_FieldVal(fp_rs,"BC")

But these don't work. I get a tyoe mismatch.
yes it can be done,  but where are you going to place the X on the table?
Hi,

If you are viewing the results in a table and you want the value of "X" to be on the same line as in:

BC          BD     ED   X
7            6       3     45
5            6       7     37
4            4       4     20

You can do it without Spooky diet.

1- Open your DRW in Normal Mode
2- Put the cursor on the row that has the field name <<BC>> <<BD>><<ED>>
3- Table > Select Row
4- Table > Insert Rows or Columns
5- Select Columns radio button
6- Select Right of Selection
7- A new column will be added,  now type the name of the column  on the column header
8- In the new cell next to <<BD>>,  the new cell that you created type "HERE"
9- Swith to HTML View
10- Look for the <td> that has the word "HERE" it will look like <td>HERE</td>. This should appear in the last part of the DRW where you have the field name.
11- Highlight the word HERE and replace it with this:
<%=FP_Field(fp_rs,"BC")* FP_Field(fp_rs,"BD")+FP_Field(fp_rs,"ED")%>

Of course change field name.
12- Save the DRW and you are done

When you view the DRW you will see the results of * and + are displayed on the same row.

Regards
hhammash


Notice that I removed FP_FieldVal and changed it to FP_Field in the X field
I just assumed that you want to have an additional column with the result.  If you want the calculations to appear in a different way just let me know.
Thanks hhammash for your attempts to help me.

What I thought was my problem, was not my problem. One of the techniques I was trying was working, I just didn't know it. My problem was somewhere else.

My question:

How do I access the values in the actual Database Results Region cells to assign them to VBScript variables.

Is answered by:

BC = fp_rs("BC")              'where the first BC is a VB variant and the BC in quotes is the field name

or

BC = fp_rs.fields("BC")     'I believe this is the same thing as above



Hi,

So you want to give a variable the value of a field:

<%
BC=FP_Field(fp_rs,"BC")
%>
My problem is I am not getting output. I thought it was because I was getting the values from the DRW into my VBScript variables, but I did a response.write immediately following the assignment, and there are there.

Then I am getting a type mismatch on my function

sub Calculate

I was calling it with the Onclick value of the control. I eliminated the OnClick value of the control and change the name of the sub to Calculate_Onclick.

No i am not getting an errors. But my problem that remains, I am not getting my output in the textbox.

So here is what its supposed to do:

The actual equation (sub Calculate_Onclick) is much more complex than X = BC*BD+ED
and is broken into 5 lines. It must go in a sub-routine/function. A button calls the sub (which is suppossed to use the VBscript variables that were assigned the values from the DRW), does the calculation and then places the value in an existing textbox (named Hb), BUT NOT back in the DRW table.

But I can't tell if it is working, my values aren't showing up in my textbox. I put a response write in my function, but it doesn't show up anywhere.

I think either

1. I am not calling my function correctly, so it isn't actually being executed or
2. I am not outputting to the textbox correctly.

Now, I spent more time with it:

I had to put the sub in

<SCRIPT LANGUAGE="VBScript">
Sub Calculate_OnClick
</SCRIPT>

Now it is executing my sub when I press the calculate button. I know it is becuase a put a message box in it that shows one of the variables (assigned a value from the DRW). The message box ops up but the variable is empty!

Why would my variables not but accessible to my sub?





Sorry, my second sentence above should have said:

I thought it was because I was NOT getting the values from the DRW into my VBScript variables...
Hi,

Is the textbox in a form?
Where are you putting the sub?
You better put the sub between the file includes of the DRW
What is the code for the sub?

In order to get the results from the DRW.

Create the variables to pick up the values from the DRW fields as I showed you (create them after the DRW)
then use these variables in your sub.


hhammash


Yes the textbox is in the same form as the Calculate button.

I have tried putting the sub everywhere. Here is the code as you are saying:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Script-Type" content="text/vbscript">
<title>Qualify A Sine Tool</title>

<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<script type="text/vbscript"></script>
<meta name="Microsoft Theme" content="granite 111, default">
<meta name="Microsoft Border" content="tlb, default">
</head>

<body>

<h2>You must qualify your Sine Fixture values  before
using this calculator. If you have not done so, <a href="sinechkreg2.asp">click
here.</a></h2>



<h3>Setup &quot;A&quot; notes ( drawing):</h3>



<ul>
  <li>Fixture is a Sine Vise with the moveable jaw removed.</li>
  <li>Workpiece being inspected is an Electrode.
  <ul>
    <li>Use absolute value of overburn (not negative values).</li>
    <li>Enter in &quot;O&quot; window below.</li>
  </ul>
  </li>
  <li>Electrode is mounted centrally in precision holder.<ul>
    <li>The accuracy of this set-up is affected by the accuracy of the holder.</li>
  </ul>
  </li>
  <li>A spacer can be use if needed to allow for a larger electrode
  <ul>
    <li>Enter in &quot;S&quot; window below.</li>
  </ul>
  </li>
  <li>X, Y &amp; Z are the Cartesian coordinates from a user-established origin.<ul>
    <li>Use X or Y, not both. Enter in &quot;X/Y&quot; window below.</li>
  </ul>
  </li>
</ul>

<h3>Instructions:</h3>

<dl>
    <dd>Enter all values that apply. Reference the drawing and click on the
    corresponding buttons for an explanation of the variable.</dd>
    <dd>Press the Calculate button and the values for G and H will be displayed. </dd>
</dl>

<hr>

<p>
&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<img border="0" src="../images/sinefixhorwsp.png" width="641" height="476" align="center"></p>

<p>&nbsp;</p>
<form BOTID="0" METHOD="POST" ACTION="sinechkahh.asp">
  <table BORDER="0">
    <tr>
      <td><b>Username</b></td>
      <td>
      <input TYPE="TEXT" NAME="Username" VALUE="<%=Server.HtmlEncode(Request("Username"))%>" size="20"></td>
    </tr>
    <tr>
      <td><b>Pswd</b></td>
      <td>
      <input TYPE="TEXT" NAME="Pswd" VALUE="<%=Server.HtmlEncode(Request("Pswd"))%>" size="20"></td>
    </tr>
  </table>
  <p><br>
  <input TYPE="Submit"><input TYPE="Reset"></p>
  <p>&nbsp;</p>
</form>
<table width="100%" border="1">
  <thead>
    <tr>
      <td><b>Username</b></td>
      <td><b>Sine_ID</b></td>
      <td><b>Sine_Desc</b></td>
      <td><b>BC</b></td>
      <td><b>BD</b></td>
      <td><b>ED</b></td>
      <td><b>JD</b></td>
      <td><b>RD</b></td>
      <td><b>TD</b></td>
    </tr>
  </thead>
  <tbody>

<!--#include file="../_fpclass/fpdblib.inc"-->

<%
fp_sQry="SELECT * FROM qryUserSineData WHERE (Username =  '::Username::' AND Pswd =  '::Pswd::')"
fp_sDefault="Username=&Pswd="
fp_sNoRecords="<tr><td colspan=9 align=left width=""100%"">User Name not found or incorrect Password.</td></tr>"
fp_sDataConn="SineUsers"
fp_iMaxRecords=256
fp_iCommandType=1
fp_iPageSize=0
fp_fTableFormat=True
fp_fMenuFormat=False
fp_sMenuChoice=""
fp_sMenuValue=""
fp_sColTypes="&Username=202&Pswd=202&PswdVrfy=202&EmailAddress=202&CompanyName=202&Sine_ID=202&Sine_Desc=202&BC=5&BD=5&ED=5&JD=5&RD=5&TD=5&"
fp_iDisplayCols=9
fp_fCustomQuery=False
BOTID=0
fp_iRegion=BOTID
%>

<!--#include file="../_fpclass/fpdbrgn1.inc"-->

<tr>
      <td>
      <%=fp_rs("Username")%>&nbsp;</td>
      <td>
      <%=FP_FieldVal(fp_rs,"Sine_ID")%>&nbsp;</td>
      <td>
      <%=FP_FieldVal(fp_rs,"Sine_Desc")%>&nbsp;</td>
      <td>
      <%=FP_FieldVal(fp_rs,"BC")%>&nbsp;</td>
      <td>
      <%=FP_FieldVal(fp_rs,"BD")%>&nbsp;</td>
      <td>
      <%=FP_FieldVal(fp_rs,"ED")%>&nbsp;</td>
      <td>
      <%=FP_FieldVal(fp_rs,"JD")%>&nbsp;</td>
      <td>
      <%=FP_FieldVal(fp_rs,"RD")%>&nbsp;</td>
      <td>
      <%=FP_FieldVal(fp_rs,"TD")%>&nbsp;</td>
    </tr>

<%

BCv=FP_Field(fp_rs,"BC")
BDv=FP_Field(fp_rs,"BD")
EDv=FP_Field(fp_rs,"ED")
JDv=FP_Field(fp_rs,"JD")
RDv=FP_Field(fp_rs,"RD")
TDv=FP_Field(fp_rs,"TD")

SUB calculate()

Dim C, B2R, R2P
Dim A, S, T, U, X, Z, O, G, H

msgbox(BCv)

A = (document.getcheckdata.Ab.value)
S = (document.getcheckdata.Sb.value)
T = (document.getcheckdata.Tb.value)
U = (document.getcheckdata.Ub.value)
X = (document.getcheckdata.Xb.value)
Z = (document.getcheckdata.Zb.value)
O = (document.getcheckdata.Ob.value)

Pi = 4 * Atn(1)
C = EDv+RDv+TDv+RDv
B2R = BDv+RDv+TDv+RDv+EDv+RDv
R2P = T+X+A+U+JDv+Z
H = B2R+R2P
G = BCv+A

document.putcheckdata.Gb.value = (G)
document.putcheckdata.Hb.value = (H)

End Sub

%>


<!--#include file="../_fpclass/fpdbrgn2.inc"-->

</tbody>
</table>

<FORM NAME="getcheckdata">
 <TABLE WIDTH="100%" cellspacing="0" cellpadding="2" border="1" valign="top" bgcolor="">
  <TR>
   <TH><INPUT TYPE=button VALUE="A" OnClick="alert('The .')"></TH>
   <TH><INPUT TYPE=button VALUE="S" OnClick="alert('The .')"></TH>
   <TH><INPUT TYPE=button VALUE="T" OnClick="alert('The .')"></TH>
   <TH><INPUT TYPE=button VALUE="U" OnClick="alert('The .')"></TH>
   <TH><INPUT TYPE=button VALUE="X/Y" OnClick="alert('The .')"></TH>
   <TH><INPUT TYPE=button VALUE="Z" OnClick="alert('The .')"></TH>
   <TH><INPUT TYPE=button VALUE="O" OnClick="alert('The .')"></TH>
  </TR>
  <TR>
   <TH><INPUT TYPE=text NAME="Ab" SIZE=6></TD>
   <TH><INPUT TYPE=text NAME="Sb" SIZE=6></TD>
   <TH><INPUT TYPE=text NAME="Tb" SIZE=6></TD>
   <TH><INPUT TYPE=text NAME="Ub" SIZE=6></TD>
   <TH><INPUT TYPE=text NAME="Xb" SIZE=6></TD>
   <TH><INPUT TYPE=text NAME="Zb" SIZE=6></TD>
   <TH><INPUT TYPE=text NAME="Ob" SIZE=6></TD>
  </TR>
 </TABLE>
</FORM>


<FORM NAME="putcheckdata">
 <TABLE WIDTH="20%" cellspacing="0" cellpadding="2" border="1" valign="top" halign="center" bgcolor="">
  <TR>
   <TH><INPUT TYPE=button NAME="Calculate" VALUE="Calculate G & H" OnClick="Calculate"></TH>
  </TR>
 </TABLE>
 <TABLE WIDTH="20%" cellspacing="0" cellpadding="2" border="1" valign="top" halign="center" bgcolor="">
  <TR>
   <TH><INPUT TYPE=button VALUE="G" OnClick="alert('The')"></TH>
   <TH><INPUT TYPE=button VALUE="H" OnClick="alert('The')"></TH>
  </TR>
  <TR>
   <TH><INPUT TYPE=text NAME="Gb" SIZE=7></TD>
   <TH><INPUT TYPE=text NAME="Hb" SIZE=7></TD>
  </TR>
 </TABLE>
</FORM>

</body>
</html>

I get this error:

Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/CNC_Mold_Tools/sinechkahh.asp, line 185
SUB calculate()


BTW, That's not the actual equations, but each one has all the variable of the corresponding actual equations.
Hi,

Try:

After defining the variable:

BCv=FP_Field(fp_rs,"BC")
BDv=FP_Field(fp_rs,"BD")
EDv=FP_Field(fp_rs,"ED")
JDv=FP_Field(fp_rs,"JD")
RDv=FP_Field(fp_rs,"RD")
TDv=FP_Field(fp_rs,"TD")

Close the asp %>

Then create the Javascript sub after the last file include


hhammash
<%

BCv=FP_Field(fp_rs,"BC")
BDv=FP_Field(fp_rs,"BD")
EDv=FP_Field(fp_rs,"ED")
JDv=FP_Field(fp_rs,"JD")
RDv=FP_Field(fp_rs,"RD")
TDv=FP_Field(fp_rs,"TD")

%>

<SCRIPT LANGUAGE="VBScript">
SUB calculate()

Dim C, B2R, R2P
Dim A, S, T, U, X, Z, O, G, H

msgbox(BCv)

A = (document.getcheckdata.Ab.value)
S = (document.getcheckdata.Sb.value)
T = (document.getcheckdata.Tb.value)
U = (document.getcheckdata.Ub.value)
X = (document.getcheckdata.Xb.value)
Z = (document.getcheckdata.Zb.value)
O = (document.getcheckdata.Ob.value)

Pi = 4 * Atn(1)
C = EDv+RDv+TDv+RDv
B2R = BDv+RDv+TDv+RDv+EDv+RDv
R2P = T+X+A+U+JDv+Z
H = B2R+R2P
G = BCv+A

document.putcheckdata.Gb.value = (G)
document.putcheckdata.Hb.value = (H)

End Sub

</SCRIPT>

Ok. Now it compiles, but once again, when I press the Calculate button,
the Msgbox value comes up empty and the textboxs stay blank.
Also, I get an overflow error when I press the calculate button.
Probably because the variables BCv, BDv, ... don't have values.
Hi,

I am a little bit lost here.

You want to do calculations on a form.  Your calculations are based on the values from the drw right?  If you have a form with it's fields populated with values it will be easier for you to apply javascript.

Why don't you get the DRW data into a form,  then use the calculations.  

This way you do not need to create variables,  you just name the form fields which will be populated with the data.

How:
1- Create a DRW
2- At the end in step 4/5 select "list-one field per item"
3- In the list options down select "text fields"

Now you will have a form.  Try applying your JavaScript code on it.

Regards
hhammash
Don't worry, hhammesh, I'm the one that is lost, not you. I barely have a clue what I am doing.

I didn't start out programming on webpages so my mind doesn't think in terms of a webpage.

I thought about putting it into a form, but I don't want it showing again on my page.
It already shows once from the Database Results Region. But I think I see what you are saying
about making my DRW into a form (why don't they make it one to start with?).

BTW, the DRW it is only returning one row because the criteria field is a unique ID.

It seems to me my problem at this point is accessing the fields values of the DRW with my code.
Once I change my DRW to a form, how do I address the fields? They don't have names (or
do they?). Can they be accessed by index?

Why is it so difficult to assign values to variables? That's a common task in programming.

Sorry to be so dense, but I don't have any training and its not very intuitive. But thats why I
gave it the Max points!
ASKER CERTIFIED SOLUTION
Avatar of hhammash
hhammash

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That worked!

I had to name the form, also. And the H value is coming up NaN, but I'm
sure that is just something with my equation isn't quite right.

hhammash, thank your for time and your patience,
you earned your 500 points!

Cheers, and goodnight!
I am glad it worked nomoslogos

Thank you