gerorge
gerorge

Reputation: 19

Less than or equal to not working

I am using VBScript to process incoming text messages. I have a condition whereby if the incoming value is lower than the value in the database a message will be sent to the sender. For some reason even if the value is higher the message set is still being sent.

Basically the variable arrmessage contains a number, for example 300, it is then compared to the variable val, which is the max value from database table called bid. So for example val = 10.

When I place arrmessage <= val then... elseif arrmessage > val then it always tells me that arrmessage is lower than val, even though it is higher.

Set objConn = CreateObject("ADODB.Connection")
set mycommand = CreateObject("ADODB.COMMAND")

objConn.Open "Provider=SQLOLEDB.1;Data Source=OFFICE-PC\SQLEXPRESS Initial Catalog=SMSSERVER","sa","Password1"
set highestbid = objConn.execute("select max(bid) from bid")
val = highestbid.fields(0).value
highestbid.close

IF arrmessage <= val then
  strResponse = "Your bid is " & arrmessage & " and the highest bid is " & (val) & " you need to out bid the highest bidder"
elseif arrmessage > val then
  'continue and insert bid in table
  Set objConn = CreateObject("ADODB.Connection")
  set mycommand = CreateObject("ADODB.COMMAND")
  objConn.Open "Provider=SQLOLEDB.1;Data Source=OFFICE-PC\SQLEXPRESS;  Initial Catalog=SMSSERVER","sa","Password1"
  set mycommand = objConn.execute("update bid set bid='"& arrmessage & " 'where  msisdn='" & objMessageIn.FromAddress & "'")
  strResponse = "Thanks your bid of " & arrmessage & " has been recorded. To query the highest bid text keyword query"
else

Upvotes: 0

Views: 606

Answers (1)

joehanna
joehanna

Reputation: 1489

My guess is that arrmessage is not numeric, possibly caused by the problem in your update statement. The single quote that surrounds the arrmessage variable has a space in front of it in the string concatenation, it will thereby always add a space to end of each bid you write out. In fact, I am surprised that update doesn't return a syntax error given you don't have a space preceding the where also. In addition, you should explicitly close the DB connection before you initialise it again in preparation for the update.

Upvotes: 1

Related Questions