Code layout? (1 Viewer)

FreshCoder

Registered User.
Local time
Today, 14:00
Joined
Sep 22, 2018
Messages
33
Hi!

Can someone tell me if the layout of this code is ok?


Code:
Option Compare Database
Option Explicit

Private M As Double
    Dim i As Double
    Dim v1 As Double, v2 As Double, v As Double
    Dim op As String

Private Sub Com0_Click()
    txtDisplay = txtDisplay & "0"
End Sub

Private Sub Com1_Click()
    txtDisplay = txtDisplay & "1"
End Sub

Private Sub Com2_Click()
    txtDisplay = txtDisplay & "2"
End Sub

Private Sub Com3_Click()
    txtDisplay = txtDisplay & "3"
End Sub

Private Sub Com4_Click()
    txtDisplay = txtDisplay & "4"
End Sub

Private Sub Com5_Click()
    txtDisplay = txtDisplay & "5"
End Sub

Private Sub Com6_Click()
    txtDisplay = txtDisplay & "6"
End Sub

Private Sub Com7_Click()
    txtDisplay = txtDisplay & "7"
End Sub

Private Sub Com8_Click()
    txtDisplay = txtDisplay & "8"
End Sub

Private Sub Com9_Click()
    txtDisplay = txtDisplay & "9"
End Sub

Private Sub comMRC_Click()
    txtDisplay = M
    M = 0
End Sub

Private Sub ComDesimal_Click()
    txtDisplay = txtDisplay & ","
End Sub

Private Sub ComPluss_Click()
    txtDisplay = txtDisplay & "+"
End Sub

Private Sub ComMinus_Click()
    txtDisplay = txtDisplay & "-"
End Sub

Private Sub ComMult_Click()
    txtDisplay = txtDisplay & "*"
End Sub

Private Sub ComDiv_Click()
    txtDisplay = txtDisplay & "/"
End Sub

Private Sub ComClear_Click()
    txtDisplay = ""
End Sub

Private Sub ComMpluss_Click()
    If txtDisplay <> 0 Then
    M = M + txtDisplay
    End If
End Sub

Private Sub ComMminus_Click()
    If txtDisplay <> 0 Then
    M = M - txtDisplay
    End If
End Sub

Private Sub ComLik_Click()
   
'Oppsett for et uttrykk i txtDisplay med maks en operatør

    For i = 1 To Len(txtDisplay)
        op = Mid(txtDisplay, i, 1)
        If (op < "0" Or op > "9") And op <> "," Then
            Exit For
        End If
    Next i
        v1 = Left(txtDisplay, i - 1)
        v2 = Right(txtDisplay, Len(txtDisplay) - i)
    If op = "+" Then
        v = v1 + v2
    ElseIf op = "-" Then
        v = v1 - v2
    ElseIf op = "*" Then
        v = v1 * v2
    ElseIf op = "/" Then
        v = v1 / v2
    End If
        txtDisplay = v
End Sub
 

CJ_London

Super Moderator
Staff member
Local time
Today, 22:00
Joined
Feb 19, 2013
Messages
16,674
layout looks ok -some sort of calculator?

a potential issue

comMRC assigns M to txtDisplay - what if M has not been assigned a value?

comLik - you might want to investigate the Eval function - Eval("23*4/2") will return 46
 

FreshCoder

Registered User.
Local time
Today, 14:00
Joined
Sep 22, 2018
Messages
33
Thanks.

Yeah. Its a calculator, and i didnt get it approved so then i know its not the layout.
Its made to make one calculation. Just simple! Like 2*2 not 2*2*2. Guess its a bit work to make it work with more calculations. But the M function. You have an idea there?
 

Attachments

  • Kalkulator-Utvidet.accdb
    1.1 MB · Views: 97

Users who are viewing this thread

Top Bottom