How can i declare an array as string to be share to whole structure
I’v read about it in the forum…some talk about dictionary ???.. or constant
As newbie is seem complicate
Is there a easy way to do it
Thanks
Add a Module to your project and then add a public or protected property to the module with a declaration of:
myArray() as String
If you choose Public, you can just use myArray in your code. If Protected, you will need to use Module1.myArray (which is handy if you name the module something like Security for keeping security based methods, classes and properties together)
i feel like very newbie
where i fill up MyArray = Array("one","two","three","four")
when i try to reach it… MsgBox str(myArray(1))
i’v got Out of bound exception
Did i mention newbie
My guess is that you’ve made MyArray a property of the window as Greg advised, but you are still using Dim MyArray() As String in your code. That will create a local variable MyArray in that method that will go away as soon as the method finishes. Creating an array property has already Dim’d it so just use it without the additional Dim.
no Kem
i’v create a new project… just to test
with a break…and i see in global… MyArray(-1)… so empty
my two guess are
1- the syntax of MyArray = Array(“one”,“two”,“three”,“four”)
2-Where i put MyArray = Array(“one”,“two”,“three”,“four”)… in the window property or in “Default” textfield of property
neither work
[quote=82916:@Denis Despres]MyArray = Array(“one”,“two”,“three”,“four”)
when i try to reach it… MsgBox str(myArray(1))
i’v got Out of bound exception[/quote]
You got MyArray = Array("one","two","three","four")
right.
But do not str a string !
msgbox(MyArray(0))
will work.
no
MyArray is empty… before the msgbox
i miss something in filling up that array
Where in my code do i have to filling up the data
MyArray = Array("one","two","three","four")
i feel really dummy…i’v made more than that before
if you put anywhere these three lines together, it will work
Dim MyArray() as String
MyArray = Array("one","two","three","four")
MsgBox MyArray(1)
thats the way i did local…it work but local only
Now i try to declare MyArray in property(global) of module1
the msgbox is in mainwindow and the break tell me that MyArray is empty
Create a new “Destop” project called “MyArray”
Add the “Open” event handler for “main” “Window1”.
Add the following code in the “Open” event handler of Window1.
Call SetMyArray.SetMyArray
Add a Module called “SetMyArray”.
Add the Property having Name = MyArray() and Type = String to this Module.
Add a Method “SetMyArray” to the Module “SetMyArray”. Makse sure the Scope = Global.
Add the following code in the “SetMyArray” Method.
MyArray = Array( "One", "Two", "Three", "Four")
MsgBox( MyArray(1))
Make sure the “App” is showing “DefaultWindow” = “Window1”.
When the above project is run that it should display an untitled message box with text = “Two”. When the message box is dismissed with “Ok” button then the blank main Window1 should be displayed.
If the code below is moved from the “SetMyArray” method of “SetMyArray” module and in to the Window1 “Open” event handler before calling “SetMyArray.SetMyArray” then this should also work and still the MsgBox called from the “SetMyArray” method will display the text = “Two” because the “SetMyArray” module property “MyArray” is global in scopy and is visible to all the code in this project.
MyArray = Array( "One", "Two", "Three", "Four")
And the answer is
Fill up MyArray = Array( "One", "Two", "Three", "Four")
at the open event
thank you syed