Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

I need help on ArrayList and AddArrayList

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-29-2009, 11:35 AM
Junior Member
 
Join Date: Aug 2007
Posts: 13
Default I need help on ArrayList and AddArrayList



I have this code:
'-----------------------------------------------------
Sub Globals
Dim c(0)
Dim p(0)
End Sub

Sub bTest_Click

AddArrayList("al")

c() = GetControls("Main.Form1")
al.add(c())
Msgbox(c(0))
c() = GetControls("fTest")
al.add(c())
Msgbox(c(0))

p() = al.item(0)
Msgbox(p(0))
p() = al.item(1)
Msgbox(p(0))

End Sub
'-----------------------------------------------------

There are 2 problems:

1 - if i call this sub twice, the second time i get an error because
"al" is already instanced, there are a way to know it or i must put a
flag?

2 - I add to "al" 2 different arrays, but when i retrive the values with
p() = al.item(0) and p() = al.item(1) i get the same result. Why?

thanks
claudio
Reply With Quote
  #2 (permalink)  
Old 05-29-2009, 02:32 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 4,463
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

What exactly do you want to do?

1) The AddArrayList("al") must be in the App_Start routine, so it is instanced only one time.

2) Do you need to check the controls for each Form ?
If you want the Controls for all Forms you schould use
c() = GetControls("")

3) al.Add(c()) doesn't do anything, you can only add single values.
If you replace in the first MsgBox line
MsgBox(c(0)) by MsgBox(al.Item(0) you will see nothing

Best regards.
__________________
Klaus
Switzerland

Beginner's Guide / User's Guide
Reply With Quote
  #3 (permalink)  
Old 05-29-2009, 02:56 PM
Junior Member
 
Join Date: Aug 2007
Posts: 13
Default

Quote:
Originally Posted by klaus View Post
What exactly do you want to do?

1) The AddArrayList("al") must be in the App_Start routine, so it is instanced only one time.

2) Do you need to check the controls for each Form ?
If you want the Controls for all Forms you schould use
c() = GetControls("")

3) al.Add(c()) doesn't do anything, you can only add single values.
If you replace in the first MsgBox line
MsgBox(c(0)) by MsgBox(al.Item(0) you will see nothing

Best regards.
1) ok, but for example AddButton() has the Form argument so i can search it at runtime with GetControls() function, with AddArrayList i have no way to inspect it at runtime.

What i'm tryng to do is to add arrays or structures to ArrayList to simulate dynamic arrays.

But it seams which when i add more then once the c() array to the ArrayList i change each item, in other words the array is passed by reference and there are no way to add dynamically created arrays.

Best regards
Claudio
Reply With Quote
  #4 (permalink)  
Old 05-29-2009, 03:23 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 4,463
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

Quote:
1) ok, but for example AddButton() has the Form argument so i can search it at runtime with GetControls() function, with AddArrayList i have no way to inspect it at runtime.
What do you mean with 'inspect it at runtime' ?

Could you post your test sbp file, so we see better what you are doing.

Best regards.
__________________
Klaus
Switzerland

Beginner's Guide / User's Guide
Reply With Quote
  #5 (permalink)  
Old 05-29-2009, 04:14 PM
Junior Member
 
Join Date: Aug 2007
Posts: 13
Default

Quote:
Originally Posted by klaus View Post
What do you mean with 'inspect it at runtime' ?

Could you post your test sbp file, so we see better what you are doing.

Best regards.
For "inspect at runtime" i mean to test if i have a variable instanced. For example when i add a button to a form with AddButton("Form1","Button1") i can find it with

Code:
controls() = GetControls("Form1")
For i = 0 To ArrayLen(controls())-1
  
If controls(i).Name = "Button1" Then 
    
msgbox("Yeah! found it")
  
End If
Next
But there is nothing similar for ArrayList.

As you can see, i'm still exploring the best practices in using b4ppc, thanks for help.

Claudio
Reply With Quote
  #6 (permalink)  
Old 05-29-2009, 05:32 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 4,463
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

If you use
controls() = GetControls("")
you will also get the ArrayList.

Attached a small program to show it.

Sorry, but I still don't understand the reason for the "inspecting at runtime".

Best regards.
Attached Files
File Type: sbp ArrayList.sbp (1.0 KB, 18 views)
__________________
Klaus
Switzerland

Beginner's Guide / User's Guide
Reply With Quote
  #7 (permalink)  
Old 05-30-2009, 07:53 AM
Basic4ppc Veteran
 
Join Date: May 2008
Location: Newcastle Upon Tyne - England
Posts: 271
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Code:
controls() = GetControls("Form1")
For i = 0 To ArrayLen(controls())-1
  
If controls(i).Name = "<font color="Red">Button1</font>" Then 
    
msgbox("Yeah! found it")
  
End If
Next
Please be aware that any control name returned by Basic4PPC is always all in lower case - regardless if you use capitals adding your control at design time or runtime. Try:

Code:
...
  
If controls(i).Name = "<font color="Red">b</font>utton1" Then 
...
Reply With Quote
  #8 (permalink)  
Old 05-30-2009, 11:11 AM
Junior Member
 
Join Date: Aug 2007
Posts: 13
Default

Quote:
Originally Posted by klaus View Post
If you use
controls() = GetControls("")
you will also get the ArrayList.

Attached a small program to show it.

Sorry, but I still don't understand the reason for the "inspecting at runtime".

Best regards.
Ok, the whole thing is if i can use ArrayList as a full functional dynamic array as i can find in other languages. As i can see, i can't, no problem i will find other ways to do things.

About "inspecting at runtime", is a common programming technique in dynamic languages, is called introspection.

Sometimes is useful, for example if i can retrive the names of controls i can automatically load fields from database record into textfields with the same name of db fields and at the end save back only the modified fields.

Fortunately i can do this task wit b4ppc and i really appreciated the quick and easy development cycle, but would be nice to have some more power in other fields like arrays usage and arrays as local variables.

Thanks for your help
Best regards.
Claudio
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Array and Arraylist junglejet Questions (Windows Mobile) 2 02-09-2009 06:52 PM
Generic "addarraylist" problem. dan kabestan Questions (Windows Mobile) 2 12-03-2008 03:41 PM
ArrayList Bobbes German Forum 2 02-25-2008 08:36 PM
Arraylist tvrman Questions (Windows Mobile) 7 07-01-2007 10:42 AM
listbox = arraylist ? sloopa Questions (Windows Mobile) 1 05-07-2007 12:38 PM


All times are GMT. The time now is 04:27 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0