Error not filling in program fields

Asked

Viewed 55 times

0

I created a program in Visualstudio that uses 4 Textbox, and when I do not put anything in the 4 Textbox and then click on the button that adds what is inside the 4 Textbox the error program, how can I replace this error with a message like "Fill in the fields before continuing" ?

  • 1

    You put C. The answer was in VB.Net. Who’s wrong?

1 answer

0

You can test all of them before doing the operation:

if txt1.text="" or txt2.text = "" or txt3.text = "" or txt4.text = "" Then
    MsgBox("Preencha todos os campos!")
End If

Or you can assign 0 to empty textboxes:

if txt1.text= "" Then
    txt1.text = "0"
End If
' ....

Or direct in comparison, convert to integer:

Dim resultado as integer = CInt(txt1.text) + CInt(txt2.text) '....
  • Can you explain to me how these codes work ? Just understood that: if the Textbox1 is equal to "" or Textbox2 is equal to "" will appear the message of fill all fields. just didn’t understand what the ""function is. (I’m a beginner)

  • Now I see your doubt is in C, ams the logic is the same. If texbox1 = blank OR textbox2 = blank...etc, does not do the calculation and displays the message for the user to fill in all, so it does not generate error. The second alternative is the same thing, but instead of displaying message, you will fill in with "0" if the text of that textbox is blank and then do the sum. The third uses the . net "Cint", where it tries to convert what is in the field to the integer, so nothing = 0. The language c must have something similar if you want this resolution.

  • Yes, the "" means that that textbox is empty. If it types something the program would understand as textbox1.text = "120". Since it is a textbox, the idea is that what is there is a text and text is always placed in quotation marks.

  • Thank you very much :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.