Solved

Loop through an array?

Posted on 2002-05-26
7
180 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 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
Technology Partners: 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

691 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