Percentage Calculation question....

D

David

Hi,

I have the following calculation I am trying to work out ..... Not sure
how ?

Variable 1 = minstock
Variable 2 = oDict(oKey)

I need to test if my variable 'minstock' <= 40% of oDict(oKey)

I've tried

IF minstock <= oDict(oKey)*0.4 then
swarn = "Low Stock"
else
swarn = "&nbsp;"
end if

I just get an error


What is the correct way of writing this calculation ?

Thanks

David
 
R

Ray Costanzo [MVP]

"I just get an error."

What's the error?! What's the value of oDict(oKey)?

Ray at work
 
B

Bob Barrows [MVP]

David said:
Hi,

I have the following calculation I am trying to work out ..... Not
sure how ?

Variable 1 = minstock
Variable 2 = oDict(oKey)

I need to test if my variable 'minstock' <= 40% of oDict(oKey)

I've tried

IF minstock <= oDict(oKey)*0.4 then
swarn = "Low Stock"
else
swarn = "&nbsp;"
end if

I just get an error

What error?
What is the correct way of writing this calculation ?

It looks correct to me.
Give us some actual data to look at, i.e., provide us with a repro
script that we can run to reproduce your symptoms. We don't want to see
your entire page -- we don't even need to see your actual data. Just
provide a small repro script that uses data that reproduces the
symptoms. Something like this:

<%
dim oKey, oDict, minstock
minstock=20
set oDict=createobject("scripting.dictionary")
oKey="test"
oDict.Add oKey, 100
IF minstock <= oDict(oKey)*0.4 then
Response.Write "Low Stock"
Else
Response.Write "Stock OK"
End If
%>

This works fine for me, by the way.
 
D

David

Hi Ray,

It is a calculated integer. A sum of a calculation

David

-------------------------------------------------------
Ray said:
"I just get an error."

What's the error?! What's the value of oDict(oKey)?

Ray at work

---------------------------------------------
 
D

David

Microsoft VBScript runtime error '800a000d'

Type mismatch

/L&R/Metal/complete_orderbook_view.asp, line 120
 
M

Mike Brind

Do a Response.Write TypeName(oDict(oKey)) to check. You should also check
the datatype of minstock.
 
D

David

Bob said:
What error?


It looks correct to me.
Give us some actual data to look at, i.e., provide us with a repro
script that we can run to reproduce your symptoms. We don't want to see
your entire page -- we don't even need to see your actual data. Just
provide a small repro script that uses data that reproduces the
symptoms. Something like this:

<%
dim oKey, oDict, minstock
minstock=20
set oDict=createobject("scripting.dictionary")
oKey="test"
oDict.Add oKey, 100
IF minstock <= oDict(oKey)*0.4 then
Response.Write "Low Stock"
Else
Response.Write "Stock OK"
End If
%>

This works fine for me, by the way.


--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


------------------------------

Thanks,

I've sorted it now
perc = round(cint(oDict(oKey))*0.4)

Thanks for all your help :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,351
Latest member
LolaD32479

Latest Threads

Top