New topic: 

Checking for a Nil argument -- Not working for me

<http://forums.realsoftware.com/viewtopic.php?t=38413>

         Page 1 of 1
   [ 3 posts ]                 Previous topic | Next topic          Author  
Message        basil.bourque          Post subject: Checking for a Nil argument 
-- Not working for mePosted: Wed Mar 30, 2011 6:09 pm                         
Joined: Thu Apr 15, 2010 10:41 pm
Posts: 209
Location: Seattle                I'm getting a compiler error when checking for 
a nil argument.

Why does this code fail in a brand new project in a new class?

Code:Sub bogusMethod(x as String)
  if x = Nil then
  MsgBox "Is Nil."
  end if
End Sub


Compiler reports:
Quote:Type mismatch error. Expected String, but got Nil

Shouldn't I be checking for a nil argument being passed? 
The docs explicitly say that a nil can be passed in place of a String.      
_________________
--Basil Bourque

Using REAL Studio 2010 r5.1 with Postgres 9.0.3 on Mac OS X 10.6.5
http://crafted-software.blogspot.com/  
                             Top                 Specialised          Post 
subject: Re: Checking for a Nil argument -- Not working for mePosted: Wed Mar 
30, 2011 6:30 pm                                 
Joined: Thu Aug 26, 2010 6:57 am
Posts: 181
Location: Sydney Australia                Code:if x="" then      
_________________
Regards

Chris Musty
Specialised Technologies Pty Ltd

Software | Electronics | IT | Multimedia

http://www.specialised.net.au
-----------------------------------------------
RB 2011r1 Enterprise on Win7 Ultimate, Ubuntu 10.10 on Virtualbox  
                             Top                 mjh          Post subject: Re: 
Checking for a Nil argument -- Not working for mePosted: Wed Mar 30, 2011 7:55 
pm                                 
Joined: Sun Feb 19, 2006 3:10 pm
Posts: 1175
Location: Hamburg, Germany                If I remember correctly, it used to 
be the case that the empty string was actually implemented as nil (though that 
was never documented) and that you could test a string for being nil 
(equivalent to testing it for being the empty string). This appears to have 
changed. While the Language Reference claims that “You can pass Nil for any 
of the string parameter types”, it appears you cannot (anymore – this used 
to be possible).

Btw, see 
http://www.declaresub.com/article/153/strings-can-be-nil-even-if-they-cant-be-set-to-nil.
 At the time (around 2008) you could write code such as

Code:dim s as String

MsgBox Str(s is nil)
but now the compiler complains about ‘is’ being used with a non-object (and 
if you replace ‘is’ by ‘=’ it complains about nil not being a string).  
    
_________________
Michael J. Hußmann 
http://digicam-experts.de  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 3 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to