Micro Focus QTP (UFT) Forums
correct use of OR statement - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: correct use of OR statement (/Thread-correct-use-of-OR-statement)



correct use of OR statement - lotos - 06-02-2011

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?!


RE: correct use of OR statement - sundari.msls - 06-02-2011

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



RE: correct use of OR statement - lotos - 06-02-2011

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?!