Hej kan man på något sätt stänga av, så man inte kan skriva något annat än siffror i en textbox? Inga problem använd keypress för att kolla vad som skrivs in. Du kan prova:endast siffror
Sv: endast siffror
I ditt form så kör du enligt följande:
<code>
Private Sub txtDatum_KeyPress(KeyAscii As Integer)
KeyAscii = OnlyNumbers(KeyAscii) 'godkänner endast siffror plus delete
End Sub
Private Function OnlyNumbers(ByVal KeyAscii As Integer) As Integer
Const Nummer As String = "0123456789"
If InStr(1, Nummer, Chr(KeyAscii)) > 0 Or KeyAscii = 8 Then 'godkänner endast siffror plus delete
OnlyNumbers = KeyAscii
Else
OnlyNumbers = 0
End If
End Function
</code>
OKSv: endast siffror
<code>
Private Const ES_NUMBER As Long = &H2000&
Private Const GWL_STYLE As Long = -16&
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Sub NumericEdit(Textbox As Textbox)
Dim lReturn As Long
lReturn = GetWindowLong(Textbox.hwnd, GWL_STYLE)
lReturn = lReturn Or ES_NUMBER
SetWindowLong Textbox.hwnd, GWL_STYLE, lReturn
End Sub
Private Sub Form_Load()
NumericEdit Text1
End Sub
</code>