Blogs

  • Browse Blogs
  • My Blog
  • My Updates

Tags Help

  • View as cloud  | list

Similar Entries

photo

Compile Problem fixe...

Blog:  Jan Schulz
Jan Schulz
Updated 
No Ratings 0     No Comments 0
photo

Sending Designer int...

Blog:  Jan Schulz
Jan Schulz
Updated 
No Ratings 0     Comments 1
photo

I was wrong: plus is...

Blog:  Yellow is the...
Tim Tripcony
Updated 
No Ratings 0     Comments 2
photo

Recompile in 8.0.2

Blog:  Urs Meli
Urs Meli
Updated 
No Ratings 0     No Comments 0
photo

Extending a Java Cla...

Blog:  .Domino Frame...
Peter Presnell
Updated 
No Ratings 0     No Comments 0

Jan Schulz

Blog Authors:  Jan Schulz  

Previous |  Main  | Next

How to test if an array is initialized?

Jan Schulz  |     |  Tags:  lotusscript array  |  Comments (1)
I like to write code like this:


public function getSomething() as Something
if oSomething is nothing then
set oSomething = new Something()
end if
set getsomething = oSomething
end function

How do this with dynamic arrays? I was very surprised when this threw an error:


dim arrSomethings() as Something
if isArray(arrSomethings) then print ubound(arrSomething) ' unitialized array error when calling the ubound function

You have to call a redim arrSomething(0 to 0) bevor you can do anything with that array. I tested it with every isXYZ function I could find in the designer help, but i couldn't find a way to detect that...Somehow I agree with Tommy Valand: LS Arrays are strange. Give me a Java collections like API and I'm happy :-)

BTW: datatype (arrSomething) gives "8738", even after the redim, but the designer help says that "8704" is a Dynamic array. Bug?

Comments

1 Erik Werfel      Permalink I've seen the technique of initializing only when necessary referred to as lazy initialization, and it's a pretty cool technique. Unfortunately, there doesn't seem to be a simple way to determine whether a dynamic array as been redimmed.

You have a couple of options: trap the uninitialized array error, and redim only when you get the error; or have a flag variable that you set when you redim the array, and check the flag before redimming.

The 8738 you see as the datatype of your array is telling you that you have an array of user-defined objects -- 8704 for the dynamic array plus 34 for the user-defined objects. There's a note at the bottom of the help entry:

If the argument to DataType is a list or an array, the return value is the sum of the value that represents a list or an array plus the value that represents the data type of elements of the list or array. For example, a fixed array of Integers is 8194 (that is, 8192 + 2); a list of Variants is 2060 (that is, 2048 + 12).


So I think that's working as documented.




Previous |  Main  | Next
Skip to main content link. Accesskey S
IBM Lotus Connections Help Tools About

Tags

A tag is a keyword that is used to categorize an entry. To view the entries with a particular tag, click a tag name or enter a tag in the box.
The tag cloud indicates the frequency of tag use. Popular tags appear darkest. The slider control adjusts how many tags are displayed in the tag cloud.