Solved

Some questions from VB newbie

Posted on 1999-01-22
5
199 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:stinger_60284
5 Comments
 
LVL 1

Accepted Solution

by:
batdan earned 20 total points
ID: 1470076
1)  Double click on the textbox, then in the text1_change procedure insert the following code:

Text1_Change()

     If Not IsNumeric(Text1.Text) then
          Text1.Text = ""
     End If

End Sub


2)  Set the BackStyle property of the label to Transparent in the properties window.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 1470077
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.
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1470078
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....
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1470079
OK - look at this question:
http://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!
0
 

Author Comment

by:stinger_60284
ID: 1470080
Thank you guys...
You are all cool experts!!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now