Solved

Loop through an array?

Posted on 2002-05-26
7
177 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA error replacing data 6 40
VB6 Compile Compatibility Issue 4 115
using Access 8 75
Microsoft Access combo box help 2 50
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
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…

828 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