Looping through valid inputs (VBA)

  • Thread starter Thread starter desireestar
  • Start date Start date
D

desireestar

How to write a simple program to:


Test all possible combinations of adding two numbers that range from
1-100 each (10,000 total possible combination) using some sort of
looping structure.



My guess (and I'm new at programming) is that there will be some sort
of nested loops but the logic escapes me.
 
Not sure what you want to test but

for N = 1 to 100
for M = 1 to 100
'perform test
next
next

will give you the loop structure you want.
 
Do you want to produce all possible sums (2-200), or are you searching for all combinations which produce a particular sum?

I guess it's not clear what you mean by "test".
 
Dim intA As Integer
Dim intB As Integer

For intA = 1 To 100
For intB = 1 To 100
Me!txtTotal = BlackBox(intA, intB)
Next
Next

How can I tell if it's gone through all 10,000 possible combinations
for testing purposes? Do I need to put it inside another For Loop?

(blackbox is a simple method that just adds two ints together)
 
Dim intA As Integer
Dim intB As Integer

For intA = 1 To 100
For intB = 1 To 100
Me!txtTotal = BlackBox(intA, intB)
Next
Next

MsgBox "All done now"

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
Heh, yeah. I mean to produce an actual number as to how many times it
looped total.

Ie:
MsgBox "This looped " + loopCountTotal + " times"
 
Dim intA As Integer
Dim intB As Integer
n=0

For intA = 1 To 100
For intB = 1 To 100
n=n+1
Me!txtTotal = BlackBox(intA, intB)
Next
Next

MsgBox "This looped " & n & " times"

should do the job for you I think....


HTH
DS
 
Dim intA As Integer
Dim intB As Integer

For intA = 1 To 100
For intB = 1 To 100
Me!txtTotal = BlackBox(intA, intB)
Next
Next

MsgBox "All done now - after " & (intA - 1) * (intB - 1) & " iterations"


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
DS's solution is for those who don't trust the system.
Bob Phillips is for those with faith in something as well established as For
Next loops to actually work.

You could combine the two in your MsgBox output to compare the values
computed by each method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top