Question: In this exercise, you modify the Check Digit application from this chapter's Apply lesson. Use Windows to make a copy of the Check Digit Solution

In this exercise, you modify the Check Digit application from this chapter's Apply lesson. Use Windows to make a copy of the Check Digit Solution folder. Rename the copy Check Digit Solution-ForNext. Open the Check Digit Solution.sln file contained in the Check Digit Solution-ForNext folder. Delete the [EOCEXECNL]intGrandTotal = intTotalOdd + intTotalEven[/EOCEXECNL] statement from the btnAssign_Click procedure. Also delete the two Dim statements that declare the [EOCEXECNL]intTotalOdd[/EOCEXECNL] and [EOCEXECNL]intTotalEven[/EOCEXECNL] variables. Modify the procedure to use one For...Next loop (rather than two For...Next loops) to calculate the grand total. Save the solution and then start and test the application. (If the user enters 978128586026, the btnAssign_Click procedure should display 9781285860268.)
Here is my current code that needs to be modified:
Option Explicit On
Option Strict On
Option Infer Off
Public Class frmMain
Private Sub btnAssign_Click(sender As Object, e As EventArgs) Handles btnAssign.Click
' Assign a check digit to an ISBN.
Dim strIsbn As String
Dim intDigit As Integer
Dim intTotalOdd As Integer
Dim intTotalEven As Integer
Dim intGrandTotal As Integer
Dim intRemainder As Integer
Dim intCheckDigit As Integer
If txtIsbn.Text.Length =12 Then
strIsbn = txtIsbn.Text
For intOdd As Integer =1 To 11 Step 2
Integer.TryParse(strIsbn(intOdd), intDigit)
intTotalOdd +=(intDigit *3)
Next intOdd
For intEven As Integer =0 To 10 Step 2
Integer.TryParse(strIsbn(intEven), intDigit)
intTotalEven += intDigit
intGrandTotal = intTotalOdd + intTotalEven
intRemainder = intGrandTotal Mod 10
Next
If intRemainder <>0 Then
intCheckDigit =10- intRemainder
End If
lblFinalIsbn.Text = strIsbn & intCheckDigit.ToString
Else
MessageBox.Show("Please enter 12 numbers.", "Check Digit",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub txtIsbn_Enter(sender As Object, e As EventArgs) Handles txtIsbn.Enter
txtIsbn.SelectAll()
End Sub
Private Sub txtIsbn_TextChanged(sender As Object, e As EventArgs) Handles txtIsbn.TextChanged
lblFinalIsbn.Text = String.Empty
End Sub
Private Sub txtIsbn_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtIsbn.KeyPress
' Allow only numbers and the Backspace key.
If (e.KeyChar <"0" OrElse e.KeyChar >"9") AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
End Class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!