Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert value in Textbox

Status
Not open for further replies.

singoi

Technical User
Mar 1, 2005
46
DE
Hallo, I am little bit used to VB but having lots of queries.

i have a textbox where in i should type only integers.this textbox should be restricted only to integers.

but the first letter in the textbox should be "Ø" which should be enabled=false.

like example : Ø1516

so this symbol will be standard and when the textbox set to focus it should get focused only after the symbol so that we enter the integer.

how can i make this.

thanks in advance friends.

singoi
 
Place a label in front of your text box with "Ø"

To allow only numbers in text box:
Code:
Private Sub txtMyTextBox_KeyPress(KeyAscii As Integer)

If (KeyAscii > 47 And KeyAscii < 58) Or KeyAscii = 8 Then
    'Only numbers are entered - it is OK
Else
    KeyAscii = 0
End If

End Sub

HTH

---- Andy
 
Try this...

Sub Text1_GotFocus()
If Text1 = "" Then Text1 = "Ø"
Text1.SelStart = 1
Text1.SelLength = Len(Text1)
End Sub

Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If Text1 = "" Then
Text1 = "Ø"
Text1.SelStart = 1
Text1.SelLength = Len(Text1)
End If

End Sub

Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 47 To 58, 8
Case Else: KeyAscii = 0
End Select
End Sub
 
In the module:

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Const GWL_STYLE = (-16)
Private Const ES_NUMBER = &H2000

Public Sub SetDigitsOnly(ByRef ioobjTextBox As TextBox)

Dim dwStyle As Long

With ioobjTextBox
dwStyle = GetWindowLong(.hwnd, GWL_STYLE)
dwStyle = dwStyle Or ES_NUMBER
SetWindowLong .hwnd, GWL_STYLE, dwStyle
End With

End Sub

In the Form:

Private Sub Form_Load()
Text1.Text = "Ô"
SetDigitsOnly Text1
End Sub

Private Sub Text1_Change()
If Left$(Text1.Text, 1) <> "Ô" Then
Text1.Text = "Ô" & Text1.Text
End If
End Sub

vladk
 
Thanks,

these solutions were very helpfull..i could make my program.

Thanks again my friends.

singoi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top