Hi,
I have written a code to accept value entered into textboxes. Then calculate when a button 'calculate' is clicked.
How do I prompt the user if they haven't entered a value in a textbox before clicking calculate? Below is the code.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim pipediameterStr As String = pipediameter.Text()
        Dim totalpipelengthStr As String = totalpipelength.Text()
        Dim pipedesignlifeStr As String = pipedesignlife.Text()
        Dim anodecrsectperStr As String = TextBox14.Text()
        Dim utlfactorStr As String = TextBox10.Text()
        Dim echemcapacityStr As String = TextBox11.Text()
        Dim dccpotentialStr As String = TextBox12.Text()
        Dim dppotentialStr As String = TextBox13.Text()
        Dim coatingresStr As String = TextBox3.Text()
        Dim initctbrkdfactorStr As String = Initialctbrkdfactor.Text()
        Dim avgyrlyctbrkdfactorStr As String = avgyrlyctbrkdfactor.Text()
        Dim searesistivityStr As String = TextBox5.Text()
        Dim meancurrdensityStr As String = TextBox7.Text()
        Dim finalcurrdensityStr As String = TextBox8.Text()
        Dim indvntanodemassStr As String = TextBox2.Text()
        Dim exposedanodediameterStr As String = TextBox1.Text()
        Dim anodelengthStr As String = TextBox9.Text()
        Dim numfieldjointStr As String = TextBox15.Text()
        Dim fieldjointspacingStr As String = TextBox16.Text()
        Dim engtimeinhrsStr As String = TextBox49.Text()
        Dim costofengtimeStr As String = TextBox48.Text()
        Dim addedcostengStr As String = TextBox47.Text()
        Dim costofmaterialStr As String = TextBox46.Text()
        Dim overheadmaterialexStr As String = TextBox45.Text()
        Dim costofrightofwayStr As String = TextBox44.Text()
        Dim costofcompconstructStr As String = TextBox43.Text()
        Dim inspectiontimeStr As String = TextBox42.Text()
        Dim costofinspectionStr As String = TextBox41.Text()
        Dim ascostofinspectionStr As String = TextBox40.Text()
        Dim costofcompsyscheckStr As String = TextBox39.Text()
        Dim iccpindvnetanodemassStr As String = TextBox21.Text()
        Dim totalcablelengthStr As String = TextBox18.Text()
        Dim cableresistanceStr As String = TextBox6.Text()
        Dim iccpanodelengthStr As String = TextBox20.Text()
        Dim iccpelectrochemcapStr As String = TextBox22.Text()
        Dim iccputlfactorStr As String = TextBox25.Text()
        Dim iccpdccpotentialStr As String = TextBox26.Text()
        Dim iccpexposedanodediameterStr As String = TextBox27.Text()
        Dim iccpanodecrsectperStr As String = TextBox28.Text()
        Dim iccprectdcratingStr As String = TextBox29.Text()
        Dim iccprectacratingStr As String = TextBox30.Text()
        Dim anodetypeStr As String = ComboBox3.Text()
        Dim iccpanodetypeStr As String = ComboBox1.Text()
        Dim iccpengtimeinhrsStr As String = TextBox17.Text()
        Dim iccpcostofengtimeStr As String = TextBox19.Text()
        Dim iccpaddedcostengStr As String = TextBox24.Text()
        Dim iccpcostofmaterialStr As String = TextBox31.Text()
        Dim iccpoverheadmaterialexStr As String = TextBox32.Text()
        Dim iccpcostofrightofwayStr As String = TextBox37.Text()
        Dim iccpcostofcompconstructStr As String = TextBox36.Text()
        Dim iccpinspectiontimeStr As String = TextBox35.Text()
        Dim iccpcostofinspectionStr As String = TextBox34.Text()
        Dim iccpascostofinspectionStr As String = TextBox33.Text()
        Dim iccpcostofcompsyscheckStr As String = TextBox38.Text()

You need to loop through all the text boxes on the form and check if it empty.

If anyone is empty prompt the user to fill that.

Its an event driven application so there must be an event before there is a response. You could only use your conditional loops to check before proceeding to the calculation

or use this


Dim h AS String
Dim b AS Integer
Dim c AS String

IF TextBox1.text = "" Then
MsgBox("Please enter ........")
ElseIf Textbox2.text = "" Then
MsgBox("Enter ..........")
End If

If IsNumeric(TextBox3.Text) Then
h = Val(TextBox3.Text)
Else
MsgBox (" Please enter numeric Value")
End If

That is not practical if using almost 50 or more text boxes in scenarios like this.

Simply try this

Private Sub ValidateControls()
        Dim cControl As Control
        For Each cControl InMe.Controls
            If (TypeOf cControl Is TextBox) Then
                'check for what ever you want to check
            End If
        Next cControl
    End Sub
Comments
Agree, but only if you add a space after in
This article has been dead for over six months. Start a new discussion instead.