Solved

i need a simple way to add values (strings) to an array

Posted on 2006-10-30
6
181 Views
Last Modified: 2010-04-30
Hi

i am trying to add to an array a path to mypicture collection. i have the code to get the file paths and set array up using
Dim MyPicture() As String

how do i add to the array so i can access using

Image1(X) = LoadPicture(MyPicture(X))

Image1 is an array of 3 x 3 image boxes.

i have used array's in php but VB has me stuck

Mark
0
Comment
Question by:obantec
6 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 17832868
Greetings, obantec.

If I understand correctly you want to increase the size of the array by one element.  If that's right, then use the Redim Preserve statement.  Something like

    intArrLen = UBound(MyPicture)                   'Get the number of elements in the array now
    Redim Preserve MyPicture(intArrLen + 1)     'Increase the array by one element

Instead of going to this effort you might want to consider using a Collection object.  They behave somewhat like arrays, but are much more flexible.

Cheers!
0
 

Author Comment

by:obantec
ID: 17833030
Hi

I just want to be able to add a string to an array. the default size of the array needs to be 100

at start array has no data
then add 1 string to array so later i can access the array using an index.

example

Text4.Text = nameofarray(index) ' get string using an index number

i have not used Collection object but am will to learn

Mark
0
 
LVL 1

Accepted Solution

by:
Clivous earned 125 total points
ID: 17833272
Hi,

Do u mean this?

   Dim TheArray(100) As String
   
   TheArray(1) = "C:\Documents and Settings\beheerder\Mijn documenten\Mijn afbeeldingen\DSCN1450.JPG"
   TheArray(2) = "C:\Documents and Settings\beheerder\Mijn documenten\Mijn afbeeldingen\DSCN1451.JPG"
   TheArray(3) = "C:\Documents and Settings\beheerder\Mijn documenten\Mijn afbeeldingen\DSCN1456.JPG"
   TheArray(4) = "C:\Documents and Settings\beheerder\Mijn documenten\Mijn afbeeldingen\DSCN1457.JPG"
   
   Picture1.Picture = LoadPicture(TheArray(1))

Regards,
Hans
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:obantec
ID: 17833423
That's it!!!

i did not have the 100 so my array size was 0

All working as expected.

Mark
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 17833438
Hi Mark,

BlueDevilFan showed the usual way to change the dimensioning on an array; the one thig I have to add is that you
have to decalre such a variable without dimensions:

Dim MyPitcure() AS String

and not

Dim MyPitcure(99) AS String

Another alternative would be to use a Collection, which dynamically resizes as you add or remove elements,
or a Dictionary object.

Regards,

Patrick
0
 

Author Comment

by:obantec
ID: 17833558
Hi

i used 99 (0 to 99 = 100 inc!)

will look at Collection.

Thanks to all

Mark
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now