Solved

Loop Statement - Incrementing a String

Posted on 2001-06-21
5
174 Views
Last Modified: 2010-05-02
I wish to write a statement that allows me to add an increment to a string.
eg,
     repeat until i = 11
     i=i+1
     cat = "Number" + i
     

     so i get cat = "Number 1"
           cat = "Number 2"

Thanks
Dave Steers
0
Comment
Question by:dsteers
[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
5 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6213901
For i = 1 to 11
  cat = "Number " & i
next

Cheers
0
 
LVL 3

Accepted Solution

by:
cmgarnett earned 50 total points
ID: 6213916
dim intX as integer
dim strCode as String

   For intX = 1 To 9999
      strCode = "Number " & Format(intX, "0000")
      debug.Print strCode
   Next

This gives you "Number 0001" to "Number 9999"
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 6214027
Optional Code return same result:

Dim i As Integer
    i = 1
    List1.Clear
    Do Until i > 11
        List1.AddItem "Number " & i
        i = i + 1
    Loop
0
 
LVL 17

Expert Comment

by:inthedark
ID: 6214032
As cmgarnett suggests format is a good function. It handles null values which you will discover the more time you spend with VB.  So if you get in the habit it the best to use.  You can also use CSTR() and STR()

Format(123,"0") produces "123" ' output controlled by format string
Cstr(123) Produces "123"
Str(123) Produces " 123" ' adds a leading space or minus.

angelIII suggests using "& I" which is fine because it will work in your circumstaces.  It works by converting the number to a variant first then a string.  But if you use the & operator instead of the + (concatination) in other circumstances you may get problems.  So it is better to get into a habit of using Format, CStr or STR whenever  you need to convert numeric to string.   Others may not share this view.

hope this helps, inthedark.
0
 

Author Comment

by:dsteers
ID: 6224380
cmgarnet,
Thanks for your help and quick response.

Regards
Dave Steers
0

Featured Post

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!

Question has a verified solution.

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

Suggested Solutions

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…
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…
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…

738 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