Nedenstående er ikke nogen speciel god lomme regner. Koden er heller ikke specielt smart. Men koden er så simpel som den kan være !
Imports System Imports System.Drawing Imports System.Windows.Forms
Namespace DefaultNamespace Public Class MainForm Inherits Form
Private acc As Double Private op As String Private tb As TextBox Private btnOne As Button Private btnTwo As Button Private btnThree As Button Private btnFour As Button Private btnFive As Button Private btnSix As Button Private btnSeven As Button Private btnEigth As Button Private btnNine As Button Private btnZero As Button Private btnPlus As Button Private btnMinus As Button Private btnMultiply As Button Private btnDivide As Button Private btnEqual As Button
Public Shared Sub Main Dim fMainForm As New MainForm fMainForm.ShowDialog() End Sub
Public Sub New() MyBase.New Me.InitializeComponent End Sub
Private Sub InitializeComponent() acc = 0 op = "" tb = New TextBox btnOne = New Button btnTwo = New Button btnThree = New Button btnFour = New Button btnFive = New Button btnSix = New Button btnSeven = New Button btnEigth = New Button btnNine = New Button btnZero = New Button btnPlus = New Button btnMinus = New Button btnMultiply = New Button btnDivide = New Button btnEqual = New Button
SuspendLayout
tb.Location = New Point(50, 50) tb.Size = New Size(350, 50) tb.Text = ""
btnOne.Location = New Point(50, 150) btnOne.Size = New Size(50, 50) btnOne.Text = "1" AddHandler btnOne.Click, AddressOf ButtonClick
btnTwo.Location = New Point(150, 150) btnTwo.Size = New Size(50, 50) btnTwo.Text = "2" AddHandler btnTwo.Click, AddressOf ButtonClick
btnThree.Location = New Point(250, 150) btnThree.Size = New Size(50, 50) btnThree.Text = "3" AddHandler btnThree.Click, AddressOf ButtonClick
btnFour.Location = New Point(50, 250) btnFour.Size = New Size(50, 50) btnFour.Text = "4" AddHandler btnFour.Click, AddressOf ButtonClick
btnFive.Location = New Point(150, 250) btnFive.Size = New Size(50, 50) btnFive.Text = "5" AddHandler btnFive.Click, AddressOf ButtonClick
btnSix.Location = New Point(250, 250) btnSix.Size = New Size(50, 50) btnSix.Text = "1" AddHandler btnSix.Click, AddressOf ButtonClick
btnSeven.Location = New Point(50, 350) btnSeven.Size = New Size(50, 50) btnSeven.Text = "7" AddHandler btnSeven.Click, AddressOf ButtonClick
btnEigth.Location = New Point(150, 350) btnEigth.Size = New Size(50, 50) btnEigth.Text = "8" AddHandler btnEigth.Click, AddressOf ButtonClick
btnNine.Location = New Point(250, 350) btnNine.Size = New Size(50, 50) btnNine.Text = "9" AddHandler btnNine.Click, AddressOf ButtonClick
btnZero.Location = New Point(50, 450) btnZero.Size = New Size(50, 50) btnZero.Text = "0" AddHandler btnZero.Click, AddressOf ButtonClick
btnPlus.Location = New Point(350, 150) btnPlus.Size = New Size(50, 50) btnPlus.Text = "+" AddHandler btnPlus.Click, AddressOf ButtonClick
btnMinus.Location = New Point(350, 250) btnMinus.Size = New Size(50, 50) btnMinus.Text = "-" AddHandler btnMinus.Click, AddressOf ButtonClick
btnMultiply.Location = New Point(350, 350) btnMultiply.Size = New Size(50, 50) btnMultiply.Text = "*" AddHandler btnMultiply.Click, AddressOf ButtonClick
btnDivide.Location = New Point(350, 450) btnDivide.Size = New Size(50, 50) btnDivide.Text = "/" AddHandler btnDivide.Click, AddressOf ButtonClick
btnEqual.Location = New Point(150, 450) btnEqual.Size = New Size(150, 50) btnEqual.Text = "=" AddHandler btnEqual.Click, AddressOf ButtonClick
Private Sub ButtonClick(sender As Object, e As EventArgs) If sender Is btnOne Then tb.Text = tb.Text & "1" End If If sender Is btnTwo Then tb.Text = tb.Text & "2" End If If sender Is btnThree Then tb.Text = tb.Text & "3" End If If sender Is btnFour Then tb.Text = tb.Text & "4" End If If sender Is btnFive Then tb.Text = tb.Text & "5" End If If sender Is btnSix Then tb.Text = tb.Text & "6" End If If sender Is btnSeven Then tb.Text = tb.Text & "7" End If If sender Is btnEigth Then tb.Text = tb.Text & "8" End If If sender Is btnNine Then tb.Text = tb.Text & "9" End If If sender Is btnZero Then tb.Text = tb.Text & "0" End If If sender Is btnPlus Then acc = Double.Parse(tb.Text) op = "+" tb.Text = "" End If If sender Is btnMinus Then acc = Double.Parse(tb.Text) op = "-" tb.Text = "" End If If sender Is btnMultiply Then acc = Double.Parse(tb.Text) op = "*" tb.Text = "" End If If sender Is btnDivide Then acc = Double.Parse(tb.Text) op = "/" tb.Text = "" End If If sender Is btnEqual Then If op = "+" Then acc = acc + Double.Parse(tb.Text) End If If op = "-" Then acc = acc - Double.Parse(tb.Text) End If If op = "*" Then acc = acc * Double.Parse(tb.Text) End If If op = "/" Then acc = acc / Double.Parse(tb.Text) End If tb.Text = acc.ToString op = "" End If End Sub
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.