Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Simple Newbie VB questions

Posted on 2006-11-03
9
Medium Priority
?
230 Views
Last Modified: 2010-04-16
Let me know if I need to brak these up into multiple question...

I am a newbie trying to finish off a project.

Question #1
I am looking for a way to draw lines on a mschart  in VB. When I type a value into a textbox I need a horizontal line to be drawn on the Y axis. If I type in a 2 I need (0,2) to be graphed, and so on.

Question #2
How do I ensure that the data that can be inserted in a textbox are numerical values only.

0
Comment
Question by:zyanj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 3

Expert Comment

by:taycuong76
ID: 17872473
1)

2) Assuming that you have a textbox named Text1:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> asc("-") Then KeyAscii = 0
End Sub
0
 
LVL 1

Expert Comment

by:sagaragrawal
ID: 17897264
For the 2nd question :-

If your textbox name is Text1, then you can use below code.

Private Sub Text1_Validate(Cancel As Boolean)
       
    If Not IsNumeric(Text1.Text) Then
        MsgBox "Enter a numeric value please.", vbExclamation, "Alert"
        Cancel = True
    End If
   
End Sub

This will validate the contents in Text1 textbox. It will not allow the user to move off the textbox, untill the user enters a numeric value. Everytime the user enters a non-numeric value, it will show an alert through the message box.

I hope this will do the needful.

Enjoy !!!
0
 

Author Comment

by:zyanj
ID: 17915942
taycuong76 ....

How do i apply this to a textbox that is apart of an array.

Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> asc("-") Then KeyAscii = 0
End Sub

Private Sub Text1_Change(Index As Integer)

CODE>>>CODE

End Sub
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Expert Comment

by:ManasiD
ID: 17920578
for your textbox that is a part of an array:

suppose if there are 3 textbox and if you want to put the condition only for one text box (which is of index 1) then:

Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
    If Index = 1 Then
        If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> Asc("-") Then
           KeyAscii = 0
        End If
    End If
End Sub

suppose if the condition is to be put for all textbox in the control array then there is no need for the index condition.

Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
        If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> Asc("-") Then
           KeyAscii = 0
        End If
End Sub
0
 
LVL 3

Expert Comment

by:taycuong76
ID: 17935258
* You declare a n array of textbox and just add an If...then.... with Index in the Sub:

If Index = ..... Then
        If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> Asc("-") Then
           KeyAscii = 0
        End If
End If

* To apply the "numeric textbox" to all of your textbox in a form, you need to use a class module and do something with "With Event" to reference to the class module.
0
 

Author Comment

by:zyanj
ID: 18029879
neither work
0
 
LVL 3

Accepted Solution

by:
taycuong76 earned 1500 total points
ID: 18052004
Ok, let me show you in details:

1) Open a new project VB
2) Insert 1 textbox (automatically named as Text1)
3) Select it on the form, press Control + C to copy it to clipboard, then press Control + V to paste it to form. A message box will appear, choose Yes. This will create an array of Text1(2), you can add more by the same way but 2 is enough for this example.
4) Now, paste the following code to the code's form:
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
 If Index = 1 Then
        If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> Asc("-") Then
           KeyAscii = 0
        End If
    End If
End Sub

This must work, and in the Textbox(1) you only input numbers, Textbox (2) you can input what you can (normal mode).
Tell me if it behave strangely.
0
 

Author Comment

by:zyanj
ID: 18294302
Sorry for the delay. Good answer. Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Six Sigma Control Plans

650 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