| |
Yutaka
Posts: 5
Score: 0
Joined: 2/8/2003
From:
Status: offline
|
Dear Sir, I got a little problem for this VBScript. I'm using PWS on Windows 98 and also use Microsoft SQL 7 to store my data. Later will use SQL statement to call them and display in VBScript, ASP or HTML. The purpose of my programming would be searching for a string that contains fix keyword. Example: When I enter this question: who are the doctors specializing in eye diseases ? And I set the condition, if the question contains "Who" and "Eye". It will display the result. When I enter this: who are the doctors specializing in eye diseases ? It will display "Dr.Yeoh is specialize in eye diseases." But when I enter this: who are the doctors specializing in heart diseases ? It will display "Dr.Yeoh is specialize in eye diseases." Meaning that it will take the first IF THEN condition. I don't know what is wrong. I want to put the "AND" in the IF statement, but it doesn't work. And I put the "OR" then it works, but I don't want "OR". Logically, I think this should work as follows: If (a_strResult(i) = "Who" or a_strResult(i) = "who") AND (a_strResult(i) = "Eye" or a_strResult(i) = "eye") Then But it doesn't work, when I put the "AND". Another problem that is, when I enter the string which is not in the IF THEN statement. Example: when I enter "how are you?" It should display "sorry, result not found" one time. But it displays three times "sorry, result not found. sorry, result not found. sorry, result not found" Anyone know how to fix all of these problems? Later I need to replace Response.Write by SQL statement Like this: sqlstmt = "Select * from xxx WHERE xxxxx = 'xxxx'" The VBScript would be as follows: <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <% Option Explicit Dim strInput Dim a_strResult Dim i Dim found found = 0 strInput = Request.Form("query") a_strResult = Split(strInput, " ") For i = 0 To UBound(a_strResult) if(found = 0) then If (a_strResult(i) = "Who" or a_strResult(i) = "who") or (a_strResult(i) = "Eye" or a_strResult(i) = "eye") Then Response.Write "Dr.Yeoh is specialize in eye diseases." found = 1 Else if (a_strResult(i) = "Where" or a_strResult(i) = "where") or (a_strResult(i) = "Hospital A" or a_strResult(i) = "hospital A") Then Response.Write "Hospital A is located at York Road." found = 1 Else if (a_strResult(i) = "Who" or a_strResult(i) = "who") or (a_strResult(i) = "heart" and a_strResult(i) = "heart") Then Response.Write "Dr.Heart is specialize in heart diseases." found = 1 Else Response.Write "<font color='red'>sorry, result not found.</font>" End If end if %> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <% End if End if Next %> </body> </html> please kindly reply to cbkai2@yahoo.com thank you
|
|