Solved

Loop through an array?

Posted on 2002-05-26
7
174 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
7 Comments
 

Accepted Solution

by:
AlanSmithee earned 50 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now