Solved

Loop through an array?

Posted on 2002-05-26
7
173 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Expert Comment

by:AlanSmithee
Comment Utility
Daffy,

You're so right.
I stand corrected. Thanks

AS
0
 
LVL 3

Expert Comment

by:daffyduck14mil
Comment Utility
Welcome...

Grtz.©

D.
0
 

Author Comment

by:ADawn
Comment Utility
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
Comment Utility
ADawn,

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

Bye

AS
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

763 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

7 Experts available now in Live!

Get 1:1 Help Now