Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-10-30
6
Medium Priority
?
195 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 500 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 93

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

610 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