Visual Basic - InputBox

Life is soft - evento anual de software empresarial
 
Vista:

InputBox

Publicado por Oscar (29 intervenciones) el 07/07/2005 01:55:58
Hola tengo un problema yo tengo un InputBox y controlo que en los datos que me meta tienen que ser numericos, pero claro si yo pongo 23.,,,,....4,,,.444 y claro aqui esta mi problema quiero saber si alguen sabe comose puedo restringir la entrada de otros caracteres que no sean numeros.
Quisiera saber si se puede que en ese inputbox solo se puedan meter numeros, yo lo controlo asi:
If Not IsNumeric(strCantidad) Then
....
....

pero claro lo que explico antes si yo pongo 23,...,.,3.,.,.,3 pues me deja.
Asik resumiendo, busco la forma de que no se pueda introducir ningun dato en el inputbox, solamente los numeros.

Un saludo


Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 14
Ha aumentado 1 puesto en Visual Basic (en relación al último mes)
Gráfica de Visual Basic

Por fin aqui esta

Publicado por SuNcO (599 intervenciones) el 07/07/2005 02:59:55
Me tarde un buen buscando pero ya esta aqui la solucion

En un boton pones :

Private Sub Command1_Click()
hInst = GetWindowLong(Me.hwnd, GWL_HINSTANCE)
Thread = GetCurrentThreadId()
hHook = SetWindowsHookEx(WH_CBT, AddressOf Manipulate, hInst, Thread)

Resultado = InputBox("Intenta escribir letras", "Solo numeros")
End Sub

Insertas un Modulo y pones :

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

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

' used for placing the hook

Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Public Const GWL_HINSTANCE = (-6)
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOZORDER = &H4
Public Const SWP_NOACTIVATE = &H10
Public Const HCBT_ACTIVATE = 5
Public Const WH_CBT = 5

Public hHook As Long

' used for locating and changing the buttons
Public Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hwndParent As Long, ByVal hwndChildAfter As Long, ByVal lpszClass As String, ByVal lpszWindow As String) As Long
Public Declare Function SetWindowText Lib "user32.dll" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Public Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

Public ButtonText(0 To 3) As String

Public Sub SetNumber(hwnd As Long, Flag As Boolean)
Dim curstyle As Long, newstyle As Long

'retrieve the window style
curstyle = GetWindowLong(hwnd, GWL_STYLE)

If Flag Then
curstyle = curstyle Or ES_NUMBER
Else
curstyle = curstyle And (Not ES_NUMBER)
End If

'Set the new style
newstyle = SetWindowLong(hwnd, GWL_STYLE, curstyle)
'refresh
'NumberText.Refresh
End Sub

' function called by hook
Public Function Manipulate(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Dim Btn(0 To 3) As Long
Dim ButtonCount As Integer
Dim T As Integer

If lMsg = HCBT_ACTIVATE Then

Btn(0) = FindWindowEx(wParam, 0, vbNullString, vbNullString)

Dim cName As String, Length As Long
For T = 1 To 3
Btn(T) = FindWindowEx(wParam, Btn(T - 1), vbNullString, vbNullString)
' no more windows found
If Btn(T) = 0 Then Exit For
Next T

For T = 0 To 3
If Btn(T) <> 0 And Btn(T) <> wParam Then
cName = Space(255)
Length = GetClassName(Btn(T), cName, 255)
cName = Left(cName, Length)
'Debug.Print cName
If UCase(cName) = "EDIT" Then
SetNumber Btn(T), True
End If
'If UCase(cName) = "BUTTON" Then
' a button
' SetWindowText Btn(T), ButtonText(ButtonCount)
' ButtonCount = ButtonCount + 1
'End If
End If
Next T
'Release the CBT hook
UnhookWindowsHookEx hHook
End If
Manip = False

End Function
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:InputBox

Publicado por oscar (29 intervenciones) el 07/07/2005 09:26:33
muchas gracias SuNcO sale a las mil maravillas, eres un crack.

Un saludo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar