17-03-15, 04:40 PM
كود :
Imports System.Text.RegularExpressions
Public Class Form1
Dim res As String = String.Empty
Private Sub b0_Click(sender As Object, e As EventArgs) Handles b0.Click, b1.Click, b2.Click, b3.Click, b4.Click, b5.Click, b6.Click, b7.Click, b8.Click, b9.Click
If lblscreen.Text.Trim = "0" Then
lblscreen.Text = sender.text
Else
lblscreen.Text &= sender.text
End If
End Sub
Private Sub plus_Click(sender As Object, e As EventArgs) Handles plus.Click, minus.Click, mul.Click, div.Click
If lblscreen.Text.IndexOf("+") > 0 Or lblscreen.Text.IndexOf("-") > 0 Or lblscreen.Text.IndexOf("*") > 0 Or lblscreen.Text.IndexOf("/") > 0 Then Exit Sub
If lblscreen.Text.Trim = "0" Then
Else
lblscreen.Text &= sender.text
End If
End Sub
Private Sub eq_Click(sender As Object, e As EventArgs) Handles eq.Click
Dim str As String = "([0-9.]{1,})([/*\-+]{1,1})([0-9.]{1,})"
Dim reg As New Regex(str)
Dim ma As Match = reg.Match(lblscreen.Text.Trim)
If ma.Success Then
Select Case ma.Groups(2).Value
Case "+"
res = ma.Groups(1).Value + Val(ma.Groups(3).Value)
Case "-"
res = ma.Groups(1).Value - Val(ma.Groups(3).Value)
Case "*"
res = ma.Groups(1).Value * Val(ma.Groups(3).Value)
Case "/"
res = ma.Groups(1).Value / Val(ma.Groups(3).Value)
End Select
Dim the As String = " = " & res
If lblscreen.Text.IndexOf(the) > 0 Then Exit Sub
lblscreen.Text = ma.Groups(1).Value & " " & ma.Groups(2).Value & " " & ma.Groups(3).Value & " " & the
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
lblscreen.Text = "0"
res = String.Empty
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Function isfound() As Boolean
If lblscreen.Text.Contains("/") Or
lblscreen.Text.Contains("*") Or
lblscreen.Text.Contains("-") Or
lblscreen.Text.Contains("+") Then
Return True
Else
Return False
End If
End Function
Private Sub point_Click(sender As Object, e As EventArgs) Handles point.Click
If lblscreen.Text.Trim = "0" Then
Exit Sub
Else
Dim lapo As Integer = lblscreen.Text.LastIndexOf(".")
If isfound() = False Then
If lapo > 0 Then Exit Sub
Else
If lapo > 1 Then Exit Sub
End If
lblscreen.Text &= sender.text
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
about.ShowDialog()
End Sub
End Class