question

Hekzdaddy-3952 avatar image
0 Votes"
Hekzdaddy-3952 asked ·

Validating inputs

Hello, I am stuck. I am supposed79326-screenshot-165.png to validate the input data type into txtBox before allowitn the program to continue but I keep getting too many errors.


dotnet-visual-basic
screenshot-165.png (265.2 KiB)
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @Hekzdaddy-3952 ,
If you need further assistance, you can share your project on onedrive or GitHub, or write an answer to post your code.

0 Votes 0 ·

1 Answer

karenpayneoregon avatar image
1 Vote"
karenpayneoregon answered ·

Red needs to move to to where the other private variables are, blue needs to move outside of btnCalcluate and can only assume yellow belongs with blue. In the future post code and the image, this way if you had done that I could had made the changes.

79615-f1.png



f1.png (50.2 KiB)
· 9 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

79630-screenshot-166.png




Public Class Form1


 Private Function ValidateInputFields() As Boolean
 Public Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click

     'try to convert each of the input fields. Return false if 
     'any of the fields in invalid, and display a suitable error message. 

     If Not Decimal.TryParse(txtBoxLabor.Text, dectxtBoxLabor) Then
         lblLabor.Text = "retail must be numeric"
         Return False

     End If

     If Not Decimal.TryParse(txtBoxParts.Text, dectxtBoxParts) Then
         lblParts.Text = "type in a number"
         Return False

     End If
     Return True
         End fucntions

         End Sub
0 Votes 0 ·
screenshot-166.png (266.3 KiB)

Still having an issue, I've attached a new image and partial code (full code exceeded 1000 character limit).

0 Votes 0 ·

This was done in notepad, see if this resolve the issue.

 Private Function ValidateInputFields() As Boolean
    
      If Not Decimal.TryParse(txtBoxLabor.Text, dectxtBoxLabor) Then
          lblLabor.Text = "retail must be numeric"
          Return False
      End If
      If Not Decimal.TryParse(txtBoxParts.Text, dectxtBoxParts) Then
          lblParts.Text = "type in a number"
          Return False
      End If
         
      Return True
    
 End Function
    
    
 Public Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
     If ValidateInputFields() Then
         ' 
     Else if
         '
     End If
 End Sub

I would also encourage you to learn how to work with Git in Visual Studio. Knowing Git means you can use a link rather than post code here.
https://docs.microsoft.com/en-us/visualstudio/ide/git-with-visual-studio?view=vs-2019

0 Votes 0 ·
Show more comments

I'll take it off and see what happens

0 Votes 0 ·