search this site the web

Wednesday, March 17, 2010

VB Code for Adding Values in Combo at Runtime

Dim r As Double
r = 9.9
Combo4.Clear
Do Until r >= 50
r = r + 0.1
Combo4.AddItem FormatNumber(r, 2, True, True, True)
Loop
Combo4.ListIndex = 0

Tuesday, March 16, 2010

Upper Case Letters in Text Box in vb.net

Private Sub ValidateNameTextBox(ByRef TB As TextBox)

If Not TB.Text = String.Empty Then
TB.Text = TB.Text.Substring(0, 1).ToUpper() & TB.Text.Substring(1, TB.Text.Length - 1).ToUpper()
TB.SelectionStart = TB.Text.Length
End If
End Sub


Private Sub Textbox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Textbox1.TextChanged
ValidateNameTextBox(Me.Textbox1)
End Sub

Drop Down the Combo Box List

'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'Insert 1 ComboBox to your form (named Combo1).
'Insert this code to the module :

Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam _
As Long, ByVal lParam As Long) As Long
Public Const CB_SHOWDROPDOWN = &H14F

'Insert the following code to your form:

Private Sub Form_Load()
r = SendMessageLong(Combo1.hwnd, CB_SHOWDROPDOWN, True, 0)
End Sub

Allow only Numbers in Textbox

'Add 1 TextBox To Your Form.
'Insert the following code to your form:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < 47 Or KeyAscii > 57 Then KeyAscii = 0
End Sub

VB6 code for Clearing all Textbox in a Form

'Add 1 CommandButton and few TextBoxes To Your Form.
'Insert the following code to your form:

Private Sub Command1_Click()
Dim Contrl As Control
For Each Contrl In Form1.Controls
If (TypeOf Contrl Is TextBox) Then Contrl.Text = ""
Next Contrl
End Sub

VB code to Set The Text Box Cursor Position

Add 1 Text Box to your form.

Form Code

Private Sub Form_Load()
' the following line will place the cursor after the
' 4th character
Text1.SelStart = 4
End Sub