×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Why it doesnt work?

Why it doesnt work?

Why it doesnt work?

(OP)
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)

RE: Why it doesnt work?

Try defining the value of array as follows

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

RE: Why it doesnt work?

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources