Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Filling an array or structure.


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-01-2008, 08:57 PM
Knows the basics
 
Join Date: Oct 2007
Posts: 90
Default Filling an array or structure.

I have tried various combinations without success.
can anybody please tell me, if it is possible to fill an array or structure in some way such as...
myArray=[[1,2],[3,4]]

to avoid the tedious...
myArray(0,0)=1
myArray(0,1)=2
myArray(1,0)=3
...
Reply With Quote
  #2 (permalink)  
Old 05-01-2008, 09:09 PM
Senior Member
 
Join Date: Mar 2008
Posts: 114
Default

Not sure what you want to fill it with but how about a For ... Next Loop?

'assuming MyArray is (5,5)

For X = 0 to 4
For Y = 0 to 4
MyArray[X,Y] = {value}
Next Y
Next X

... where {value} could be ...

MyVal = "001002003004005006"

and replace {values} with a formula such as ...

MyArray[X,Y] = substring (MyVal, Y + (X*4), 3)

... or something like that ...


... or {value} could be a sub/function you call which returns the next "data" values just like in the original basic, such as:


sub GetMyValue
myval = "trees,wood,metal,plastic,grass,water,etc,etc, etc"
' bit of code here to extract the next a-z characters until it reaches a comma and store it in "myval"
return myval
end sub



and the line would read

MyArray[X,Y] = GetMyValue

-----------------

or if you have lots of values, why not replace the subs inner code to read values from a text file to save the data values cluttering up your code...

Last edited by badkarma : 05-01-2008 at 09:22 PM.
Reply With Quote
  #3 (permalink)  
Old 05-01-2008, 09:24 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,683
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Erels' suggestion Filling arrays Use StrSplit

EDIT : I just realised you want to fill a 2D array - this may not help then.

Last edited by agraham : 05-01-2008 at 09:26 PM.
Reply With Quote
  #4 (permalink)  
Old 05-01-2008, 10:51 PM
Knows the basics
 
Join Date: Oct 2007
Posts: 90
Default

@badkarma, that looks interesting thank you, I'll have a play with it.
@agraham, thanks and I'll still look at the reference, there may be something in it.
Reply With Quote
  #5 (permalink)  
Old 05-02-2008, 09:22 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,683
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Looks like Erel read your mind. From this post http://www.basic4ppc.com/forum/showthread.php?p=12033
" Array methods - Including methods to easily fill 1d arrays and 2d arrays."
Reply With Quote
  #6 (permalink)  
Old 05-02-2008, 12:56 PM
Knows the basics
 
Join Date: Oct 2007
Posts: 90
Default

Thank you very much agraham. Sorry I didn't find it myself.
[Edit] Seeing the date I now know why.

Last edited by enonod : 05-02-2008 at 12:58 PM.
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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Header structure Erel Beta Versions 3 08-27-2008 08:37 PM
Filling 2-D arrays. grgczyz Basic4ppc Wishlist 1 02-14-2008 12:38 PM
Filling arrays Erel Code Samples & Tips 3 01-13-2008 06:11 PM
Newbie-Filling a table but selected fields enonod Questions & Help Needed 7 10-13-2007 01:24 PM
Structure variables Erel Code Samples & Tips 0 05-19-2007 11:36 AM


All times are GMT. The time now is 12:07 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0