Question

Algorithm 1. Starting with the second digit, multiply every other digit by 2. (These will be the 2. If a product from Step 1 is greater than 9, sum the two digits in the product. For 3. Add together the results from Steps 1 and 2 and each of the digits skipped in Step 1 4. Divide the sum from Step 3 by 10 and find the remainder. If the remainder is 0, then second, fourth, sixth, and eighth digits.) example, if the product is 12, add the 1 to the 2, giving 3. (The skipped digits will be the first, third, fifth, seventh, and ninth digits.) the number is valid Number: 631620176 Step 1: 631 6 12 1+4 5 Step 2: Step 3: 6 61 Step 4: 12 3 6 30 30 Mod 10

Open the Validate Number Solution.sln file contained in the VB2017\Chap07\Validate Number Solution folder. The interface provides a text box for entering a 9-digit number. The btnValidate_Click procedure should use the algorithm and example shown in Figure 7-56 to validate the user’s entry. The procedure should display a message indicating whether the entry is or is not valid. Code the procedure. Include any other code that will professionalize the interface. Save the solution and then start and test the application. Create an independent function to validate the number, pass the number as a string to the function, and have the function return a boolean (true if valid, false if invalid). Before invoking the function to validate the number, insure that the input text box contains the correct number of characters and that all the characters are numbers, and if not, display a message box informing the user to enter the correct number of characters. If the number is valid, display "Valid!" in the output label. If the number is not valid, display in red text "Not Valid!". Keep the TextAlign property of the output label MiddleCenter.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ScreenShot

-------------------------------------------------------------------------

Program

'Form name=frmValidate , Textbox name=txtNumber , button name=btnValidate and result label name=lblValidNumber
Public Class frmValidate
    'Validate button click
    Private Sub btnValidate_Click(sender As Object, e As EventArgs) Handles btnValidate.Click
        'Check the entred string's length and is digit or not,if condition false generate error message otherwise goto next step
        If Len(Trim(txtNumber.Text)) <> 9 Or IsNumeric(txtNumber.Text) = False Then
            MsgBox("Please enter a Number with 9 characters.")
            txtNumber.Clear()
            txtNumber.Focus()
            Exit Sub
        End If
        'call isValid function to check the entered data correct or not
        If isValid(txtNumber.Text) Then
            lblValidNumber.Text = "Valid!"
            lblValidNumber.ForeColor = Color.Black
        Else
            lblValidNumber.Text = "Not Valid!"
            lblValidNumber.ForeColor = Color.Red
        End If
    End Sub
    'Function to check the entered data validity
    Private Function isValid(strNumber As String) As Boolean
        'Variables for looping , tempstrring generation and total sum calculation
        Dim I As Integer
        Dim intTemp As Integer
        Dim strTemp As String
        Dim intTot As Integer
        'loop to get each character of the string
        For I = 1 To Len(strNumber)
            'take even index numbers
            If I Mod 2 = 0 Then
                'convert into integer for multiplication
                intTemp = Integer.Parse(Mid(strNumber, I, 1)) * 2
                'if result of multiplication>9 then add digits and store
                If intTemp > 9 Then
                    strTemp = intTemp.ToString
                    intTemp = Integer.Parse(Mid(strNumber, 1, 1)) + Integer.Parse(Mid(strNumber, 2, 1))
                End If
                'if odd index characters convert as integer without multiplication
            Else
                intTemp = Integer.Parse(Mid(strNumber, I, 1))
            End If
            'Calculate sum of all digits
            intTot += intTemp
        Next I
        'Last step,find mod of sum with 10 division,if result=0 then valid otherwise not valid
        If intTot Mod 10 = 0 Then
            isValid = True
        Else
            isValid = False
        End If
    End Function
End Class

