[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Loop Statement - Incrementing a String

Posted on 2001-06-21
5
Medium Priority
?
179 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 200 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 53

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

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.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

649 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