Link to home
Start Free TrialLog in
Avatar of stinger_60284
stinger_60284

asked on

Some questions from VB newbie

1. How to make the TEXTBOX can only receive number?
   so, it will reject any alphabets.
2. I make the gradation color of my form from blue to
   black. The question is how to make the LABEL be
   transparent? So it will use the color of the form

Thank you for the attention.
Need the answer...

Stinger
ASKER CERTIFIED SOLUTION
Avatar of batdan
batdan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Éric Moreau
Question 1:

You have 2 choices: validate the keypress event of the TextBox or use a MaskEdit Control.

Here is the code for the KeyPress event:
Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
        KeyAscii = 0
    End If
End Sub

Question 2:
Change the Backstyle property of your label to Transparent.
Avatar of caraf_g
caraf_g

Making a text box only accept numbers is not as easy as it might initially seem....

batdan's solution is OK but it fixes things after the fact: first the user types in rubbish, then you tell the user "you can't do that!"

Ideally you want to stop the user from typing in rubbish in the first place.

emoreau's solution is better in that it does this. But it isn't great either because now you can't paste into the text box anymore.

I'll dig up some code for handling this - just bear with me a moment....
OK - look at this question:
https://www.experts-exchange.com/topics/bin/Q.10113932

This is a Previously Answered Question about "how to round euro" which has nothing to do with your question, but it is Free (no points) and it contains some example code.

In the example code there is a form with "numeric only" text boxes on it which has all the code you need.

Good luck!
Avatar of stinger_60284

ASKER

Thank you guys...
You are all cool experts!!!