something is not right with these code the Is True Then , pls help me to correct it....
If isEmpty(Mfgno) Is True Then
lbl1.Caption = "Error"
Else
lbl1.Caption = "NoError"
End If
Debug.Print (Mfgno)
something is not right with these code the Is True Then , pls help me to correct it....
If isEmpty(Mfgno) Is True Then
lbl1.Caption = "Error"
Else
lbl1.Caption = "NoError"
End If
Debug.Print (Mfgno)
Brief correction and a practical fix.
is correct that the literal "Is True" is not VB6 syntax. Also note IsEmpty has a specific meaning: it returns True only for an uninitialized Variant, not for a declared String that contains nothing or only spaces. 's trimming idea points the right way — normalize the value, then test.
A small, reusable helper avoids repeating checks and handles Null/Empty/space-only strings:
Public Function IsBlankValue(ByVal v As Variant) As Boolean
If IsNull(v) Or IsEmpty(v) Then
IsBlankValue = True
Exit Function
End If
If VarType(v) = vbString Then
IsBlankValue = (Len(Trim$(v)) = 0)
Else
IsBlankValue = False
End If
End Function Use a single loop to validate many fields instead of duplicating If lines:
Sub ValidateRecord()
Dim names As Variant
Dim vals As Variant
Dim i As Long
names = Array("Mfgno", "CardTran", "TranType", "TranDate", "DrCrFlag")
vals = Array(Mfgno, CardTran, TranType, TranDate, DrCrFlag)
For i = LBound(names) To UBound(names)
If IsBlankValue(vals(i)) Then
lbl1.Caption = "Error line=" & line & " missing " & names(i)
Exit For
End If
Next i
End Sub Few quick tips: if values come from fixed-width input (or from a DB), they may be space-padded; Trim$ immediately after reading normalizes them. To see trailing/leading spaces in the Immediate window, print markers: Debug.Print ">" & Mfgno & "<" or Debug.Print Len(Mfgno). Use Option Explicit to catch misspellings. This approach keeps checks clear, robust, and maintainable for 's scenario.
Jump to Post— QVeen72 104Hi,
What type of Variable is "Mfgno"...?
If String Check for "" If Numeric check for Zero:If Trim(MfgNo) ="" Then lbl1.Caption = "Error Else lbl1.Caption = "NoError End IfRegards
Veena
Hi,
What type of Variable is "Mfgno"...?
If String Check for "" If Numeric check for Zero:
If Trim(MfgNo) ="" Then
lbl1.Caption = "Error
Else
lbl1.Caption = "NoError
End If Regards
Veena
Is True is not available in VB 6.0 .
Are you using .NET ?
thnx both of you....
im using string and VB 6.0 , currently im using this method which is not so good
If Mfgno = " " Then lbl1.Caption = "Error line=" & line
If CardTran = " " Then lbl1.Caption = "Error line=" & line
If TranType = " " Then lbl1.Caption = "Error line=" & line
If TranDate = " " Then lbl1.Caption = "Error line=" & line
If DrCrFlag = " " Then lbl1.Caption = "Error line=" & line
i've to count the no of each substring to do this..... anyway thanx... i'm gonna try wat's veena suggest....
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.