title: My program keeps looping an inputbox. How do I get out of it?
body: <p>I'm making a program that allows users to see information on songs, play an excerpt of them, and purchase selected ones.</p>
  
  <p>And allow users to click the Purchase button to buy the indicated tune.</p>
  
  <p>When checking out:</p>
  
  <p>Users cannot checkout if they have not purchased any tunes, however they can exit the program.</p>
  
  <p>Use an InputBox so that users can enter their sales tax rate. Since users are entering a value, you must perform data validation on their input.</p>
  
  <p>Allow users to cancel the check out process by clicking the InputBox Cancel button.</p>
  
  <p>When the input box is displayed, the textbox should have the focus, and when an incorrect tax value is added, the incorrect value should be cleared and the textbox should have focus again.</p>
  
  <p>Use Write/Writeline to create a purchase order text file named PurchaseOrder.txt that includes the date the file was created and an itemized list of purchases, the subtotal, tax, and total.</p>
  
  <p>When I click on the "Purchase" button of the selected song and click on the "Check Out" button, I get an inputbox, type the numeric value, however, it continues to loop over and over again. I don't get why this is happening. Please refer to the cmdCheckOut_Click subroutine in the code below. I think that's where I'm getting my error.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>   Public Structure musicInfo
      &lt;VBFixedString(30)&gt; Public title As String
      &lt;VBFixedString(20)&gt; Public artist As String
      &lt;VBFixedString(20)&gt; Public genre As String
      &lt;VBFixedString(10)&gt; Public duration As String
      Public year As Integer
      Public price As Double
      &lt;VBFixedString(15)&gt; Public songFileName As String
     End Structure
  
  Public Const NoOfTunes = 5
  Public songs(NoOfTunes - 1) As musicInfo
  
  
  Option Explicit On
  Imports System.IO
  Public Class frmTunes
    Public index As Integer
    Public purchaseCount As Integer
    Public purchasePrice(10) As Decimal
    Public purchaseTitle(10) As String
    Dim decimal1 As Decimal
    Dim decimal3 As Decimal
    Dim decimal4 As Decimal
  Private Sub frmTunes_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  
      Dim i As Integer
  
      FileOpen(1, "music.dat", OpenMode.Random, , , Len(songs(0)))
      For i = 0 To NoOfTunes - 1
          FileGet(1, songs(i))
      Next
      FileClose(1)
  
      cmdPrevious.Visible = False
  
      DisplaySong(0)
  End Sub
  
  Sub DisplaySong(ByVal i As Int32)
      lblTitle.Text = songs(i).title
      lblArtist.Text = songs(i).artist
      lblGenre.Text = songs(i).genre
      lblDuration.Text = songs(i).duration
      lblYear.Text = Convert.ToString(songs(i).year)
      lblPrice.Text = Convert.ToString(songs(i).price)
  End Sub
  
  Private Sub cmdStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStop.Click
      My.Computer.Audio.Stop()
  End Sub
  
  Private Sub cmdPurchase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPurchase.Click
      purchaseTitle(purchaseCount) = lblTitle.Text
      purchasePrice(purchaseCount) = Convert.ToDecimal(lblPrice.Text)
      purchaseCount = (purchaseCount + 1)
  End Sub
  
  Private Sub cmdPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrevious.Click
      index = (index - 1)
      If (index &lt; 4) Then
          cmdNext.Visible = True
      End If
      If (index = 0) Then
          cmdPrevious.Visible = False
      End If
      DisplaySong(index)
  End Sub
  
  Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click
      index = (index + 1)
      If (index = NoOfTunes - 1) Then
          cmdNext.Visible = False
      End If
      If (index &gt; 0) Then
          cmdPrevious.Visible = True
      End If
      DisplaySong(index)
  End Sub
  
  Private Sub cmdPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPlay.Click
      My.Computer.Audio.Play(songs(index).songFileName)
  End Sub
  
  Private Sub cmdCheckOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCheckOut.Click
      Dim str1 As String = ""
      If (purchaseCount = 0) Then
          MsgBox("You have not ordered any items!", MsgBoxStyle.Exclamation, "Order Error")
      Else
          Do Until ((IsNumeric(str1) And (Decimal.Compare(decimal3, Decimal.Zero) &lt;= 10)) And (Decimal.Compare(decimal3, (10D)) &gt;= 0))
              str1 = InputBox("Enter your tax rate as a %" &amp; vbCrLf &amp; "between and including 0 - 10:", "Tax Rate", "", -1, -1)
              If (str1 &lt;&gt; "") Then
                  If (Not IsNumeric(str1)) Then
                      MsgBox("You must enter a numeric tax rate", MsgBoxStyle.Exclamation, "Tax Rate Error")
                  Else
                      Dim decimal3 As Decimal = Convert.ToDecimal(str1)
                      If ((Decimal.Compare(decimal3, Decimal.Zero) &lt; 0) Or (Decimal.Compare(decimal3, (10D)) &gt; 0)) Then
                          MsgBox("You must enter a tax rate between and including 0% - 10%", MsgBoxStyle.Exclamation, "Tax Rate Error")
                      End If
                  End If
              End If
          Loop
          Dim StreamWriter As StreamWriter = File.CreateText("PurchaseOrder.txt")
          StreamWriter.WriteLine("For Purchases dated: " &amp; DateTime.Now.ToLongDateString())
          StreamWriter.WriteLine()
          Dim num2 As Integer = (purchaseCount - 1)
          Dim num1 As Integer = 0
          Do While (num1 &lt;= num2)
              StreamWriter.Write(Strings.FormatCurrency(CType(Me.purchasePrice(num1), Decimal) &amp; "     "))
              StreamWriter.WriteLine(purchaseTitle(num1))
              Dim decimal1 As Decimal = Decimal.Add(Nothing, purchasePrice(num1))
              num1 = (num1 + 1)
  
          Loop
          StreamWriter.WriteLine("------")
          StreamWriter.WriteLine(Strings.FormatCurrency(CType(decimal1, Decimal)) &amp; "  Subtotal")
          Dim decimal2 As Decimal = New Decimal(((Convert.ToDouble(decimal3) * 0.01) * Convert.ToDouble(decimal1)))
          StreamWriter.WriteLine(Strings.FormatCurrency(CType(decimal2, Decimal)) &amp; "  Tax")
          StreamWriter.WriteLine("------")
          Dim decimal4 As Decimal = Decimal.Add(decimal1, decimal2)
          StreamWriter.WriteLine(Strings.FormatCurrency(CType(decimal4, Decimal)) &amp; "  Total")
          MsgBox("Purchase Order has been created", MsgBoxStyle.OkOnly)
          StreamWriter.Close()
          Me.Close()
      End If
  End Sub
  End Class
  </code></pre>