Array in module

Hello All,

I am old user of RB (2009), i have recently switched to xojo.

I try to create module with array. But i needed only one instance of module, but this instance is used on all app.

I create module named ‘Wave’ , after i create classe named ‘Info’ with public scope.
Under Info i create 2 Properties ‘Name’ & ‘Description’ in string with public scope.
Works perfectly.

After i needed the create another class in Wave module named ‘Preheating’ with only 2 propreties ‘Time’ & ‘Temperature’ in integer with scope plublic. I add () for array in name of properties.

For test, in Windows form, in Event Handlers i write :
Wave.Preating.time(1) = 100

I clic run, the debboger stop on this line, but no message.

My question, how to create array ou other similaire in classe in module.

Thanks for you help.
Olivier

Wave.Preating.time(1) = 100

Does the time array have an element 1?
If I were you I would check the preheating.time.ubound to make sure you actually have an array element that you can amend.

The error message you say you don’t see will be a nil object exception: there is no time(1) ?

Hi Jeff,

Thanks to reply. I have checked the error is ubound.
I have tested whit: Wave.Preating.time() = Array (100)

It’s works, but is not good for my, because the ‘Array’ instruction replace the old value, not add.

I not found another method for dynamic array.

Thanks
Olivier

You should read the introduction to the Xojo programming language.
Xojo Documentation
Start with Book 1: Fundamentals (176 pages).
The introduction to arrays starts on page 87.

If I am reading your original post correctly you created a data class with the name Preheating and then you added two properties to that data class named Time and Temperature. Now you want an array of Preheating data classes if I am understanding you correctly,

In the module declare a new property. I will call it myPreheats. So, in the Name field put myPreheats(-1) and in the Type field enter Preheating, the name of the class that you created. You have now told the app that you want an array, myPreheats of the class Preheating. You don’t know the final size of the array, you will just append the values as needed.

In your code where you want to add an entry to that array put the following:

myPreheats.append new PreHeating
n = uBound(myPreheats)
myPreheats(n).Time = nn
myPreheats(n).Temperature = nn

That creates a new element in the myPreheats array. You can then get what that element number is using uBound and then assign values to Time or Temperature.

If I misunderstood your post and Preheating and Info are not data classes then just ignore what I have posted here.

Thanks to all, i have read the online help, the pdf is more complete.

if i use wave.preheating.time.append(100) it’s works perfectly

Many thanks
Olivier