[Gambas-user] Substitute of the object names

Rolf-Werner Eilert eilert-sprachen at ...221...
Thu Oct 7 10:22:03 CEST 2010


Ok, there is one thing you have to take care of, because Gambas works as 
C++ here and wants the arrays to be instantiated after declaration. So 
to make it easy, just add a NEW to the DIM line:

DIM x AS NEW String[20]

And now let me see how I did this in my programs... It's been a long 
time since I needed that:

In the Form declaration part, I have

PRIVATE mTxt AS NEW Object[]

In the Form there is a TabStrip, and on this TabStrip the "fields" 
(TextBoxes) shall appear. The TabStrip for this "mask" is called 
"Maske". (fldNr is the field number) In the SUB which builds the mask, I 
wrote for example:

         INC fldNr
         mTxt.Resize(fldNr + 1)
         mTxt[fldNr] = NEW TextBox(Maske) AS "MaskeFeld"
         mTxt[fldNr].Tag = wert[8] 'fldNr
         mTxt[fldNr].ToolTip = wert[8]
         mTxt[fldNr].X = Val(wert[2])
         mTxt[fldNr].Y = Val(wert[3])

A new TextBox-Object is created, and then some values are applied which 
come from another array ("wert"). But why did I need to declare AS 
"MaskeFeld"? Just to be able to catch events like

PUBLIC SUB MaskeFeld_Change()

   MaskenSpeichern

   'the contents of all the TextBoxes is saved if you type into one of them

END

Caution: In order to delete the TextBoxes, you have to delete them piece 
for piece from the array prior to deleting the array, such as

FOR i = mTxt.Count - 1 TO 0 STEP -1
     mTxt[i].Delete
NEXT
mTxt.Clear

Hope this helps you...

Regards

Rolf


Am 07.10.2010 09:04, schrieb Biro Zoltan:
> Thank you Rolf to helping me.
> Please take a look on the folowing piece of code:
> (I never used array of texboxes, but I think is something like I did
> here)
>
> PUBLIC SUB filltheboxes()
>
>   DIM x AS String[20]
>   DIM y[20] AS TextBox
>   DIM i AS Short
>
>   x[0] = "1"
>   x[1] = "2"
>   x[2] = "3"
>   x[3] = "4"
>   x[4] = "5"
>   x[5] = "6"
>   x[6] = "7"
>   x[7] = "8"
>   x[8] = "9"
>   x[9] = "10"
>   x[10] = "11"
>   x[11] = "12"
>   x[12] = "13"
>   x[13] = "14"
>   x[14] = "15"
>   x[15] = "16"
>   x[16] = "17"
>   x[17] = "18"
>   x[18] = "19"
>   x[19] = "20"
>
>   i = 0
>   FOR i = 0 TO 19
>    y[i].text = x[i]
>   NEXT
>
> END
>
> Why this code return a "Null object" error code??
>
> I hope to can be solved in Gambas2 more simply the substitute problem. I
> used before FoxPro for Windows. Here is simple:
>
> i=1
> for i=1 to 20
>    boxname="n"+str(i)
>    &boxname.text=" enithyng "
> endfor
> Is something in Gambas2 similar for&boxname.text, like in Foxpro?
>
> For me the second variant seems to be more simply, but please explain me
> why I have "Null object" error on the gambas2 code
>
>
> 2010. 10. 7, csütörtök keltezéssel 08.23-kor Rolf-Werner Eilert ezt
> írta:
>> Am 07.10.2010 08:11, schrieb Biro Zoltan:
>>> Hello,
>>>
>>> I will try to explain with my poor english exacly what I wish to do:
>>>
>>> 1.I have 20 pcs of valueboxes named: n1,n2,n3...n20
>>> 2.I have a variable named i defined as short
>>> 3.I wish to substitute the numbers from the valueboxes name like in
>>> folowing example:
>>>
>>> i=0
>>> for i=0 to list.count
>>>
>>>    'here I wist to give values to the valueboxes:
>>>
>>>    ni.value=list[i].text
>>>
>>> next
>>>
>>> Can I substitute the numbers with the value of i? How?
>>>
>>> Thank you.
>>>
>>> Zoli B.
>>>
>>>
>>
>> Wouldn't it be easier to just make an array of valueboxes? That would
>> enable you to write
>>
>> ni[i].value = list[i].text
>>
>> and Gambas would have direct access to each of the valueboxes during
>> runtime.
>>
>> Regards
>>
>> Rolf
>>
>> ------------------------------------------------------------------------------
>> Beautiful is writing same markup. Internet Explorer 9 supports
>> standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2&  L3.
>> Spend less time writing and  rewriting code and more time creating great
>> experiences on the web. Be a part of the beta today.
>> http://p.sf.net/sfu/beautyoftheweb
>> _______________________________________________
>> Gambas-user mailing list
>> Gambas-user at lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
>
>
> ------------------------------------------------------------------------------
> Beautiful is writing same markup. Internet Explorer 9 supports
> standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2&  L3.
> Spend less time writing and  rewriting code and more time creating great
> experiences on the web. Be a part of the beta today.
> http://p.sf.net/sfu/beautyoftheweb
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user





More information about the User mailing list