TomGee.us

Tag: .NET

VB: Disable all controls on a form

by Tom Gee on Jan.06, 2010, under Programming, VB.NET

I use this code to cycle through all controls on a form and disable them.  After each control has been disabled, you can then specify individual controls that you wish to be enabled.  This is a handy way to force users to click specific buttons or enter data in specific fields before the rest of the controls on a form become active (enabled).

Private Sub LockControls()
‘ Disable all the controls on the form
Dim
ctrl As Control

For Each ctrl In Me.Controls
ctrl.Enabled = False
Next

Me.txt_Log.Enabled = True ‘ re-enable the log box
Me.progBar.Enabled = True ‘ re-enable the progress bar
Me.lst_ItemGroups.Enabled = True ‘ re-enable the listbox
End Sub

To enable all controls on the form, use the following function:

Private Sub UnlockControls()
‘ Enable all the controls on the form
Dim ctrl As Control

For Each ctrl In Me.Controls
ctrl.Enabled = True
Next
End Sub

‘ Disable all the controls on the form
Leave a Comment :, , , , , , , more...

VB.NET LEFT and RIGHT functions

by Tom Gee on Jan.06, 2010, under Programming, VB.NET

VBA and VB6 developers are used to the familiar LEFT and RIGHT string manipulation functions.  However, VB.NET no longer has these functions built-in. As a result, when I create a new VB.NET application, I create the following two functions which I can then use to replicate the “old” LEFT and RIGHT functionality.

Public Function Left(ByVal Value As String, ByVal Length As Integer) As String
‘ Rereate a LEFT function for string manipulation
If Value.Length >= Length Then
Return Value.Substring(0, Length)
Else
Return
Value
End If
End Function

Public Function Right(ByVal Value As String, ByVal Length As Integer) As String
‘ Recreate a RIGHT function for string manipulation
If Value.Length >= Length Then
Return Value.Substring(Value.Length – Length, Length)
Else
Return
Value
End If
End Function

Leave a Comment :, , , , , , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!