Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why it doesnt work?

Status
Not open for further replies.

enque

Civil/Environmental
Dec 7, 2002
20
why this code doesnt work?? if i put k += 1 it gives the correct anwer k = 6
*Whats going on?

Sub Main()

Dim m As Double(,) = {{6, 2, 6}, {1, 3, 7}}
Dim k As Double
Dim A0 As Double
Do Until A0 = 1.0
k += 0.1
A0 = m(0, 0) / k
Loop
Console.WriteLine("k is " & k)
 
Replies continue below

Recommended for you

Try defining the value of array as follows

Dim m As Double(,) = {{6.0, 2.0, 6.0}, {1.0, 3.0, 7.0}}

 
1) In VBA += is not a valid operator.
2) The exit condition for loops should never depend on comparing floating point numbers. Due to how the computer stores numbers you may end up with A0=1.0000000001; which does not equal 1.0 and the loop would keep going.

It looks like you want to normalize an array. In this case k=1/A0, no need to loop to find the value of k.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor