user5468794 user5468794 - 1 year ago 100 Question

VB check value of structure

I have two structures that sometimes one gets filled with data from a user or sometimes both. I need to check either the whole structure to see if it has had data input or not. I'd also be ok if I can even check just a variable to see if it is not empty or null (which is what I have done below). When the code runs the btnTurn.Enabled is always disabled whether the structure has data or not. Could this be a problem with my boolean?


Public Structure StructSurvData
Friend szTBMNum As String
Friend dblTBMElev1 As Double
Friend dblTBMElev2 As Double
Friend dblTBMElev3 As Double
Friend dblBACKSIGHT1 As Double
Friend dblBACKSIGHT2 As Double
Friend dblBACKSIGHT3 As Double
Friend dblFORESIGHT1 As Double
Friend dblFORESIGHT2 As Double
Friend dblFORESIGHT3 As Double
Friend szNewMPEDescr As String
Friend szDataComm As String

End Structure

Public Structure StructSurvData2
Friend szTBMNum2 As String
Friend dblTBMElev4 As Double
Friend dblTBMElev5 As Double
Friend dblTBMElev6 As Double
Friend dblBACKSIGHT4 As Double
Friend dblBACKSIGHT5 As Double
Friend dblBACKSIGHT6 As Double
Friend dblFORESIGHT4 As Double
Friend dblFORESIGHT5 As Double
Friend dblFORESIGHT6 As Double
Friend szNewMPEDescr2 As String
Friend szDataComm2 As String
End Structure


If structSD2.szTBMNum2 = Nothing Then
btnTurn.Enabled = False
ElseIf structSD2.szTBMNum2 <> Nothing Then
btnTurn.Enabled = True
End If

Answer Source

You should always use is nothing instead of =nothing and isnot nothing instead of <> nothing

        If structSD2.szTBMNum2 is Nothing Then
            btnTurn.Enabled = False
        ElseIf structSD2.szTBMNum2 isnot Nothing Then
            btnTurn.Enabled = True
        End If

Or even better as @zaggler recommended:

        btnTurn.Enabled = structSD2.szTBMNum2 Is Nothing
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download