Solved

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

Posted on 2006-10-30
6
188 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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hide vba in gp 7 95
Problem to With line 4 57
Excel VBA - Run Time error '1004' Application-defined or object-defined error 4 82
Send outlook email from VBS Script 2 30
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

773 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