Jump to content

VB Calc.

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
Erobobo

Erobobo

    Newbie

  • Members
  • Pip
  • 1 posts
Hey,

for school, i need to make a calculator in Visual Basic, so i look around on the internet, and tried something myself and created a calculator... (see attachment)(i hope it works :P) now, if u see the image, u see 4 textboxes, the first one, is to put in the first number, the second one is for the operator the 3rd one is for the second number, and the last, big, one is for the answer.

now here's my question: you can put in the numbers with the numbpad, but i also like to put them in, with the numbers on my calculator, but i don't know, what script i need for that... can anyone help me?

I hope you know what i mean, and i hope my English is good enough :P

GrtZ
:cool:Erobobo:cool:

Attached Files



#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,086 posts
Double click on 1 button, code window opens with a new sub.
In the sub should be something like:
    Dim btn As Button = CType(sender, Button)
    activeTextfield.text += btn.text
Where activeTextfield is a (private) class parameter
To find the active textfield i would do something like:

Quote

Private Sub btn_focus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtField1.GotFocus,txtField2.GotFocus,txtField3.GotFocus

activeTxtfield = ctype(sender,Button)

end sub


#3
Ray Tawil

Ray Tawil

    Programmer

  • Members
  • PipPipPipPip
  • 108 posts
Hello Erobobo,

here is a small sample i made for you, remember you need to set the form property, Keypreview = true

here is the code, i did it for 3 buttons:

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

        Select Case e.KeyCode

            Case Keys.NumPad1

                Button1_Click(Me, e)

            Case Keys.NumPad2

                Button2_Click(Me, e)

            Case Keys.NumPad3

                Button3_Click(Me, e)

        End Select

    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        TextBox1.Text = TextBox1.Text + "1"

    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        TextBox1.Text = TextBox1.Text + "2"

    End Sub


    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        TextBox1.Text = TextBox1.Text + "3"

    End Sub

i will attach the sample maybe you can benefit from it. :cool:

Attached Files


Share your Knowledge, It's one way to achieve immortality.
Video Tutorial Channel