[jawsscripts] Re: Represent null in a comparison

  • From: Andrew Hart <ahart@xxxxxxxxxxxxx>
  • To: jawsscripts@xxxxxxxxxxxxx
  • Date: Thu, 08 Nov 2012 12:08:17 -0300

The usual way of doing this in JAWS script is to do something like this:

Var
Object oMyObject

If !oMyObject Then
   SayString("Error!  The object does not exist.")
EndIf

This has always worked for me.  I'm guessing you could also compare the 
object var with the return from the Null function, e.g.,

if oMyObject==Null() Then
   SayString("Error!  The object does not exist.")
EndIf

Though the first method is neater and faster imho.  Don't waste your 
time doing other kinds of comparisons.  The only comparison that makes 
sense of Object variables is zero/non-zero.

The following should also work in theory, but I have never tried it.  It 
depends how clever/fussy that Script compiler type-checking/type-casting is.

if oMyObject!=0 Then
   SayString("Error!  The object does not exist.")
EndIf

btw, I should mention that null and empty are not the same concepts in 
VB.  Is Nothing is testing if an object variable or database entry is 
not set to any value, indicating an undefined object pointer or db 
entry.  vbEmpty, on the other hand, applies to strings and is equivalent 
to "".  In JAWS script, if you want to check if a String is empty, it is 
best to use

If Length(mystring)==0 Then
...
EndIf

Although in mor recent versions of JAWS (since JAWS 13 if I remember 
correctly), the following should work:

If mystring=="" Then
...
EndIf

It is safer to test the length of the string as this works in all 
versions of JAWS.

Hth,
Andrew.

On 8/11/2012 10:50 AM, Andy B. wrote:
> In most languages, you can test for a null, nothing in VB, or empty object
> by doing this:
>
>
> C#: if (!vs_addon) {do something if it doesn't exist}
>
> VB: if vs_addon is nothing then do something if it doesn't exist end if
>
>
>
> How would you do this in a jaws script?
>
>
>
>
>
> __________ï
>
> View the list's information and change your settings at
> http://www.freelists.org/list/jawsscripts
>
>
>


__________ï

View the list's information and change your settings at 
http://www.freelists.org/list/jawsscripts

Other related posts: