[Gambas-user] Re: casting or changing datatype.
ron
ronstk at ...239...
Sat Jan 14 17:46:34 CET 2006
On Saturday 14 January 2006 15:07, Benoit Minisini wrote:
> But I think what is wanted is the old request of controls indexed by name,
> like in Visual Basic?
I do not think so, but I have seen you had some code for it in the past
versions before 1.0 (seen in 0.7x or so).
VB does indexing by number but you can refer to the .Name property
Iterate the indexed controls by number in a VB control array with
for i = 0 to MyForm.MyAccount.Count -1
Print MyForm.MyAccount[i].Name & " = " & MyForm.MyAcount[i].Value
next
will give the same name for all controls in VB.
Making the array is done by using the same name and increment the index.
Runtime add of same control to the array does the same name and increment.
For VB the array contains always the same control
For Gambas the array contains same or different controls, more advanced.
What you asume above is using a name as substitute for the index number.
Not that bad to have also possible.
The .Name in VB for the group is the .Group you add to gambas.
There is no need to have the .Name the same as in VB anymore.
The old request you mentioned was to be able to use .Name of the control.
A TextBox on the Form with name 'txtboxUserName' in design and in code the
'txtboxUserName_event' can provide 'txtboxUserName.Tag' but not the
'txtboxUserName.Name', wich is "txtboxUserName" .
Simple the .Name property in runtime available for the control.
Using the beatifull Last it could be nice to know the .Name of it to
determine what to do.
The VB group is done by .Name+.Index and in Gambas by .Group
The .Name is used in design and entering the code for reference.
Your way of grouping for i.e. account-group properties of different controls
working on a what_ever event without consider to the control type.
if Last.Index=1 then Last.Value = "MyName"
if Last.Index=2 then Last.Value = "YourName"
if Last.Index=3 then Last.Value = 1000
Using the .Name property as substitut for .Index you get if
'accountGrp' is the .Group name and Last is a control in that group.
Sub accountGrp_event()
If Last.Name="txtUser" then Last.Value = "MyName" ' or txtUser.Value = "MyName"
If Last.Name="txtOther" then Last.Value = "YourName"
If Last.Name="Price" then Last["Price"].Value = 1000 ' or Last[Last.Name].Value = 1000
End Sub
In my view more clear, and VB can't do that, the "Price" index.
Add and delete controls to the group and changing the index number
When using numbers you must constant check for the number in the form design
Special when you add 5 more, and have writen the numbers down.
Delete the 3'rd and the remaining get another number.
With using the Name property, as index, you can refer to the exact control
in a array group.
I personaly think .Name should be possible in future. Some reasons,
1 for porting VB to Gambas is more easy.
2 reference to myAccount["User"] and myAccount["Address"] is more friendly
opposite to myAccount[1] and myAccount[2] where myAccount is a
TextBox control Group with index by number.
Using tag can be done but the tag gives more comfort for other purpose
as storing i.e. the old content for undo or as storage for many other,
more complex things instead simply a name.
my 2 cents
Ron
More information about the User
mailing list