Add a comment
Know the answer?
Add Answer to:
Open the Validate Number Solution.sln file contained in the VB2017\Chap07\Validate Number Solution folder. The interface provides...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Open the Gross Pay Solution.sln file contained in the VB2017\Chap08\Gross Pay Solution folder. The interface provides...

    Open the Gross Pay Solution.sln file contained in the VB2017\Chap08\Gross Pay Solution folder. The interface provides a text box for entering the number of hours an employee worked. It also provides a list box for selecting the employee’s pay code. The btnCalc_Click procedure should display the gross pay, using the number of hours worked and the pay rate corresponding to the selected code. The pay codes and rates are listed in Figure 8-47. Employees working more than 40 hours receive...

  • REQUIREMENTS: Write a Graphical User Interface (GUI) program using JavaFX that prompts the user to enter...

    REQUIREMENTS: Write a Graphical User Interface (GUI) program using JavaFX that prompts the user to enter a credit card number. Display whether the number is valid and the type of credit cards (i.e., Visa, MasterCard, American Express, Discover, and etc). The requirements for this assignment are listed below: • Create a class (CreditNumberValidator) that contains these methods: // Return true if the card number is valid. Boolean isValid(String cardNumber); // Get result from Step 2. int sumOfDoubleEvenPlace(String cardNumber); // Return...

  • Please write code in Python! You are asked to implement the following checksum formula to validate...

    Please write code in Python! You are asked to implement the following checksum formula to validate an identifi- cation number given to you. The formula works as follows. Using the original number, double the value of every other digit. Then add the values of the individual digits together (if a doubled value now has two digits, add the digits individually). The identification number is valid if the resulting sum is divisible by 10. Write a function called validateID that takes...

  • Credit card numbers follow certain patterns. A credit card number must have between 13 and 16...

    Credit card numbers follow certain patterns. A credit card number must have between 13 and 16 digits. The number must start with the following: 4 for Visa cards 5 for MasterCard cards 37 for American Express cards 6 for Discover cards In 1954, Hans Luhn of IBM proposed an algorithm for validating credit card numbers. The algorithm is useful to determine whether a card number is entered correctly or is scanned correctly by a scanner. Almost all credit card numbers...

  • I want it in C++ 4. When choice 4 (Verify Your Credit Card) is selected, the...

    I want it in C++ 4. When choice 4 (Verify Your Credit Card) is selected, the program should read your credit card (for example: 5278576018410787) and verify whether it is valid or not. In addition, the program must display the type (i.e. name of the company that produced the card). Each credit card must start with a specific digit (starting digit: 1st digit from left to ight), which also is used to detemine the card type according Table 1. Table...

  • Write a function called "phoneNumberFormat" that takes a string containing a ten-digit phone number (such as...

    Write a function called "phoneNumberFormat" that takes a string containing a ten-digit phone number (such as 5155551212) as input, convert into a more readable string with parentheses and dashes like (515)555-1212 and display it. If the input string contains more than or less than ten characters, display an error message. Note: Steps of phoneNumberFormat function can be given as follows: def phoneNumberFormat (phoneNum): 1. Let l be the length of the phoneNum 2. If 1 does not equal 10 then,...

  • You are hired by a college to write a Java program to use a so-called check...

    You are hired by a college to write a Java program to use a so-called check sum technique for catching typing errors of student ID. The college assigns a seven-digit number to each student. The seventh digit (i.e., the rightmost digit) is determined from the other digits with the use of the following formula: 7th digit = (1 *(1st digit) * 2 * (2nd digit) * ... * 6 * (6th digit)) % 10 Your program should prompt users to...

  • Program Set 2 10 points) Credit card number validation Program Credit card numbers follow certain patterns:...

    Program Set 2 10 points) Credit card number validation Program Credit card numbers follow certain patterns: It must have between 13 and 16 digits, and the number must start with: 4 for Visa cards 5 for MasterCard credit cards 37 for American Express cards 6 for Discover cards In 1954, Hans Luhn of IBM proposed an algorithm for validating credit card numbers. The algorithm is useful to determine whether a card number is entered correctly or whether a credit card...

  • Modify current code to complete the following: Current code: Validate a Web IP address which will...

    Modify current code to complete the following: Current code: Validate a Web IP address which will accept the following positive examples: 1.1.1.1 192.0.0.255 255.255.255.255 The IP address comprises four parts each of which is one to three digits, with each part separated by a DOT or period. To match a single digit, or two digits, or three digits, you will need to use the curly braces to specify the minimum and maximum number of digits desired. digits, you will need...

  • Using c++ A ten diglt ISBN number uses a checksum as its last diglt to verlfy...

    Using c++ A ten diglt ISBN number uses a checksum as its last diglt to verlfy the first nine digits are valid. Before 2007, all ISBN numbers were composed like this, such as: e-20-5e8005-7 or 1-234-56789-X The first nine digits are assigned by a book's publisher and the last digit is calculated by "weighted sum (described below). The X stands for the checksum value of 10, in order to represent ten as a single digit. You must write a program...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT