aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS-TheRevival/TerminalApplications/External/BasicCalculator/App_BC.vb
blob: adcb3bdcb970de2bece46e8003f9e95cf6cf670a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
Module App_BC
    'Basic Calculator's RAM
    Public BC_ReadNumbers As Integer
    Public BC_Numbers1 As String
    Public BC_Numbers2 As String
    Public BC_ThriceMoreValue As Integer
    Public BC_ThriceMoreCount As Integer
    Public BC_CurrentNumber As String
    Public BC_Result As Integer
    Public BC_Operation2 As String

    Public Sub BC_Start()
        Console.DefaultPrompt = "> "
        ResetLine("bc (Basic Calcultator)")
        NewLine("Copyright, Free Software Foundation.")
        NewLine("ShiftOS port by DevX.")
        NewLine("This is free software with ABSOLUTELY NO WARRANTY.")
        NewLine(Nothing)
        Console.CurrentInterpreter = "bc"
        Console.ShouldChange = True
        Console_Interpreters()
    End Sub

    Public Sub BC_Calculate()
        BC_ReadNumbers = 0
        BC_ThriceMoreValue = 1
        BC_Numbers1 = Nothing
        BC_Numbers2 = Nothing
        BC_Operation2 = Nothing
        BC_CurrentNumber = Nothing
        BC_Result = Nothing
        Dim GetText As String
        Try
            Do
                GetText = command.Chars(BC_ReadNumbers)
                Select Case GetText
                    Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
                        BC_CurrentNumber = BC_CurrentNumber & GetText
                    Case "+", "-", "*", "/", "^"
                        Dim BC_Numbers3 As Integer
                        Select Case BC_ThriceMoreValue
                            Case 1
                                BC_Numbers1 = BC_CurrentNumber
                                BC_CurrentNumber = Nothing
                                BC_Operation2 = GetText
                                BC_ThriceMoreValue = BC_ThriceMoreValue + 1
                            Case >= 2
                                BC_Numbers2 = BC_CurrentNumber
                                BC_Counting(BC_Numbers1, BC_Numbers2, BC_Operation2)
                                BC_Numbers3 = BC_Result
                                BC_Numbers1 = BC_Numbers3
                                BC_Numbers2 = Nothing
                                BC_CurrentNumber = Nothing
                                BC_ThriceMoreValue = BC_ThriceMoreValue + 1
                        End Select
                        BC_Operation2 = GetText
                    Case "."
                        NewLine("Decimals aren't supported yet!")
                    Case Else
                        'BC_Counting(BC_Numbers1, BC_Numbers2, BC_Operation2)
                End Select
                BC_ReadNumbers = BC_ReadNumbers + 1
            Loop
        Catch ex As Exception
            BC_Numbers2 = BC_CurrentNumber
            BC_CurrentNumber = Nothing
        End Try
        BC_Counting(BC_Numbers1, BC_Numbers2, BC_Operation2)
        BC_ThriceMoreValue = Nothing
        NewLine(BC_Result)
        If BC_Result = 69 Then
            NewLine("Nice!")
        End If
    End Sub

    Public Sub BC_Counting(FirstNum As Integer, SecondNum As Integer, Operation As String)
        Select Case Operation
            Case "+"
                BC_Result = FirstNum + SecondNum
            Case "-"
                BC_Result = FirstNum - SecondNum
            Case "*"
                BC_Result = FirstNum * SecondNum
            Case "/"
                BC_Result = FirstNum / SecondNum
            Case "^"
                BC_Result = FirstNum ^ SecondNum
        End Select
    End Sub
End Module