' 5.09.2007 by pac-man
' Calculadora basica
' Sin validaciones _
' Manejadores _
' Metodo Mid _
' Pasaje por valor y ref, en este caso no lo utilize.
' Nota: El siguiente codigo corre sin necesidad de incrustar los controles _
' ya que los mismo estan implementados en el codigo, para poder usarlo, creen _
' un proyecto nuevo, pulsen sobre el fomulario, borren el codigo que le _
' genera, luego peguen el siguiente codigo y por ultimo a correrlo.
' www.vebenet.blogspot.com , allí puse los demas ejercicios.Cualquier cosa _
' pregunten.
Public Class Form1
Dim i, LugarSigno As Integer
Dim aux As String
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button01 As System.Windows.Forms.Button
Friend WithEvents Button02 As System.Windows.Forms.Button
Friend WithEvents Button03 As System.Windows.Forms.Button
Friend WithEvents Button04 As System.Windows.Forms.Button
Friend WithEvents Button05 As System.Windows.Forms.Button
Friend WithEvents Button06 As System.Windows.Forms.Button
Friend WithEvents Button07 As System.Windows.Forms.Button
Friend WithEvents Button08 As System.Windows.Forms.Button
Friend WithEvents Button09 As System.Windows.Forms.Button
Friend WithEvents Button10 As System.Windows.Forms.Button
Friend WithEvents Button11 As System.Windows.Forms.Button
Friend WithEvents Button12 As System.Windows.Forms.Button
Friend WithEvents Button13 As System.Windows.Forms.Button
Friend WithEvents Button14 As System.Windows.Forms.Button
Friend WithEvents Button15 As System.Windows.Forms.Button
Friend WithEvents Button16 As System.Windows.Forms.Button
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Button01 = New System.Windows.Forms.Button
Me.Button02 = New System.Windows.Forms.Button
Me.Button03 = New System.Windows.Forms.Button
Me.Button04 = New System.Windows.Forms.Button
Me.Button05 = New System.Windows.Forms.Button
Me.Button06 = New System.Windows.Forms.Button
Me.Button07 = New System.Windows.Forms.Button
Me.Button08 = New System.Windows.Forms.Button
Me.Button09 = New System.Windows.Forms.Button
Me.Button10 = New System.Windows.Forms.Button
Me.Button11 = New System.Windows.Forms.Button
Me.Button12 = New System.Windows.Forms.Button
Me.Button13 = New System.Windows.Forms.Button
Me.Button14 = New System.Windows.Forms.Button
Me.Button15 = New System.Windows.Forms.Button
Me.Button16 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 72.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.TextBox1.Location = New System.Drawing.Point(0, 1)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(399, 116)
Me.TextBox1.TabIndex = 0
'
'Button01
'
Me.Button01.Font = New System.Drawing.Font("Microsoft Sans Serif", 27.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Button01.Location = New System.Drawing.Point(0, 157)
Me.Button01.Name = "Button01"
Me.Button01.Size = New System.Drawing.Size(75, 53)
Me.Button01.TabIndex = 1
Me.Button01.Text = "1"
Me.Button01.UseVisualStyleBackColor = True
'
'Button02
'
Me.Button02.Font = New System.Drawing.Font("Microsoft Sans Serif", 27.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Button02.Location = New System.Drawing.Point(81, 157)
Me.Button02.Name = "Button02"
Me.Button02.Size = New System.Drawing.Size(75, 53)
Me.Button02.TabIndex = 2
Me.Button02.Text = "2"
Me.Button02.UseVisualStyleBackColor = True
'
'Button03
'
Me.Button03.Font = New System.Drawing.Font("Microsoft Sans Serif", 27.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Button03.Location = New System.Drawing.Point(162, 157)
Me.Button03.Name = "Button03"
Me.Button03.Size = New System.Drawing.Size(75, 53)
Me.Button03.TabIndex = 3
Me.Button03.Text = "3"
Me.Button03.UseVisualStyleBackColor = True
'
'Button04
'
Me.Button04.Font = New System.Drawing.Font("Microsoft Sans Serif", 27.75!)
Me.Button04.Location = New System.Drawing.Point(243, 157)
Me.Button04.Name = "Button04"
Me.Button04.Size = New System.Drawing.Size(75, 53)
Me.Button04.TabIndex = 4
Me.Button04.Text = "4"
Me.Button04.UseVisualStyleBackColor = True
'
'Button05
'
Me.Button05.Font = New System.Drawing.Font("Microsoft Sans Serif", 27.75!)
Me.Button05.Location = New System.Drawing.Point(324, 157)
Me.Button05.Name = "Button05"
Me.Button05.Size = New System.Drawing.Size(75, 53)
Me.Button05.TabIndex = 5
Me.Button05.Text = "5"
Me.Button05.UseVisualStyleBackColor = True
'
'Button06
'
Me.Button06.Font = New System.Drawing.Font("Microsoft Sans Serif", 27.75!)
Me.Button06.Location = New System.Drawing.Point(0, 216)
Me.Button06.Name = "Button06"
Me.Button06.Size = New System.Drawing.Size(75, 53)
Me.Button06.TabIndex = 6
Me.Button06.Text = "6"
Me.Button06.UseVisualStyleBackColor = True
'
'Button07
'
Me.Button07.Font = New System.Drawing.Font("Microsoft Sans Serif", 27.75!)
Me.Button07.Location = New System.Drawing.Point(81, 216)
Me.Button07.Name = "Button07"
Me.Button07.Size = New System.Drawing.Size(75, 53)
Me.Button07.TabIndex = 7
Me.Button07.Text = "7"
Me.Button07.UseVisualStyleBackColor = True
'
'Button08
'
Me.Button08.Font = New System.Drawing.Font("Microsoft Sans Serif", 27.75!)
Me.Button08.Location = New System.Drawing.Point(162, 216)
Me.Button08.Name = "Button08"
Me.Button08.Size = New System.Drawing.Size(75, 53)
Me.Button08.TabIndex = 8
Me.Button08.Text = "8"
Me.Button08.UseVisualStyleBackColor = True
'
'Button09
'
Me.Button09.Font = New System.Drawing.Font("Microsoft Sans Serif", 27.75!)
Me.Button09.Location = New System.Drawing.Point(243, 216)
Me.Button09.Name = "Button09"
Me.Button09.Size = New System.Drawing.Size(75, 53)
Me.Button09.TabIndex = 9
Me.Button09.Text = "9"
Me.Button09.UseVisualStyleBackColor = True
'
'Button10
'
Me.Button10.Font = New System.Drawing.Font("Microsoft Sans Serif", 27.75!)
Me.Button10.Location = New System.Drawing.Point(324, 216)
Me.Button10.Name = "Button10"
Me.Button10.Size = New System.Drawing.Size(75, 53)
Me.Button10.TabIndex = 10
Me.Button10.Text = "0"
Me.Button10.UseVisualStyleBackColor = True
'
'Button11
'
Me.Button11.Font = New System.Drawing.Font("Microsoft Sans Serif", 27.75!)
Me.Button11.Location = New System.Drawing.Point(324, 277)
Me.Button11.Name = "Button11"
Me.Button11.Size = New System.Drawing.Size(76, 51)
Me.Button11.TabIndex = 11
Me.Button11.Text = "="
Me.Button11.UseVisualStyleBackColor = True
'
'Button12
'
Me.Button12.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.75!)
Me.Button12.Location = New System.Drawing.Point(0, 123)
Me.Button12.Name = "Button12"
Me.Button12.Size = New System.Drawing.Size(399, 28)
Me.Button12.TabIndex = 12
Me.Button12.Text = "&Limpar"
Me.Button12.UseVisualStyleBackColor = True
'
'Button13
'
Me.Button13.Font = New System.Drawing.Font("Microsoft Sans Serif", 27.75!)
Me.Button13.Location = New System.Drawing.Point(0, 275)
Me.Button13.Name = "Button13"
Me.Button13.Size = New System.Drawing.Size(75, 53)
Me.Button13.TabIndex = 13
Me.Button13.Text = "+"
Me.Button13.UseVisualStyleBackColor = True
'
'Button14
'
Me.Button14.Font = New System.Drawing.Font("Microsoft Sans Serif", 27.75!)
Me.Button14.Location = New System.Drawing.Point(81, 275)
Me.Button14.Name = "Button14"
Me.Button14.Size = New System.Drawing.Size(75, 53)
Me.Button14.TabIndex = 14
Me.Button14.Text = "-"
Me.Button14.UseVisualStyleBackColor = True
'
'Button15
'
Me.Button15.Font = New System.Drawing.Font("Microsoft Sans Serif", 27.75!)
Me.Button15.Location = New System.Drawing.Point(162, 277)
Me.Button15.Name = "Button15"
Me.Button15.Size = New System.Drawing.Size(75, 51)
Me.Button15.TabIndex = 15
Me.Button15.Text = "*"
Me.Button15.UseVisualStyleBackColor = True
'
'Button16
'
Me.Button16.Font = New System.Drawing.Font("Microsoft Sans Serif", 27.75!)
Me.Button16.Location = New System.Drawing.Point(243, 277)
Me.Button16.Name = "Button16"
Me.Button16.Size = New System.Drawing.Size(75, 51)
Me.Button16.TabIndex = 16
Me.Button16.Text = "/"
Me.Button16.UseVisualStyleBackColor = True
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(490, 329)
Me.Controls.Add(Me.Button16)
Me.Controls.Add(Me.Button15)
Me.Controls.Add(Me.Button14)
Me.Controls.Add(Me.Button13)
Me.Controls.Add(Me.Button12)
Me.Controls.Add(Me.Button11)
Me.Controls.Add(Me.Button10)
Me.Controls.Add(Me.Button09)
Me.Controls.Add(Me.Button08)
Me.Controls.Add(Me.Button07)
Me.Controls.Add(Me.Button06)
Me.Controls.Add(Me.Button05)
Me.Controls.Add(Me.Button04)
Me.Controls.Add(Me.Button03)
Me.Controls.Add(Me.Button02)
Me.Controls.Add(Me.Button01)
Me.Controls.Add(Me.TextBox1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.MaximizeBox = False
Me.Name = "Form1"
Me.ShowIcon = False
Me.Text = " Calculadora"
Me.ResumeLayout(False)
Me.PerformLayout()
' Manejadores
AddHandler Button01.Click, AddressOf Metodo
AddHandler Button02.Click, AddressOf Metodo
AddHandler Button03.Click, AddressOf Metodo
AddHandler Button04.Click, AddressOf Metodo
AddHandler Button05.Click, AddressOf Metodo
AddHandler Button06.Click, AddressOf Metodo
AddHandler Button07.Click, AddressOf Metodo
AddHandler Button08.Click, AddressOf Metodo
AddHandler Button09.Click, AddressOf Metodo
AddHandler Button10.Click, AddressOf Metodo
AddHandler Button11.Click, AddressOf Calcul
AddHandler Button12.Click, AddressOf Limpia
AddHandler Button13.Click, AddressOf Metodo
AddHandler Button14.Click, AddressOf Metodo
AddHandler Button15.Click, AddressOf Metodo
AddHandler Button16.Click, AddressOf Metodo
End Sub
Private Sub Metodo(ByVal sender As System.Object, ByVal e As System.EventArgs)
TextBox1.Text = TextBox1.Text & CType(sender, Button).Text
i = i + 1
If IsNumeric(Mid(TextBox1.Text, i, 1)) = False Then LugarSigno = i
End Sub
Private Sub Calcul(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
Select Case (Mid(TextBox1.Text, LugarSigno, 1))
Case "+"
TextBox1.Text = (CType((Mid(TextBox1.Text, 1, LugarSigno - 1)), Integer)) + (CType((Mid(TextBox1.Text, LugarSigno + 1, i - LugarSigno)), Integer))
Case "-"
TextBox1.Text = (CType((Mid(TextBox1.Text, 1, LugarSigno - 1)), Integer)) - (CType((Mid(TextBox1.Text, LugarSigno + 1, i - LugarSigno)), Integer))
Case "*"
TextBox1.Text = (CType((Mid(TextBox1.Text, 1, LugarSigno - 1)), Integer)) * (CType((Mid(TextBox1.Text, LugarSigno + 1, i - LugarSigno)), Integer))
Case "/"
TextBox1.Text = (CType((Mid(TextBox1.Text, 1, LugarSigno - 1)), Integer)) / (CType((Mid(TextBox1.Text, LugarSigno + 1, i - LugarSigno)), Integer))
Case Else
Button12.Text = "Borrar resultado"
End Select
End Sub
Public Sub Limpia(ByVal sender As System.Object, ByVal e As System.EventArgs)
i = 0
TextBox1.Clear()
Button12.Text = "Limpiar"
End Sub
End Class