Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
correct use of OR statement
#1
Not Solved
Hi guys, I have a situation where I am trying to use the OR statement. And when I'm running the test, I observed that this statement is ignored (or it's not used in the right way). See the code bellow:
Code:
'querying a 'SELECT' event within DB
    Public Function DBSelect(sqlSelect, itemCode)
        Dim MyCheck
            If Browser("URL:=" & Environment.Value("baseUrl")).Exist Then
                set conn = createobject("adodb.connection")
                conn.open "DSN=" & Environment.Value("DBdsn") & "; UserID=" & Environment.Value("DBLoginName") & "; Password=" & Environment.Value("DBLoginPass") & ";"
                set rs = createobject("adodb.recordset")
            'get the value from DB
                rs.open sqlSelect, conn
                            ' running the select to find the field we need to know -> dBitem
                            dBitem = rs(itemCode)
                    ' checking the format of the string got as result of select DB
                    MyCheck = varType(rs(itemCode))
                    If MyCheck <> 8 or 1 or 9 or 0 Then
                            ' formating the value of the string - adding max 2 nr.'s after the dot (e.g.: 123.09)
                            dBitem = FormatNumber(dBitem, 2)
                            reporter.ReportEvent micPass, "Data BASE:", "the Data within DB for the field: '" & itemCode & "' is: '" &  dBitem & "'"
                        Else IF MyCheck = 1 or  MyCheck = 0 or MyCheck = 9 Then
                            reporter.ReportEvent micWarning, "Data BASE:", "The Data within DB is: 'Null' or there are no values for requested field; So the value was converted to '0.00'. The warning is to inform you that there is no data."
                            dBitem = "0.00"
                        Else If MyCheck = 8 Then
                            reporter.ReportEvent micPass, "Data BASE:", "the Data within DB for the field: '" & itemCode & "' is: '" &  dBitem & "'"
                        End If
                        End If
                    End If
                rs.close
            Else
                reporter.ReportEvent micFail, "ERROR:", "The browser was not found!"
            End If
        DBSelect = dBitem
    End Function

In my case I have the MyCheck = 8, and it is ignoring the first condition and checking it's conditions, but should go to the 3rd condition (Else If MyCheck = 8 Then)

I've tried next ways:
IF MyCheck = 1 or 0 or 9 Then
IF MyCheck = 1 or MyCheck = 0 or MyCheck = 9 Then

Can please anyone help me with right use of OR?!
Reply
#2
Not Solved
I think the below logic works for you. Usually when your are using the same variable mutliple times in a condition, you should use AND.
See the code below:

Code:
MyCheck =8
If MyCheck <> 8 AND MyCheck<> 1 AND MyCheck<> 9 AND MyCheck<> 0 Then
  MsgBox "Mycheck<>8"
ElseIF MyCheck = 1 AND MyCheck = 0 AND MyCheck = 9 Then
  MsgBox "MyCheck=1"
ElseIf MyCheck = 8 Then
  MsgBox "Success"
End If
Reply
#3
Not Solved
Hi sundari, thanks, but as I know the AND statement when it's used, means that all the conditions are true?! so in this case doesn't AND means that MyCheck <> 8, 1, 9, and 0?!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Executing statement and commiting statement via qtp unbeliever 6 20,638 01-07-2010, 07:11 PM
Last Post: unbeliever
  Is the split array method the correct tool for the job? qatestbrian 0 2,112 01-06-2010, 02:06 AM
Last Post: qatestbrian
  How to select correct list? rahul1234 1 2,376 10-14-2009, 12:55 PM
Last Post: Saket
Exclamation How to chk alert given is correct or not. mayur.bidkar 1 1,897 11-07-2008, 02:40 PM
Last Post: MR21135

Forum Jump:


Users browsing this thread: 1 Guest(s)