?
Solved

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

Posted on 2006-10-30
6
Medium Priority
?
197 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 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month16 days, 15 hours left to enroll

862 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