Forum Discussion

kaiiii's avatar
kaiiii
Regular Contributor
5 years ago

How can I check a function return type in another function in vb script.

How can I check a function return type in another function in vb script.

like there are 2 function.Kindly check below

 

Function A()

     Set obj = ----------something here-----

    If(Obj.Exists) then

         Log.message("ok")

    Else

        log.message("not ok")

    End IF

End Function

 

 

Function B()

     .....In this function i want to check status of function A... It's true or False----

so I can return value in boolean and check the same

End Function

  • Um... OK, so that's some basic VBScripting there.  Simply...

     

    Function A()
    
         Set obj = ----------something here-----
         A = Obj.Exists
    
    End Function

    And then, in function B

     

    Function B()
    
         If A then
              Log.Message("Object exists")
         else
              Log.Message("Object does not exists")
         End If
    End Function
  • You can try below scenario and check if it works for you

    Function A()

         Set obj = ----------something here-----

        If(Obj.Exists) then

             Log.message("ok")

             strResult=TRUE

        Else

            log.message("not ok")

           strResult=FALSE

        End IF

       A=strResult

    End Function

     

    Function B()

      strResult=A()

       If strRESUlt=TRUE Then

          log.Message"True"

    Else

         log.Message"False"

    End Function

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    > How can I check a function return type [...]

    so I can return value in boolean and check the same

     

    I am pretty sure that tristaanogre and rajulapati provided you with the answer you was looking for.

    But been a naughty old-school guy I can't but clarify:

    Considering your example and function A():

    -- Return type of function A() is of boolean type. To be perfectly correct, the return type of A() is OleVariant of boolean subtype. VarType() is the function that returns the subtype of the tested object/variable. All functions and variables in scripting languages (in VBScript) are of OleVariant type.

    -- As function A() is expected to return the boolean *type*, the returned *value* can be either True or False.

     

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor
      I am pretty sure that @tristaanogre and @rajulapati provided you with the answer you was looking for. But been an old-school naughty guy I can't but clarify:
      The snark is strong with this one.
      • sonya_m's avatar
        sonya_m
        SmartBear Alumni (Retired)

        Thank you everyone. A lot of great suggesions to choose from here:smileyhappy:

         

        Hi kaiiii, which one works for you best? 

  • You can try below scenario and check if it works for you

    Function A()

         Set obj = ----------something here-----

        If(Obj.Exists) then

             Log.message("ok")

             strResult=TRUE

        Else

            log.message("not ok")

           strResult=FALSE

        End IF

       A=strResult

    End Function

     

    Function B()

      strResult=A()

       If strRESUlt=TRUE Then

          log.Message"True"

    Else

         log.Message"False"

    End Function

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Um... OK, so that's some basic VBScripting there.  Simply...

     

    Function A()
    
         Set obj = ----------something here-----
         A = Obj.Exists
    
    End Function

    And then, in function B

     

    Function B()
    
         If A then
              Log.Message("Object exists")
         else
              Log.Message("Object does not exists")
         End If
    End Function