Solved

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

Posted on 2006-10-30
6
191 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

729 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