![]() |
|
|||||||
| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| Questions & Help Needed Post any question regarding Basic4ppc. |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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 ... |
|
|||
|
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. |
|
||||
|
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. |
|
||||
|
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." |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |