A small calculator in vb

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 27
Reputation: thilinam is an unknown quantity at this point 
Solved Threads: 0
thilinam thilinam is offline Offline
Light Poster

A small calculator in vb

 
0
  #1
Dec 22nd, 2008
hi friends,
I have designed a simple calculator using vb.net I want to execute click event of button which labeled as "1", when I press key "1" on keyboard. please help me.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: A small calculator in vb

 
0
  #2
Dec 22nd, 2008
Normal buttons require ALT-key to be pressed. If you don't mind this, name the buttons
  1. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  2. '
  3. Button1.Text = "&1"
  4. Button2.Text = "&2"
  5.  
  6. End Sub
and trap "number"-buttons
  1. Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click
  2. Select Case CType(sender, Button).Text
  3. Case "&1"
  4. ' Number 1 pressed
  5. Case "&2"
  6. ' Number 2 pressed
  7. End Select
  8.  
  9. End Sub
If you do not want ALT-key to be used, you have to trap KeyUp or similar event and use some other control instead of Button control.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 19
Reputation: hakimkal is an unknown quantity at this point 
Solved Threads: 4
hakimkal hakimkal is offline Offline
Newbie Poster

Re: A small calculator in vb

 
0
  #3
Dec 24th, 2008
I assume you have your click event sub proceedure running, to add another event for a button say "button1" you have to make sure you have enable its 'tabstop' property and then you can add another event sub proceedure.

However for your calculator, when the tabstop gets to the 'btn1' button all the user has to do is to press the "enter key".

This is in simple context, however you may have to implement threading for complex scenario where you need responses. (My opinion)

I am leaving you with some code snippet for your review, it may help.

[CODE syntax=vb]

Private Sub btn1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles btn1.KeyPress

Dim keyasc As Short

If keyasc >= System.Windows.Forms.Keys.D1 And keyasc <= System.Windows.Forms.Keys.D9 Then
txtDisplay.Text = Val(btn1.Text)
Exit Sub
Else
MessageBox.Show("Error key pressed")

End If

End Sub

[/CODE]
Last edited by hakimkal; Dec 24th, 2008 at 2:14 am.
abdoolherkym!
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 16
Reputation: gurshan is an unknown quantity at this point 
Solved Threads: 0
gurshan gurshan is offline Offline
Newbie Poster

Re: A small calculator in vb

 
0
  #4
Dec 24th, 2008
thanks Teme64
thanks for sharing your code with us i think it will defiantly useful for someone.good job..
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC