Sunteți pe pagina 1din 8

please help me to finish this calc. this calc.

's work, but when i do this < 1 + 1 * 2 > or i should say when using other operations it stops working. here's my code: Public Class Form1 Dim num1, num2 As Integer Dim opr As String Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click lbl1.Text = lbl1.Text & "0" End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click lbl1.Text = lbl1.Text & "1" End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click lbl1.Text = lbl1.Text & "2" End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click lbl1.Text = lbl1.Text & "3" End Sub Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click lbl1.Text = lbl1.Text & "4" End Sub Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click lbl1.Text = lbl1.Text & "5" End Sub Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click lbl1.Text = lbl1.Text & "6" End Sub

Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click lbl1.Text = lbl1.Text & "7" End Sub Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click lbl1.Text = lbl1.Text & "8" End Sub Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click lbl1.Text = lbl1.Text & "9" End Sub Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click lbl1.Text = "" End Sub Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click num1 = Val(lbl1.Text) opr = "+" lbl1.Text = "" End Sub Private Sub btnsubtract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsubtract.Click num1 = Val(lbl1.Text) opr = "-" lbl1.Text = "" End Sub Private Sub btnmultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmultiply.Click num1 = Val(lbl1.Text) opr = "*" lbl1.Text = "" End Sub Private Sub btndivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndivide.Click

num1 = Val(lbl1.Text) opr = "/" lbl1.Text = "" End Sub Private Sub btnequals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnequals.Click num2 = Val(lbl1.Text) Select Case opr Case "+" : lbl1.Text = num1 + num2 Case "-" : lbl1.Text = num1 - num2 Case "*" : lbl1.Text = num1 * num2 Case "/" : lbl1.Text = num1 / num2 End Select End Sub Private Sub lbl1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbl1.Click lbl1.Text = "" End Sub End Class ____________

Calc Program 'Declare the global variables to be used throughout the form Dim mfirst As Single Dim msecond As Single Dim manswer As Single ' Declare the global variables for the operators: Add,Sub,Mul and DIV Dim mbutton As Integer 'Change the sign of the number from + or - or vice versa ' Depending on its state now they show in txtNUMBER text box Dim Signstate As Boolean

Private Sub cmd0_Click() 'Put the value 0 into the txtNUMBER text box txtNUMBER = txtNUMBER + "0" End Sub Private Sub cmd1_Click() 'Put the value 1 into the txtNUMBER text box txtNUMBER = txtNUMBER + "1" End Sub Private Sub cmd2_Click() 'Put the value 2 into the txtNUMBER text box txtNUMBER = txtNUMBER + "2" End Sub Private Sub cmd3_Click() 'Put the value 3 into the txtNUMBER text box txtNUMBER = txtNUMBER + "3" End Sub Private Sub cmd4_Click() 'Put the value 4 into the txtNUMBER text box txtNUMBER = txtNUMBER + "4" End Sub Private Sub cmd5_Click() 'Put the value 5 into the txtNUMBER text box txtNUMBER = txtNUMBER + "5" End Sub

Private Sub cmd6_Click() 'Put the value 6 into the txtNUMBER text box txtNUMBER = txtNUMBER + "6" End Sub Private Sub cmd7_Click() 'Put the value 7 into the txtNUMBER text box txtNUMBER = txtNUMBER + "7" End Sub Private Sub cmd8_Click() 'Put the value 8 into the txtNUMBER text box txtNUMBER = txtNUMBER + "8" End Sub Private Sub cmd9_Click() 'Put the value 9 into the txtNUMBER text box txtNUMBER = txtNUMBER + "9" End Sub Private Sub cmdADD_Click() 'User slected the add button mbutton = 1 'Convert into a number and transfer the value from 'The text box on the form into the first number mfirst = Val(txtNUMBER) txtNUMBER = "" End Sub Private Sub cmdCANCEL_Click() 'Remove the values in the txtNUMBER text box txtNUMBER = " " End Sub Private Sub cmdDIVIDE_Click() 'User slected the Divide button mbutton = 4 'Convert into a number and transfer the value from 'The text box on the form into the first number mfirst = Val(txtNUMBER) txtNUMBER = "" End Sub Private Sub cmdDOT_Click()

txtNUMBER = txtNUMBER + "." End Sub Private Sub cmdEQUALS_Click() msecond = Val(txtNUMBER) Select Case mbutton Case Is = 1 manswer = mfirst + msecond Case Is = 2 manswer = mfirst - msecond Case Is = 3 manswer = mfirst * msecond Case Is = 4 manswer = mfirst / msecond End Select txtNUMBER = manswer End Sub Private Sub cmdEXIT_Click() Unload frmCALCULATOR End Sub Private Sub cmdMULTIPLY_Click() 'User slected the multiply button mbutton = 3 'Convert into a number and transfer the value from 'The text box on the form into the first number mfirst = Val(txtNUMBER) txtNUMBER = "" End Sub Private Sub cmdSIGN_Click() 'Sign state = false on load of form If txtNUMBER = "-" + txtNUMBER Then MsgBox "error start again" End If If Signstate = False Then txtNUMBER = "-" + txtNUMBER Signstate = True Else 'SignState = True minusvalue = Val(txtNUMBER) 'Value now positive

minusvalue = Val("-1" * minusvalue) txtNUMBER = minusvalue Signstate = False End If End Sub Private Sub cmdSUBTRACT_Click() 'User slected the minus button mbutton = 2 'Convert into a number and transfer the value from 'The text box on the form into the first number mfirst = Val(txtNUMBER) txtNUMBER = "" End Sub

List box
Dim Ds As New DataSet Sub Fill_ListBox() Dim Con As New SqlClient.SqlConnection, Cmd As New SqlClient.SqlCommand Dim Da As New SqlClient.SqlDataAdapter, i As Integer, Dr As DataRow Dim tSql As String = "" Try Con.ConnectionString = ConStr tSql = "Select Ip_Address,Emp_Name from TBL_TEST" If Con.State = ConnectionState.Open Then Con.Close() End If Con.Open() Cmd.Connection = Con Cmd.CommandText = tSql Da.SelectCommand = Cmd Da.Fill(Ds, "Table(0)") ListBox1.DataSource = Ds.Tables(0) ListBox1.DisplayMember = Ds.Tables(0).Columns(1).ToString ListBox1.DisplayMember = Ds.Tables(0).Columns(1).ToString ListBox1.Refresh() Catch ex As Exception MsgBox(ex.Message) Finally Cmd = Nothing 'Ds = Nothing Con.Close() End Try End Sub -------------------------------------------------------------------

S-ar putea să vă placă și