I'm trying to get a Excel vba macro working. The code I'm using is the following :
Dim foo, bar, toto As Double
Dim nb As Integer
nb = 1
For bar = 1 To 1 Step 0.2
For toto = 1 To 4 Step 0.2
For foo = 1 To 2 Step 0.2
Cells(nb, 1).Value = CStr("bar " & bar & " toto " & toto & " foo " & foo)
nb = nb + 1
Next foo
Next toto
Next bar
End Sub
I would expect to see the case toto=4 printed. The end result I'm getting is :
bar 1 toto 1 foo 1
bar 1 toto 1 foo 1.2
bar 1 toto 1 foo 1.4
[....]
bar 1 toto 3.8 foo 1.6
bar 1 toto 3.8 foo 1.8
bar 1 toto 3.8 foo 2
Variable foo is going as expected from 1 to 2 and incrementing by 0.2 each times. On the other hand, variable toto is going from 1 to 3.8 instead of going up to 4.
How can I change my code in order for toto to reach 4 ? I tried changing the upper value of my for loops to (max + 1 step), and for toto it worked but for foo and bar their was an "extra" loop.
I tried to change the code to a while based approach, with no success either.
bar = 1
toto = 1
foo = 1
nb = 1
While (bar <= 1)
toto = 1
While (toto <= 4)
foo = 1
While (foo <= 2)
Cells(nb, 4).Value = CStr("bar " & bar & " toto " & toto & " foo " & foo)
nb = nb + 1
foo = foo + 0.2
Wend
toto = toto + 0.2
Wend
bar = bar + 0.2
Wend