New topic: 

How to nullify a variable (Nil)

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

         Page 1 of 1
   [ 2 posts ]                 Previous topic | Next topic          Author  
Message        wex-alpha          Post subject: How to nullify a variable 
(Nil)Posted: Fri May 11, 2012 8:09 am                         
Joined: Mon Jul 30, 2007 5:03 am
Posts: 93
Location: Sarajevo - Bosnia                Hello,

How can I set this to null:

dim s as string
s= nil // wont work


Thanks    
                             Top                arthofer          Post subject: 
Re: How to nullify a variable (Nil)Posted: Fri May 11, 2012 8:45 am             
            
Joined: Tue Feb 14, 2012 5:39 am
Posts: 70
Location: Austria                I'm not 100% sure, but since a string is a 
data type and not an Object, you cant set nil to it.

The documentation also lists Boolean, Byte, CFStringRef, Color, CString, 
Currency, Delegate, Double, Int16, Int32, Int64, Int8, Integer, OSType, 
PString, Ptr, Short, Single, String, UInt16, UInt32, UInt64, UInt8, UShort, 
Variant, WindowPtr, WString as data types.

Everything else (TextArea, TCPSocket) is subclassed from the "object" class, 
which means that it may be nil.

One workaround for you would be the use of the Variant datatype.
Since a Variant is not a data type, you may assign nil to it.
Quoted from the documentation: "Variant: Class (inherits from Object)"

This may be useful if you want to seperate between a string with the length 0 
and a nil string.
dim name as Variant

'Your code does its magic here
name = nil
'End of the magic

if name = nil then
  MsgBox "No name entered"
else
  MsgBox name
end

TL;DR: Primitive data structures are not objects, so they cant be nil.      
_________________
Thomas Arthofer

  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 2 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