Rabu, 20 Maret 2024

Check Is Nothing In Visual Basic Classic

Is Nothing command consist of Is operator and Nothing keyword. Is Nothing command function for check whether an object is used or not.

SDI (Single Document Interface)

For this following objects:

Screen.ActiveForm

you can use this following snippet code:

Private Sub mnuFileClose_Click()
  If Not ( Screen.ActiveForm.Name = "Form1" ) Then Unload Screen.ActiveForm
End Sub

Multiple Document Interface

For this following objects:

<MDI-Form-Name>.ActiveForm

Me.ActiveForm ' in MDI parent Form

you can use this following snippet code:

'In the other form

Private Sub mnuFileClose_Click()

    If Not (MDIForm1.ActiveForm Is Nothing) Then Unload ActiveForm

End Sub

or you can use this following snippet code:

'In the MDI form

Private Sub mnuFileClose_Click()

    If Not (Me.ActiveForm Is Nothing) Then Unload ActiveForm

End Sub

ADO ( ActiveX Data Object ) Set To Nothing

For this following objects:

Dim m_adoCon As ADODB.Connection
Dim m_adoRs As ADODB.Recordset
Dim m_adoCmd As ADODB.Command

you can use this following snippet code:

'To unload m_adoCon object when m_adoCon object has created
Private Sub Form_Load()
  If Not ( m_adoCon Is Nothing ) Then Set m_adoCon = Nothing
End Sub

ADO ( ActiveX Data Object ) Create Object

For this following object:

Dim m_adoCon As ADODB.Connection
Dim m_adoRs As ADODB.Recordset
Dim m_adoCmd As ADODB.Command

you can use this following snippet code:

'To Create m_adoCon object
Private Sub Form_Load()
  If m_adoCon Is Nothing Then Set m_adoCon = New ADODB.Connection
End Sub

Bibliography:

https://www.fortypoundhead.com/

http://www.shershahcollege.co.in/ ( university )

Related Post:

ADODB Properties 1
Datagrid Visual Basic Classic 1
Visual Basic Variable Keywords 1
Error Handling In Visual Basic 
Most Common Chr Code In Visual Basic 
Default Value Of Data Types In Visual Basic 6
Visual Basic Intrinsic Controls
 Visual Basic 6 Data Type Function

    Tidak ada komentar:

    Posting Komentar