|
-
Jun 24th, 2000, 11:34 AM
#1
Thread Starter
Addicted Member
I know that it related some how to keypress event ,
but I tryed and couldn't worked it out.
The MORE I get to know,
I realize that I know NOTHING !
-
Jun 24th, 2000, 11:36 AM
#2
Frenzied Member
click on the text box, then goto the properties window, and click on Data Format, and chose numbers
NXSupport - Your one-stop source for computer help
-
Jun 24th, 2000, 11:49 AM
#3
Thread Starter
Addicted Member
well , it doesn't work !!
again I need that the user want be able to insert numbers
to the textbox.
The MORE I get to know,
I realize that I know NOTHING !
-
Jun 24th, 2000, 11:57 AM
#4
Frenzied Member
ok, this isn't the best but here it is (no gaurantee):
[code]
'put this into the declerations:
dim inttxt as interger
' end declerations
'put this into the text change function:
if text1.text = "0", or "1", or "2", or "3", or "4", or "5", or "6", or "7", or "8", or "9" then
text1.visible = true ' just a command to waste time
inttxt = text1.text
else:
text1.text = ""
'this might not work
NXSupport - Your one-stop source for computer help
-
Jun 24th, 2000, 12:19 PM
#5
Hyperactive Member
There are a lot of ways to do this, but you should find that this is pretty bullet proof. What you do is just check the Asc entered into the box on keypress. In this example, Text1.text will only accept 1-9, a backspace (character 8) and a space (character 32).
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
CheckChar = KeyAscii
If CheckChar = 8 Then
Exit Sub
ElseIf CheckChar = 32 Then
Exit Sub
ElseIf CheckChar < 48 Or CheckChar > 57 Then
MsgBox "You can only enter a numeric in this box", vbApplicationModal, "Numeric violation"
KeyAscii = 0
Text1.Text = Text1.Text & Chr(KeyAscii)
End If
End Sub
Hope that this helps
(Using VB 6 SP 3)
-
Jun 24th, 2000, 12:25 PM
#6
Hyperactive Member
Well, you can use the Isnumeric funtion too.
This should be secure.
Code:
Private Sub Text1_Change()
If IsNumeric(Text1.Text) Then
'Code when it is
'(Nothing)
Else
'Code when it's not
MsgBox "Only numbers! Try again!"
Text1.Text = ""
Text1.SetFocus
End If
End Sub
Signed, Rodik ([email protected])
Programmer,usesVB6ED
===========================
Copyright©RodikCo,2002.
Dont mind this signature ;] Its old
-
Jun 24th, 2000, 12:31 PM
#7
Hyperactive Member
Also, just pointing out.
The method which reeset refers too wouldn't allow the user to paste a number from the clipboard.
Signed, Rodik ([email protected])
Programmer,usesVB6ED
===========================
Copyright©RodikCo,2002.
Dont mind this signature ;] Its old
-
Jun 24th, 2000, 12:56 PM
#8
Hyperactive Member
Good point. But you could easily fix that by just adding exeptions to new values.
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
CheckChar = KeyAscii
If CheckChar = 8 Then
Exit Sub
ElseIf CheckChar = 32 Then
Exit Sub
ElseIf CheckChar = 22 Then
'If user tries to paste
svalue = Clipboard.GetText
For x = 1 To Len(svalue)
sNextChar = Asc(Mid(svalue, x, 1))
If sNextChar < 48 Or sNextChar > 57 Then
MsgBox "You can only enter a numeric in this box", vbApplicationModal, "Numeric violation"
Clipboard.Clear
Exit Sub
End If
Next
ElseIf CheckChar = 3 Then
'if user try's to copy
Exit Sub
ElseIf CheckChar < 48 Or CheckChar > 57 Then
MsgBox "You can only enter a numeric in this box", vbApplicationModal, "Numeric violation"
KeyAscii = 0
Text1.Text = Text1.Text & Chr(KeyAscii)
End If
End Sub
Thanks for pointing that out.
-
Jun 24th, 2000, 09:53 PM
#9
transcendental analytic
This code will work with negative values and commas
Code:
Private Sub Text1_Change(): Dim temp&
temp = Text1.SelStart
If IsNumeric(Text1) Then Text1.Tag = Text1 Else Text1 = Text1.Tag
Text1.SelStart = temp
End Sub
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jun 24th, 2000, 11:18 PM
#10
PowerPoster
API function
I know this can be done just with a simple API function, but I can remeber the Function name, if anyone found it just email.
Thanks
-
Jun 24th, 2000, 11:51 PM
#11
Lively Member
VbSquare posted a tip about doing this same thing. Here's the code:
Code:
'Declarations
Public Declare Function GetWindowLong& Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long)
Public Declare Function SetWindowLong& Lib "user32" Alias _
"SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long)
Public Const ES_NUMBER = &H2000&
Public Const GWL_STYLE = (-16)
'Textbox Change
Private Sub Text1_Change()
Dim tmpValue&
Dim fAlignment&
Dim ret&
fAlignment& = ES_NUMBER
tmpValue& = GetWindowLong&(txtRefreshRate.hwnd, GWL_STYLE)
ret& = SetWindowLong&(txtRefreshRate.hwnd, GWL_STYLE, tmpValue& Or fAlignment&)
txtRefreshRate.Refresh
End Sub
Well, there ya go! Works no problem.
-
Jun 25th, 2000, 05:04 AM
#12
Addicted Member
Wow, such overkill!
try this:
Code:
text1.text = val(text1.text)
hehe. Easy.
-
Jun 25th, 2000, 07:02 AM
#13
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|