# IsEmpty in VB6



## cj_white (Oct 28, 2001)

hey guys i am learning VB6 and messing aroung with some of the functions. i am trying to use the isempty() function but i am getting 'Wrong # of argument or invalid property assignment. this is what i have so far

Private Sub cmdResult_Click()
Dim strFname As String * 50
Dim strLname As String * 50

strFname = Me.txtFname.Text
strLname = Me.txtLname.Text

If IsEmpty(strFname, strLname) = True Then MsgBox "you have not filled out all fields"
ElseIf IsEmpty(strFname, strLname) = False Then MsgBox "Hello " & strFname & " " & strLname & "!" & " How are you today?"

End Sub

Private Sub Form_Load()

End Sub

i'm not sure if there is a problem with the way i have the IsEmpty() set up or maybe i am using the if, then , else statement incorrectly. basicly i have 2 text boxes where you put your first and last name and it is supposed to check to see if they are filled out. thanks in advance


----------



## RedAxl (Nov 17, 2004)

Hi,



> IsEmpty returns TRUE if the variable is uninitialized, or is
> EXPLICITLY SET TO EMPTY; otherwise, it returns FALSE.
> FALSE is ALWAYS returned if expression contains MORE THAN ONE variable.
> IsEmpty ONLY returns meaningful information for VARIANTS.


It is simpler, direct, and safer to test empty variable strings against blank ("") strings.

Change the following lines:


> If IsEmpty(strFname, strLname) = True Then MsgBox "you have not filled out all fields"
> ElseIf IsEmpty(strFname, strLname) = False Then MsgBox "Hello " & strFname & " " & strLname & "!" & " How are you today?"


Into: 


> If strFname = "" OR strLname = "" Then
> MsgBox "you have not filled out all fields"
> Else
> MsgBox "Hello " & strFname & " " & strLname & "!" & " How are you today?"
> End If


Also, consider TRIMming your string variables. 

Red


----------



## cj_white (Oct 28, 2001)

thanks for replying. i made the changes you have suggested. I am now getting 'else without if' compile errors. i have the 'end if' at the end of the code. any other suggestions

Private Sub cmdResult_Click()
Dim strFname As String
Dim strLname As String

strFname = Me.txtFname.Text
strLname = Me.txtLname.Text

If strFname = "" Or strLname = "" Then MsgBox "you have not filled out all fields"
Else: MsgBox "Hello " & strFname & " " & strLname & "!" & " How are you today?"
End If
End Sub


----------



## RedAxl (Nov 17, 2004)

Just place the 


> MsgBox "you have not filled out all fields"


on the next line. It will make your code more readable too.

Also, you can ommit the optional COLON ":" after the ELSE.



> If strFname = "" Or strLname = "" Then
> MsgBox "you have not filled out all fields"
> Else
> MsgBox "Hello " & strFname & " " & strLname & "!" & " How are you today?"
> End If


Red


----------



## cj_white (Oct 28, 2001)

that worked. thanks for all your help. is that just the syntax for the if, then, else statement? some things i noticed you can't do that with because as soon as you hit enter to move it to the next line you get a compiler error. i am trying to learn this after i have already learned PHP and i have found it's hard to keep them straight in my head. once again thanks for the help


----------



## RedAxl (Nov 17, 2004)

It is the setting of Auto Syntax Check option that causes the immediate error/warning.

To set/unset the Auto Syntax Check option 

From the Tools menu, select Options, and click the Editor tab on the Options dialog box.


Select Auto Syntax Check (Check/Uncheck). 

:up:

Red


----------

