2015-08-14 112 views
0

我正在使用VBScript處理傳入的文本消息。我有一個條件,如果傳入值低於數據庫中的值,則會向發送者發送一條消息。由於某些原因,即使值較高,消息集仍然正在發送。小於或等於不工作

基本上,變量arrmessage包含一個數字,例如300,然後將其與變量val進行比較,該變量是數據庫表中稱爲出價的最大值。因此,例如val = 10

當我放置arrmessage <= val then... elseif arrmessage > val then 它總是告訴我,arrmessage低於val,即使它更高。

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 
+1

你確定arrmessage和val都是數字,哪一個都不是字符串? –

+1

'arrmessage'從哪裏來?它可能是一個字符串? –

+1

'MsgBox TypeName(arrmessage)'報告什麼? – Bond

回答

1

我的猜測是,arrmessage不是數字,可能是這個問題在你update說法引起。圍繞arrmessage變量的單引號在字符串連接中的前面有一個空格,因此它總會爲您寫出的每個出價的結尾添加一個空格。事實上,我很驚訝,因爲where之前沒有空格,所以update也不會返回語法錯誤。另外,在準備update之前,您應該再次初始化之前明確關閉數據庫連接。