We help IT Professionals succeed at work.

VB Array

TungVan asked
Last Modified: 2010-05-03


I have an array of structure like this

Type Source

    Status      As Integer
    Date        As Integer
    Time        As Long
    Unit        As Integer
End Type

Global gtStoredSources(1 To MAX_SOURCES) As Source

Later in the code, I need to insert create a temporary Source struct and add it to the gtStoredSources. How do I know which position in the array is free so that I can insert that temporary Source?

Watch Question

High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
This one is on us!
(Get your first solution completely free - no credit card required)

I agree with Idle_Mind. That's probably the best thing to do, since all elements in the array are alreay Source-structures/types. I'm sure you can figure out how to do it, otherwise both Idle_Mind and I could give you some examples.





But I have another question as well. (I will increment the point for this question.)

Instead of 1-dimension array, this is going to be a 2-dimension array like this

gtStoredSources(1 to 2, 1 To MAX_SOURCES) As Source

The first dimension is fixed, but the 2nd dimension must be resizeable.

Can you give me an example of insert new record and delete record using Redim Preserve?


With a redim preserve, you can ONLY redim the first dimension. 2nd, 3rd, etc dimensions cannot be redimmed, without losing its data. This is because the first dimension actually sais: I have x numbers of my 2nd dimension. You can change the x, but not the number in the 2nd dimension. Maybe you can reverse it as follows:

gtStoredSources(1 To MAX_SOURCES, 1 To 2) As Source

Still you need to keep in mind that both dimensions are declared as "Source"...
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009


Do you specifically need a Type?

If you instead create a Class with those fields in it, then you can easily add/remove instances of that class from a Collection object without needing to adjust the size of the Collection because it grows/shrinks automatically.



I maintain the code of someone. If I have a choice, I would go with collection of classes. But here, I don't have choice..

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.