CODE = Option Explicit On Option Strict On Option Infer Off Public Class MainFor
ID: 3762261 • Letter: C
Question
CODE =
Option Explicit On
Option Strict On
Option Infer Off
Public Class MainForm
'-------------------------------------------------------------------------------------------------------------------------------------------------
' Sub procedure to define exitButton click event.
Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
Me.Close()
End Sub
'-------------------------------------------------------------------------------------------------------------------------------------------------
' Sub procedure to select existing text of the firstFourTextBox.
Private Sub firstFourTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles firstFourTextBox.Enter
firstFourTextBox.SelectAll()
End Sub
'-------------------------------------------------------------------------------------------------------------------------------------------------
' Sub procedure to allows only numbers and the Backspace key for the firstFourTextBox.
Private Sub firstFourTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles firstFourTextBox.KeyPress
If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
'-------------------------------------------------------------------------------------------------------------------------------------------------
' Sub procedure clear the content of the firstFourTextBox.
Private Sub firstFourTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles firstFourTextBox.TextChanged
creditNumberLabel.Text = String.Empty
End Sub
'-------------------------------------------------------------------------------------------------------------------------------------------------
' Sub procedure to define creditNumberButton click event (Determines the fifth digit in a credit card number).
Private Sub creditNumberButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles creditNumberButton.Click
' 1. Declare two String variables called creditNum, fifthDigit and an integer variable called sumOfDigits within the following space.
' 2. Write code to get the value at firstFourTextBox to the variable creditNum within the following space.
' 3. Fill the two blanks in following statement to check whether the creditNum is a four digit string.
If creditNum _ _ _ _ _ _ _ _ Then
' 4. Write code to get the summation of four digits in variable creditNum to the variable sumOfDigit within the following space.
' Steps:
' Take each string digit using Substring function.
' Use Convert.ToInt32 function to convert each string digit to an integer. Syntax of Convert.ToInt32 is as follows.
' int a = Convert.ToInt32(string)
' Get the summation according to the given scenario (First digit + 3*Second digit + Third digit + 3*Fourth digit)
' 5. Write code to find the fifth digit and store in the variable fifthDigit within the following space.
' 6. Write code to append fifth digit to first four digits in the variable creditNum within the following space.
Else ' processed when the user does not enter four digits
MessageBox.Show("Please enter a four-digit number.", "Georgetown Credit", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
firstFourTextBox.Focus()
End Sub
End Class
Explanation / Answer
declare two variables an an integer:
Imports System.Runtime.CompilerServices
Dim creditNum As Int
Dim creditNumtext As Int
Dim fifthDigit As Int
Dim fifthDigittext As Int
Dim sumOfDigits As Int
Dim i As Int
creditNumtext=TextBox1.TextLength
creditNum=creditNumtext.GetNumericValue(creditNumtext)
fifthDigittext=TextBox2.TextLength
fifthDigit=fifthDigittext.GetNumericValue(fifthDigittext)
if creditNum <>4
MsgBox("credit number must be equal to 4")
end if
public Sub creditcard(creditNum as Integer,fifthDigit as Integer,sumOfDigits as Integer)
console.Writeline(sumOfDigits)
End sub
Sub Main()
int creditNum:=creditNum
int fifthDigit:=fifthDigit
for i from 0 to creditNum-1{
int creditNum:=integer(creditNum[i])
int fifthDigit:=integer(fifthDigit[i])
sumOfDigits:=fifthDigit+creditNum
}
end sub
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.