Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK 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? 1

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 anwear 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

Are you sure that this is Visual Basic? If so, which version?

Good Luck
johnwm
 
yes is visual basic.net
 
I would avoid using the '=' operator to compare values that are not integers (your variables are doubles). Due to how the computer stores numbers and rounding errors you may never end up with 'A0=1.0'. You may get 0.999999999... or 1.000000000003 which would then put you in an infinite loop situation.

Now if you explain more of what you are trying to do we can help you. My best guess is that you are trying to normalize an array. If that is the case why not just take m(0,0) and that is what you need to divide by to get A0=1.0 (ie k=m(0,0)).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor