View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Increment for or do while loop by 0.001 (not 1)

this should get you started:

Sub abc()
Dim i As Double
Dim sStr As String
For i = 1 To 2 Step 0.1
sStr = sStr & i & vbNewLine
Next
MsgBox sStr
End Sub

--
Regards,
Tom Ogilvy

"Han" wrote in message
ups.com...
What I am trying to do: increment for loop or do while loop by 0.001
----------------------
My for loop (I don't know how to increment by 0.001, this code just
increments by 1):
----------------------
For X = 0 To 10 'For X between 0 and 10 incremented by 0.001
For Y = 0 To 10 'For X between 0 and 10 incremented by 0.001
Fnew = X * Y * Exp(1 - 2 * X) * Sin(Y - X) * (1 - Y ^ 2) 'Given
function
If Fold <= Fnew Then 'If previous value of function is less
than current value of f then...
xmax = X 'Store value of X for max value of F
ymax = Y 'Store value of y for max value of F
Fold = Fnew 'Update the function
End If 'End if statement
Next 'End inner for loop (Y loop)
Next 'End outer for loop (X loop)

----------------------
My do while loop (I tried incrementing by 0.001, but the answer is not
what I want):
----------------------
Do While X <= 10
Do While Y <= 10
Fnew = X * Y * Exp(1 - 2 * X) * Sin(Y - X) * (1 - Y ^ 2) 'Given
function with new X and Y value
If Fold <= Fnew Then 'If previous value of function is less
than current value of f then...
xmax = X 'Store value of X for max value of F
ymax = Y 'Store value of y for max value of F
Fold = Fnew 'Update the function
End If 'End if statement
Y = Y + 0.001
If Y 10 Then Exit Do
Loop
X = X + 0.001
If X 10 Then Exit Do
Loop

----------------------
My Question for the do while loop: why am I not getting an xmax = 0.215
and ymax =10.000? I think this is these are the correct answers.
----------------------