+ Reply to Thread
Results 1 to 7 of 7

Loop Not Stopping

  1. #1
    Registered User
    Join Date
    05-24-2007
    Location
    Canada & France
    MS-Off Ver
    2007
    Posts
    40

    Loop Not Stopping

    The Loop starts but wont stop. I don't see anything wrong with the code.
    Please Login or Register  to view this content.
    Thanks
    Last edited by VBA Noob; 05-24-2007 at 12:51 PM.

  2. #2
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    Hey Dummy99...

    i couldnt really work it out either so i rewrote it...

    does this do what you want??

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-24-2007
    Location
    Canada & France
    MS-Off Ver
    2007
    Posts
    40
    Thanks Stuie,
    Your stuff works but I still don't understand why mine didn't work. I have other similar Do Until / Loop routines in the same program an they work.
    Thanks again!

  4. #4
    Forum Contributor
    Join Date
    01-10-2006
    Location
    Ahmedabad, India
    MS-Off Ver
    Office 2000
    Posts
    346
    Quote Originally Posted by Dummy99
    The Loop starts but wont stop. I don't see anything wrong with the code.
    Code:
    Private Sub CommandButton1_Click()
    Base = InputBox("Enter Base Number")
    If IsNumeric(Base) = False Then
    MsgBox ("Invalid Entry"), vbCritical
    Exit Sub
    End If
    Cntr = 0
    Do While Cntr < Base
    Chkp = Chkp & "p"
    Chkb = Chkb & "b"
    MsgBox (Chkp & "---" & Chkb), vbCritical 'for debug
    Cntr = Cntr + 1
    MsgBox (Cntr & "---" & Base), vbCritical 'for debug
    Loop
    MsgBox ("EOJ"), vbCritical
    End Sub
    Thanks
    InputBox returns a string and not a number. And IsNumeric can only check if a variable can be expressed as a number and not if it is a number. eg if ABC = "12"
    then IsNumeric(ABC) is True even though ABC is a string and not a number. You will have to first convert the string variable to a number variable and then use it. Something like this
    Please Login or Register  to view this content.
    Surprisingly For ... next loop will work even if you do not convert it to number.
    eg if you say for n= 1 to Base it will work. Apparently For...Next internally converts Base to a number and then use it.

    A V Veerkar
    Last edited by avveerkar; 05-24-2007 at 01:02 PM.

  5. #5
    Registered User
    Join Date
    05-24-2007
    Location
    Canada & France
    MS-Off Ver
    2007
    Posts
    40

    Smile

    Avveekar,
    EXCELLENT!
    I knew there was an explanation & I should have thought of the 'numeric' problem myself. It aslo didn't work with an "IF" statement (same reason).
    Many thanks,
    Dummy99

  6. #6
    Forum Contributor
    Join Date
    01-10-2006
    Location
    Ahmedabad, India
    MS-Off Ver
    Office 2000
    Posts
    346
    Quote Originally Posted by Dummy99
    Avveekar,
    EXCELLENT!
    I knew there was an explanation & I should have thought of the 'numeric' problem myself. It aslo didn't work with an "IF" statement (same reason).
    Many thanks,
    Dummy99
    I am glad that I could be of a little help.

    And can we call you by some other name? To address you as Hi dummy sounds odd. Just kidding!!

    A V Veerkar
    Last edited by avveerkar; 05-25-2007 at 01:27 AM.

  7. #7
    Registered User
    Join Date
    05-24-2007
    Location
    Canada & France
    MS-Off Ver
    2007
    Posts
    40

    Re: Loop Not Stopping

    Just happen to be reviewing my posts and saw that my problem was using 'Do While' (which is incorrect).
    I should have used 'Do Until'
    There is no 'Do While'. It is simply 'While' and it doesn't use 'Loop' but 'Wend'

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1