Search code examples
functiontextboxvb6

Return nothing in VB6


Quite simply i need to figure out how to rewrite the following code for VB6 so that my application allows nothing to be passed into a textbox.text value

Function GetDbValue(ByVal tb)
 If tb.Text = "" Then
Return Nothing
Else
 Return tb.Text
End If
  End Function

Im getting a syntax error for "return nothing"

EDIT:

Stored proc

 Set prm = cmdDlrID.CreateParameter("@ContractNumberField", adVarChar, adParamInput, 50, GetDbValue(txtContNum))
 cmdDlrID.Parameters.Append prm

Solution

  • In VB6 there are at least four different types of nothing:

    • Nothing, a null pointer as an object
    • vbNullString, a null pointer as a string
    • Empty, an uninitialized variant
    • Null, a null value passed to / from a database

    If you're passing the function into an ADO parameter, you need Null, not Nothing:

    Function GetDbValue(ByVal tb)
        If tb.Text = "" Then
            GetDbValue = Null
        Else
            GetDbValue = tb.Text
        End If
    End Function