troubleshooting Question

Restritcing an Input's box input to Numbers only

Avatar of gxs
gxsFlag for United States of America asked on
.NET ProgrammingVisual Basic.NETMicrosoft Development
6 Comments1 Solution590 ViewsLast Modified:
Hello everyone,

I'm trying to restrict input box entries to numbers only.

I know the method IsNumeric but it doesn't work with me because I assigned the input's box value to a variable. So the whole thing is getting a little complicated.

Take a look at my code and you'll understand what I mean:

-------------------------------------------------------------------------------------
'Salary Calculator
Option Strict On

Public Class SalaryCal

    Private Sub BtnCal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCal.Click

        Dim Salary As Integer = 0
        Dim Name As String = InputBox("Please Enter Your name")
        Dim Hours As Integer = CInt(InputBox("Please Enter Hours Worked"))
        Dim Payrate As Integer = CInt(InputBox("Please Enter your hourly payrate"))

        Dim NetSalary As Integer = 0

        If Hours <= 40 Then
            Salary = Hours * Payrate
        ElseIf Hours > 40 Then
            Salary = CInt((40 * Payrate) + (Payrate * (Hours - 40) * 1.5))
        End If

        If Salary > 2000 Then
            NetSalary = CInt((Salary / 100) * 85)
            TxtResult.Text &= Name & ", " & "Your NetSalary is " & FormatCurrency(NetSalary) & " and your Salary is " & (Salary) & ". " & " You have been taxed %15" & vbNewLine

        ElseIf Salary <= 2000 Then
            NetSalary = CInt((Salary / 100) * 90)
            TxtResult.Text &= Name & ", " & "Your NetSalary is " & FormatCurrency(NetSalary) & " and your Salary is " & (Salary) & ". " & " You have been taxed %10" & vbNewLine
        End If

    End Sub
End Class
-------------------------------------------------------------------------------------

The bolded codes need to be modified a bit so Hour, Payrate variables accept Numeric input from the input box only and the Name variable accept Characters only.

Waiting for you help plus appreciated and thanks in advance,

Mike.
ASKER CERTIFIED SOLUTION
smilitaru

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros