vba - How to make For loop work with non integers -



vba - How to make For loop work with non integers -

the next code easy , outputs expected

code:

option explicit sub test_loop2() dim long = -3 3 step 1 debug.print next end sub

output:

the next code exiting due rounding

option explicit sub test_loop2() dim double = -0.3 0.3 step 0.1 debug.print next end sub

output:

what reliable method can utilize whilst retaining for loop ensure lastly value run in loop non integers?

eg = x y step z - y must reached if it's multiple of z

for = 0 0.3 step 0.1 0.3 in loop

for = 0 0.3 step 0.2 0.3 not in loop

floating point arithmetic screw if utilize double (or single) counter.

for counters, stick whole numbers. derive floating point value counter. example:

dim long dim d double = 0 6 d = (i - 3) * 0.1 ' or whatever formula needed debug.print d next

vba

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -