+ Reply to Thread
Results 1 to 6 of 6

Do...Loop While structure, write the code that repeatedly prompts

  1. #1
    Registered User
    Join Date
    10-15-2013
    Location
    united states
    MS-Off Ver
    Excel 2010
    Posts
    64

    Do...Loop While structure, write the code that repeatedly prompts

    the question is Using a Do...Loop While structure, write the code that repeatedly prompts the user using an InputBox for a number, and continues to prompt the user until a valid positive number is entered.
    Unfortunately it doesn't work properly, where did I go wrong?



    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim stringMagic As Double
    Do
    stringMagic = InputBox("Enter The Number", "Guess")
    If stringMagic <> 51 Or Nothing Then
    stringMagic = Val(stringMagic)
    MsgBox("Try Again!")
    End If
    Loop While stringMagic = InputBox("Enter The Number", "Guess")
    stringMagic = 51
    MsgBox("Happy Birthday!")

    End Sub
    End Class

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,576

    Re: Do...Loop While structure, write the code that repeatedly prompts

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

  3. #3
    Registered User
    Join Date
    10-15-2013
    Location
    united states
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: Do...Loop While structure, write the code that repeatedly prompts

    What the heck is wrong with you, you said you want to see my codes in order to help me.

  4. #4
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,576

    Re: Do...Loop While structure, write the code that repeatedly prompts

    Please use code tags around your code to fulfill the rules.
    I wrote about this in other post.

    And please don't open duplicated threads because it's impossible to follow one question in several threads.

    Clearer now?

  5. #5
    Registered User
    Join Date
    10-15-2013
    Location
    united states
    MS-Off Ver
    Excel 2010
    Posts
    64

    Re: Do...Loop While structure, write the code that repeatedly prompts

    This is the code I came up is but something is not right. Now would you advice please?


    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Do...Loop While structure, write the code that repeatedly prompts

    Drop the entitled attitude. You are no more special than the next person and in the scheme of personal reality no one cares about you or your problems.

    With that being said, the part you will want to focus on is what trigger the loop to end. Specifically this part in your scenario:

    Please Login or Register  to view this content.
    Instead you will need to keep within the parameters of the problem and end the loop when the entry is a positive number. Look at using IsNumeric() and >0
    If you are happy with my response please click the * in the lower left of my post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Using a Do...Loop While structure, write the code that repeatedly prompts
    By 1Melina in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-07-2016, 04:00 PM
  2. How to run VBA code repeatedly?
    By Sid108 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-14-2015, 12:49 PM
  3. How to write vb code for selecting pivot items in a loop??
    By luckyali in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-16-2014, 06:00 AM
  4. [SOLVED] How to write a code within a loop to copy and paste rows on to another Sheet
    By swade730 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-24-2014, 08:40 PM
  5. [SOLVED] doing a loop repeatedly only for an specific value
    By omid020 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-28-2013, 06:34 AM
  6. Best way to code a repeatedly used array?
    By ajm218 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-28-2008, 03:38 PM
  7. [SOLVED] How do I write an Excel Macro to run Solver repeatedly?
    By DLowie in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-27-2005, 01:05 PM

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