?
Solved

Loop through an array?

Posted on 2002-05-26
7
Medium Priority
?
184 Views
Last Modified: 2010-05-02
Hello,

The following string (Const) is changed in the code before I compile the program. The number of colors can change (I change these color in code before shipping app). Is there a way I can code the 'With cboStation' to account for any changes I make to the number of items I add to the CONST string. You'll notice that the string has four (4) items, but the With statement (in its present state) can only handle two (2)items. Is there a way to do a LOOP? or something?

Public Const gcon_strStations As String = "Blue:Red:White:Green"

Dim array_Stations() As String
array_Stations = Split(gcon_strStations, ":")
 
  With cboStation
      .AddItem array_Stations(0)
      .AddItem array_Stations(1)
  End With


Thanks

-ADawn
0
Comment
Question by:ADawn
[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
7 Comments
 

Accepted Solution

by:
AlanSmithee earned 200 total points
ID: 7035234
Hi,

Maybe this will work:

Public Const gcon_strStations As String = "Blue:Red:White:Green"

Dim intCount as Integer
Dim array_Stations() As String
array_Stations = Split(gcon_strStations, ":")
 
for intCount = LBound(array_Stations) to UBound(array_Stations) - 1
     cboStation.AddItem array_Stations(intCount)
next

bye
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7035280
Just a reminder, please update your open questions (you have been notified already by the EE Moderator):
Control (OCX) Reference Issue (I Think) Date: 03/17/2002 07:58AM PST
http://www.experts-exchange.com/jsp/qShow.jsp?ta=msaccess&qid=20277938
Access 2.0 (Stop after a date arrives) Date: 01/09/2002 05:17AM PST
http://www.experts-exchange.com/jsp/qShow.jsp?ta=msaccess&qid=20253108
Add User / Password to ADO Connection String Date: 04/01/2002 05:54AM PST  
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20283655
Points for [squid_oz] Date: 01/17/2002 04:00AM PST
http://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20256316

Thanks,
Anthony
0
 
LVL 3

Expert Comment

by:daffyduck14mil
ID: 7036942
Alan,

The code you send will leave out the last option in the string, UBound is the upperbound, no need to substract one of the total....

Grtz.©

D.
0
Independent Software Vendors: 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!

 

Expert Comment

by:AlanSmithee
ID: 7036989
Daffy,

You're so right.
I stand corrected. Thanks

AS
0
 
LVL 3

Expert Comment

by:daffyduck14mil
ID: 7036994
Welcome...

Grtz.©

D.
0
 

Author Comment

by:ADawn
ID: 7037026
Thanks AlanSmithee,

It works great if you remove the -1 as in:

for intCount = LBound(array_Stations) to UBound(array_Stations)

Thanks,

-ADawn
0
 

Expert Comment

by:AlanSmithee
ID: 7037035
ADawn,

Thanks.
I couldn't have done it without the help of Daffy. :)

Bye

AS
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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 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…
Suggested Courses

752 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