The document contains a Visual Basic code for a Windows Forms application that checks if a given number is a spy number, where the sum of its digits equals the product of its digits. It includes a button click event that processes the input from a TextBox and displays the result in a Label. If the input is invalid, it prompts the user to enter a valid number.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
30 views1 page
Spy Number
The document contains a Visual Basic code for a Windows Forms application that checks if a given number is a spy number, where the sum of its digits equals the product of its digits. It includes a button click event that processes the input from a TextBox and displays the result in a Label. If the input is invalid, it prompts the user to enter a valid number.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1
Public Class Form1
Private Sub btnCheck_Click(sender As Object, e As EventArgs) Handles
btnCheck.Click Dim number, originalNumber, sumOfDigits, productOfDigits, remainder As Integer
' Get the number from the TextBox
If Integer.TryParse(txtNumber.Text, number) Then ' Initialize variables originalNumber = number sumOfDigits = 0 productOfDigits = 1
' Loop to calculate the sum and product of the digits
While number <> 0 remainder = number Mod 10 sumOfDigits += remainder productOfDigits *= remainder number = number \ 10 End While
' Check if the sum of digits is equal to the product of digits
If sumOfDigits = productOfDigits Then lblResult.Text = originalNumber & " is a spy number." Else lblResult.Text = originalNumber & " is not a spy number." End If Else lblResult.Text = "Please enter a valid number." End If End Sub