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

Assign value to variable 1

Status
Not open for further replies.

egodette

Technical User
Jun 12, 2002
222
US
Not sure how to do this correctly. I keep getting an error.

answer = <%=FormatNumber(CDbl(rsFocus("NAV")),2)%>

the <%...%> is ok. It returns the correct value. I just don't know how to get the answer into the answer variable.

Thanks....
 
Put the result in quotes, (single quotes in this case)

Code:
answer = [!]'[/!]<%=FormatNumber(CDbl(rsFocus("NAV")),2)%>[!]'[/!]

[small]"I see pretty girls everywhere I look, everywhere I look, everywhere I look. - Band song on movie "The Ringer"[/small]
<.
 
It looks like you are using server-side code to dynamically generate client-side code.

So is the error happening in the ASP or when the browser tries to run the client-side code?

If it is happening on the ASP side then perhaps [tt]rsFocus("NAV")[/tt] is returning some value that cannot be converted to datatype double. (perhaps Null?)
 
I was assuming based off this statement:

the <%...%> is ok. It returns the correct value

that the return value was correct from the function FormatNumber.

So in that case, it had to be a data type issue (FormatNumber returning a string?).

[small]"I see pretty girls everywhere I look, everywhere I look, everywhere I look. - Band song on movie "The Ringer"[/small]
<.
 
single quotes did not work.

Here is my code

set myfileobject=server.createobject("scripting.filesystemobject")
set myfile=myfileobject.getfile("c:\storage\output\pricesheet.xls")

Set objConn = Server.CreateObject("ADODB.Connection")
objConn.open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("../data/marsico.mdb")

' Create a command text string.
strFocusSQL = "SELECT TOP 1 * FROM CurrentFundPrice WHERE Symbol = 'MFOCX' ORDER BY Date DESC"


Set rsFocus = Server.CreateObject("ADODB.Recordset")

rsFocus.Open strFocusSQL, objConn

answer = '<%=FormatNumber(CDbl(rsFocus("NAV")),2)%>'



The error message is.
Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/utility/test.asp, line 39, column 9

(line 39 is answer = .....)

The answer will always be a number.


 

Think it should be:
Code:
answer = FormatNumber(CDbl(rsFocus("NAV")),2)
If that still doesn't work, maybe declare the result a string like this:
Code:
answer = CStr(FormatNumber(CDbl(rsFocus("NAV")),2))

 
Also, be forewarned that if you attempt to apply the FormatNumber or the CDbl function to a value that doesn't exist (meaning there is no number returned or you have a non-numeric value - like "NULL"), you will have an error. You may want to add some error checking code for that eventuality.

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Since the code you posted contains a reference to Server.CreateObject it is safe to assume that this is ALL server-side code and therefore there is need to re-open the script delimitters. <% %>
 
Sheco said:
Since the code you posted contains a reference to Server.CreateObject it is safe to assume that this is ALL server-side code and therefore there is no need to re-open the script delimitters. <% %>
I assume this what you meant? ;-)

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top