Results 1 to 12 of 12

Thread: [RESOLVED] Loops making me loopy!

Hybrid View

  1. #1

    Thread Starter
    Addicted Member oldmcgroin's Avatar
    Join Date
    Jul 2005
    Location
    Manchester, UK
    Posts
    182

    Re: Loops making me loopy!

    i'm getting wierd results doing it like this. for starters it automatically sets the total as 500. if i put in a number 5 it sets the total as 500, if i put in 6 then it sets the total as 504, putting in 3 sets its as 502. very strange.

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Loops making me loopy!

    If you put in the DEBUG.PRINT statements you can "step" through the code one line at a time (with F8) and watch exactly what is going on.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3
    Member
    Join Date
    Jun 2005
    Posts
    51

    Re: Loops making me loopy!

    That's because 6 and 3 don't go evenly into 500

    EDIT: I found another problem. At the bottom of your code:

    This
    txtTotal.Text = Total

    Should be this
    Total = txtTotal.Text
    Last edited by millertime; Sep 5th, 2005 at 10:46 AM.

  4. #4

    Thread Starter
    Addicted Member oldmcgroin's Avatar
    Join Date
    Jul 2005
    Location
    Manchester, UK
    Posts
    182

    Re: Loops making me loopy!

    i know what its doing now. its just looping any number i put in until the total is over 500 when it stops.

    well i'm a bit confused about the question now. i can't see how i can do this question using loops.

  5. #5
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Loops making me loopy!

    Quote Originally Posted by oldmcgroin
    i'm getting wierd results doing it like this. for starters it automatically sets the total as 500. if i put in a number 5 it sets the total as 500, if i put in 6 then it sets the total as 504, putting in 3 sets its as 502. very strange.
    you are doing :
    Code:
    Static Total As Integer
    Total = 0
    This way Total will never be increasing.

    This one should work:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub cmdOk_Click()
    4.     Static Total As Integer
    5.     If Total >= 500 Then
    6.         MsgBox "Total Capacity Reached"
    7.         Exit Sub
    8.     ElseIf Not IsNumeric(txtNumber.Text) Then
    9.         MsgBox "Not a number"
    10.         Exit Sub
    11.     End If
    12.     Total = Total + txtNumber.Text
    13.     txtTotal.Text = Total
    14. End Sub

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width