Basic4ppc - Windows Mobile Development  

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

Code Samples & Tips Share your recent discoveries and ideas with other users.


Filling arrays


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-09-2008, 07:14 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,185
Default Filling arrays

It is sometimes necessary to fill arrays with some known values.
The most straightforward method is:
Code:
array(0) = 2
array(1) = 3
...
For larger arrays this method is a little cumbersome.
A much cleaner solution is to use StrSplit.
StrSplit splits a string and returns an array.

First we declare the array in sub Globals as an empty array.
Later we load the data using StrSplit:
Code:
Sub Globals
    Dim data(0)
    Dim names(0)
End Sub

Sub App_Start
    data() = StrSplit("2,3,5,7,11,13,17,19,23" , ",")
    names() = StrSplit("John,Robert,Mike,Barbara" , ",")
    
    'Show all names
    For i = 0 To ArrayLen(names())-1
        Msgbox(names(i))
    Next
End Sub
Make sure that you don't leave any extra spaces inside the string.
Reply With Quote
  #2 (permalink)  
Old 01-12-2008, 07:08 PM
Junior Member
 
Join Date: Apr 2007
Posts: 15
Default Filling 2-D arrays ... is it possible?


I like this method very much however I wonder if it is possible to fill 2-D arrays similarly as 1-D arrays?
Reply With Quote
  #3 (permalink)  
Old 01-13-2008, 12:31 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,185
Default

Currently not. Maybe in a future version.
Reply With Quote
  #4 (permalink)  
Old 01-13-2008, 06:11 PM
Junior Member
 
Join Date: Apr 2007
Posts: 15
Default

It would be very useful ... thank you Erel
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
Filling an array or structure. enonod Questions & Help Needed 5 05-02-2008 12:56 PM
Passing arrays to Subs. jesb4ppc Questions & Help Needed 6 04-15-2008 06:03 PM
Filling 2-D arrays. grgczyz Basic4ppc Wishlist 1 02-14-2008 12:38 PM
Newbie-Filling a table but selected fields enonod Questions & Help Needed 7 10-13-2007 01:24 PM
Arrays of any size Gale Johnson Code Samples & Tips 5 08-17-2007 05:55 AM


All times are GMT. The time now is 03:17 AM.


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