jeg skal have lavet en lommeregner som regner hvidrer når man trykker på eks. "+" dvs:
tal + tal - tal * tal = resultat, som koden er her, bliver man nød til at trykke på "=" tasten for at kunne regne hvidre, (tal +tal = resultat)
jeg hved ikke om det er uoverskueligt at jeg bare har kopieret koden ind her.
men ellers må jeg finde en anden løsning hvis det bliver nødventigt.
Koden:
Option Explicit
Dim tal1 As Double
Dim tal2 As Double
Dim M As Double
Dim PlusMinus As Variant
Private Sub Command1_Click()
FEJl
PlusMinus = "+"
Text1.Text = ""
End Sub
Private Sub Command10_Click()
If tal1 <> 0 Then
Text1.Text = "-" & Text1.Text
tal2 = "-" & tal2
Else
Text1.Text = "-" & Text1.Text
tal1 = "-" & tal1
End If
End Sub
Private Sub Command11_Click()
Text1.Text = Text1.Text & "1"
End Sub
Private Sub Command12_Click()
Text1.Text = Text1.Text & "2"
End Sub
Private Sub Command13_Click()
Text1.Text = Text1.Text & "3"
End Sub
Private Sub Command14_Click()
Text1.Text = Text1.Text & "4"
End Sub
Private Sub Command15_Click()
Text1.Text = Text1.Text & "5"
End Sub
Private Sub Command16_Click()
Text1.Text = Text1.Text & "6"
End Sub
Private Sub Command17_Click()
Text1.Text = Text1.Text & "7"
End Sub
Private Sub Command18_Click()
Text1.Text = Text1.Text & "8"
End Sub
Private Sub Command19_Click()
Text1.Text = Text1.Text & "9"
End Sub
Private Sub Command2_Click()
REGN
End Sub
Private Sub Command20_Click()
Text1.Text = Text1.Text & "0"
End Sub
Private Sub Command21_Click()
FEJl
PlusMinus = "^"
Text1.Text = ""
End Sub
Private Sub Command22_Click()
If Not IsNumeric(Text1.Text) Then
MsgBox prompt:="Fejl: der skal skrives et tal", Title:="Fejl"
Else
If Text1.Text <> 0 Then
M = Text1.Text
Label1.Caption = "M"
End If
End If
End Sub
Private Sub Command23_Click()
Text1.Text = M
End Sub
Private Sub Command24_Click()
M = 0
Label1.Caption = ""
End Sub
Private Sub Command3_Click()
FEJl
PlusMinus = "-"
Text1.Text = ""
End Sub
Private Sub Command4_Click()
FEJl
PlusMinus = "/"
Text1.Text = ""
End Sub
Private Sub Command5_Click()
FEJl
PlusMinus = "*"
Text1.Text = ""
End Sub
Private Sub Command6_Click()
FEJl
PlusMinus = "mod"
Text1.Text = ""
End Sub
Private Sub Command7_Click()
FEJl
PlusMinus = ""
Text1.Text = ""
End Sub
Private Sub Command8_Click()
PlusMinus = ""
tal1 = 0
tal2 = 0
Text1.Text = ""
End Sub
Private Sub Command9_Click()
Text1.Text = Text1.Text & ","
End Sub
Public Function FEJl()
If Not IsNumeric(Text1.Text) Then
MsgBox prompt:="Fejl: der skal skrives et tal", Title:="Fejl"
Else
tal1 = Text1.Text
End If
End Function
Public Sub REGN()
If Not IsNumeric(Text1.Text) Then
MsgBox "Fejl: Der skal skrives et tal", Title:="Fejl"
Else
tal2 = Text1.Text
End If
If PlusMinus = "+" Then
Text1.Text = tal1 + tal2
End If
If PlusMinus = "-" Then
Text1.Text = (tal1 - tal2)
End If
If PlusMinus = "/" Then
Text1.Text = tal1 / tal2
End If
If PlusMinus = "*" Then
Text1.Text = tal1 * tal2
End If
If PlusMinus = "mod" Then
Text1.Text = tal1 Mod tal2
End If
If PlusMinus = "" Then
Text1.Text = tal1 tal2
End If
If PlusMinus = "^" Then
Text1.Text = tal1 ^ tal2
End If
End Sub
--
Gæstebruger, opret dit eget
login og få din egen signatur.