by Sreeram.P (16 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Fri 9th June 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)
simple code for making a control disabled or enabled
API Declarations
'chk(0) after place combo1
'chk(1) after place List1
'chk(2) after place command1
'chk(3) after place text1
'chk(4) after place Frame1
'declerations
Public Const conTHIRTEEN As Byte = 13
Public Const conSEVEN As Byte = 7
Public Const conEIGHT As Byte = 8
Public Const conTWELVE As Byte = 12
Public Const conTEN As Byte = 10
Public Const coNFIVE As Byte = 5
Public Const conNINE As Byte = 9
Public Const conCommandButton As String * conTHIRTEEN = "CommandButton"
Public Const conListBox As String * conSEVEN = "ListBox"
Public Const conTextBox As String * conSEVEN = "TextBox"
Public Const conComboBox As String * conEIGHT = "ComboBox"
Public Const conCheckBox As String * conEIGHT = "CheckBox"
Public Const conOptionButton As String * conTWELVE = "OptionButton"
Public Const conMsFlexGrid As String * conTEN = "MSFlexGrid"
Public Const conFrame As String * coNFIVE = "Frame"
Public Const conMaskEdBox As String * conNINE = "MaskEdBox"
Public Const conStatusBar As String * conNINE = "StatusBar"
Public Const conVASpread As String = "VASPREAD"
Public Const conNumericControl As String = "ctlNumber"
Public Const conDateControl As String = "ctlDate"
Public Function CtrlEnable(ByVal CtlEnable As Boolean, ByRef Ctl As Object) As Boolean
'***************************************************************************************
'# Function Name : gsEnable
'# Purpose : Enables/Disables the passed control
'# Scope : Public
'# Parameters : True/False
'# The Control to be Enabled
'# Returns : None
'# SL NO Date Author Reason
'# -------------------------------------------------------------------------------------
'# 1. 05Sep2006 Sreeram.P Project Requirement
'****************************************************************************************
Dim lsErrorString As String
On Error GoTo ErrorHandler
If CtlEnable Then '# Changing color to vbWindowBackground
Select Case TypeName(Ctl)
Case conTextBox, conListBox, conComboBox, conNumericControl
Ctl.Locked = Not CtlEnable
Ctl.BackColor = vbWindowBackground
Case conCommandButton, conDateControl, conFrame
Ctl.Enabled = CtlEnable
Case conVASpread
Ctl.Enabled = CtlEnable
Ctl.Row = -1
Ctl.Col = -1
Ctl.BackColor = vbWindowBackground
Case conMaskEdBox
Ctl.Enabled = CtlEnable
Ctl.BackColor = vbWindowBackground
Ctl.ForeColor = vbButtonText
Case Else
Ctl.Enabled = CtlEnable
End Select
Else '# Changing color to vbInactiveBorder
Select Case TypeName(Ctl)
Case conTextBox, conListBox, conComboBox, conNumericControl
Ctl.Locked = Not CtlEnable
Ctl.BackColor = vbInactiveBorder
Case conCommandButton, conDateControl, conFrame
Ctl.Enabled = CtlEnable
Case conVASpread
Ctl.Enabled = CtlEnable
Ctl.Row = -1
Ctl.Col = -1
Ctl.BackColor = vbInactiveBorder
Case conMaskEdBox
Ctl.Enabled = CtlEnable
Ctl.BackColor = vbInactiveBorder
Ctl.ForeColor = vbButtonText
Case Else
Ctl.Enabled = CtlEnable
End Select
End If
CtrlEnable = True
CleanUp:
Exit Function
ErrorHandler:
'frfErrorHandler lsErrorString
GoTo CleanUp
End Function
'add a form and paste this code
Private Sub chk_Click(Index As Integer)
If Index = 0 Then
If chk(Index).Value = 1 Then
'combo enable code
Module1.CtrlEnable True, Combo1
Else
'code for combo disable
Module1.CtrlEnable False, Combo1
End If
ElseIf Index = 1 Then
If chk(Index).Value = 1 Then
'list enable code
Module1.CtrlEnable True, List1
Else
'code for combo disable
Module1.CtrlEnable False, List1
End If
ElseIf Index = 2 Then
If chk(Index).Value = 1 Then
'command enable code
Module1.CtrlEnable True, Command1
Else
'code for combo disable
Module1.CtrlEnable False, Command1
End If
ElseIf Index = 3 Then
If chk(Index).Value = 1 Then
'text enable code
Module1.CtrlEnable True, Text1
Else
'code for combo disable
Module1.CtrlEnable False, Text1
End If
ElseIf Index = 4 Then
If chk(Index).Value = 1 Then
'frame enable code
Module1.CtrlEnable True, Frame1
Else
'code for combo disable
Module1.CtrlEnable False, Frame1
End If
End If
End Sub
Private Sub Form_Load()
'code for combo disable
Module1.CtrlEnable False, Combo1
'code for combo disable
Module1.CtrlEnable False, List1
'code for combo disable
Module1.CtrlEnable False, Command1
'code for combo disable
Module1.CtrlEnable False, Text1
'code for combo disable
Module1.CtrlEnable False, Frame1
End Sub