Help pls.

D

Daniel

Hi, got a problem here. 2 days around, the code works well but today
suddenly got problem and I cant find out what is wrong

rs("credit") is 20(a double value in sql)
a is 4.13
By right, it should be able to deduct but it tell me credit not enough.

a = session("total") * 1.05
set my_conn5= Server.CreateObject("ADODB.Connection")
my_Conn5.Open ConnString5
set rs5 = my_conn5.Execute ("select * from Member where email='" &
session("email") & "'")

if rs5("credit") > (formatNumber(a, 2)) or rs5("credit") =
(formatNumber(a, 2)) then
if not rs5.eof then
strSQL5 = "UPDATE Member SET credit=credit - " & a & " where email='"
& session("email") & "'"
my_conn5.Execute strSQL5
end if
else
shtml = "Sorry, you do not have enough credit." & cbCrlf
response.write "<center>" & shtml
response.end
end if
 
B

Bob Barrows [MVP]

Basic debugging. See inline.
Hi, got a problem here. 2 days around, the code works well but today
suddenly got problem and I cant find out what is wrong

rs("credit") is 20(a double value in sql)
a is 4.13
By right, it should be able to deduct but it tell me credit not
enough.

a = session("total") * 1.05

Response.Write "a contains """ & a & "" said:
set my_conn5= Server.CreateObject("ADODB.Connection")
my_Conn5.Open ConnString5
set rs5 = my_conn5.Execute ("select * from Member where email='" &
session("email") & "'")

Don't use selstar (select *) in production code. I forces ADO to make an
extra trip to the database to resolve the * into a list of column names, and
it forces you to retrieve data you probably aren't going to use.

Response.Write "if rs5(""credit"") contains """ & if rs5("credit") & _
" said:
if rs5("credit") > (formatNumber(a, 2)) or rs5("credit") =
(formatNumber(a, 2)) then

This is probably your problem here. formatNumber returns a string, and
therefore can lead to incorrect results when the result is compared to a
number.. You should be using the Round function if you need to round the
value contained in a. Check it out:

Response.Write "formatNumber(a, 2) contains """ & _
formatNumber(a, 2)) & """<BR>"

Bob BArrows
 
D

Daniel

Bob, thanks for ur advice.

But I already do the basic debugging by displyaing all the value and I
alreasy posted my value..

rs("credit") is 20 so can dedcut away a which is 4.02. but today it just
cant seem to be working....

cheers
 
B

Bob Barrows [MVP]

D said:
Bob, thanks for ur advice.

But I already do the basic debugging by displyaing all the value and I
alreasy posted my value..

rs("credit") is 20 so can dedcut away a which is 4.02. but today it
just cant seem to be working....
Try it without the formatNumber function.
 
B

Bob Barrows [MVP]

Bob said:
Try it without the formatNumber function.

Better yet:

if rs5("credit") >= Round(a,2) then

Bob Barrows
PS. As I said in my first reply, formatNumber is returning a string, forcing
an alphabetic comparison between "20" and "4.02". "4" is greater than "2"
 
D

Daniel

Bob, thanks

Round is round up to whole number? if 4.04, round give 4? what about
4.5??

regards
cheers
 
B

Bob Barrows [MVP]

D said:
Bob, thanks

Round is round up to whole number?

No. Try a few values to see for yourself. Or better yet, get the
documentation using the link I provide below.
if 4.04, round give 4? what about

Depends on the argument you use in the call to the function. Round(4.04,2)
should give you 4.04
Here is the documentation:
http://www.microsoft.com/downloads/...48-207d-4be1-8a76-1c4099d7bbb9&DisplayLang=en


IIRC, it uses bankers' rounding: 5 gets rounded to the closest even number.
If that's not acceptable, then you need to roll your own function. If you
search the MS Knowledge base (http://support.microsoft.com) you will find
articles talking about rounding in VB and vbscript.

Bob Barrows
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top