Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Repost: Modifying a loop

Posted on 2000-03-27
7
Medium Priority
?
139 Views
Last Modified: 2010-05-02
Ok, this is what I need the loop to do.
For i = 0 To 31

txtName(0).text=499
txtName(1).text=581 ' 499+82
txtName(2).text=663 ' 499+82+82
.........txtName(31)....
Below are the desired results, notice that at
txtName(16) the value is 539,
txtName(17) the value is 621 '539+82

0      499
1      581
2      663
3      745
4      827
5      909
6      991
7      1073
8      1155
9      1237
10      1319
11      1401
12      1483
13      1565
14      1647
15      1729
16      539
17      621
18      703
19      785
20      867
21      949
22      1031
23      1113
24      1195
25      1277
26      1359
27      1441
28      1523
29      1605
30      1687
31      1769

Thanks much
0
Comment
Question by:ptran2000
[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
 
LVL 14

Expert Comment

by:mcrider
ID: 2661311
I think this is what you want...


    Dim iVal As Long
    Dim jVal As Long
    jVal = 499
    For iVal = 0 To 15
        txtName(iVal) = CStr(jVal)
        jVal = jVal + 82
    Next iVal
    jVal = 539
    For iVal = 16 To 31
        txtName(iVal) = CStr(jVal)
        jVal = jVal + 82
    Next iVal



Cheers!®©
0
 
LVL 7

Expert Comment

by:Joe_Griffith
ID: 2661319
There are many ways to do this.  I think the most straight forward method is to break it into two loops:

  Dim i           As Integer
  Dim txtName(31) As Integer
 
  For i = 0 To 15
    txtName(i) = 499 + i * 82
  Next
  For i = 16 To 31
    txtName(i) = 539 + (i - 16) * 82
  Next
 
  For i = 0 To 31
    Debug.Print i, txtName(i)
  Next
0
 
LVL 7

Accepted Solution

by:
Joe_Griffith earned 200 total points
ID: 2661336
if it has to be in a single loop then try this:

  Dim i           As Integer
  Dim txtName(31) As Integer
 
  For i = 0 To 31
    If i < 16 Then
      txtName(i) = 499 + i * 82
    Else
      txtName(i) = 539 + (i - 16) * 82
    End If
  Next
 
  For i = 0 To 31
    Debug.Print i, txtName(i)
  Next
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:ptran2000
ID: 2661357
Any way I can make it with just one loop.  The reason is that I also need to add another element.
0
 
LVL 3

Expert Comment

by:wpsjr1
ID: 2661373
Dim i%, lValue&, lCounter&
 
  lValue = 499
  For i = 0 To 31
    If i = 16 Then: lValue = 539: lCounter = 0
    txtName(i).Text = CStr(lValue + (lCounter * 82))
    lCounter = lCounter + 1
  Next i

Enjoy!  :)

Paul
0
 

Author Comment

by:ptran2000
ID: 2661409
Joe Griffith has posted the answer first,  Joe please repost so I can give you the points

thanks
0
 

Author Comment

by:ptran2000
ID: 2661497
thanks much
0

Featured Post

Industry Leaders: 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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

598 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