###前提・実現したいこと
電卓プログラムを作っているのですが、1+2+3+4+などの連続した計算処理
を書くことができません。
= の処理のところにIF文を書くと思ったのですが、分かりません。
アドバイスの方お願いいたします。
コメント インデントがまだ未完全ですが、すみませんがよろしくお願いします。
###発生している問題・エラーメッセージ
エラーメッセージ
###該当のソースコード
Public Class Form2
'変数宣言
Private mode As String
Private taihi As String
Private cmd As String
Private hozon As String
Private Sub Keisan(Tasu As String) Select Case cmd Case "+", "-", "/", "*" TextBox1.Text = Tasu.ToString() cmd = "" Case Else If TextBox1.Text = "0" Then TextBox1.Text = Tasu.ToString() Else TextBox1.Text &= Tasu.ToString() End If End Select End Sub Private Sub BtnOne_Click(sender As Object, e As EventArgs) Handles btn1.Click Keisan("1") End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btn2.Click Keisan("2") End Sub '1~9のメソッド呼び出し Private Sub Button3_Click(sender As Object, e As EventArgs) Handles btn3.Click Keisan("3") End Sub Private Sub Button4_Click(sender As Object, e As EventArgs) Handles btn4.Click Keisan("4") End Sub Private Sub Button5_Click(sender As Object, e As EventArgs) Handles btn5.Click Keisan("5") End Sub Private Sub btn6_Click(sender As Object, e As EventArgs) Handles btn6.Click Keisan("6") End Sub Private Sub btn7_Click(sender As Object, e As EventArgs) Handles btn7.Click Keisan("7") End Sub Private Sub btn8_Click(sender As Object, e As EventArgs) Handles btn8.Click Keisan("8") End Sub Private Sub btn9_Click(sender As Object, e As EventArgs) Handles btn9.Click Keisan("9") End Sub Private Sub btn0_Click(sender As Object, e As EventArgs) Handles btn0.Click Keisan("0") End Sub Private Sub btn00_Click(sender As Object, e As EventArgs) Handles btn00.Click Keisan("00") End Sub Private Sub Form2_Load(sender As Object, e As EventArgs) Handles Me.Load TextBox1.Text = "0" mode = "" cmd = "" taihi = "" End Sub Private Sub btnDel_Click(sender As Object, e As EventArgs) Handles btnDel.Click If TextBox1.Text >= "0" And Text <= "9" Then End If If TextBox1.Text = "C" Then End If End Sub Private Sub ButtonPlus_Click(sender As Object, e As EventArgs) Handles ButtonPlus.Click taihi = TextBox1.Text cmd = "+" mode = "+" End Sub Private Function Geta() As Integer Throw New NotImplementedException() End Function Private Function d() As Object Throw New NotImplementedException() End Function Private Function Getope() As String End Function Private Sub btnPoint_Click(sender As Object, e As EventArgs) Handles btnPoint.Click End Sub Private Sub ButtonCancel_Click(sender As Object, e As EventArgs) Handles ButtonCancel.Click mode = "" cmd = "" hozon = "" taihi = "" TextBox1.Text = "0" End Sub Private Sub ButtonMinus_Click(sender As Object, e As EventArgs) Handles ButtonMinus.Click taihi = TextBox1.Text cmd = "-" mode = "-" End Sub Private Sub ButtonEqual_Click(sender As Object, e As EventArgs) Handles ButtonEqual.Click Dim a As Integer = Integer.Parse(taihi) Dim b As Integer = Integer.Parse(TextBox1.Text) If hozon = "" Then hozon = TextBox1.Text Else b = Integer.Parse(hozon) End If Select Case mode Case "+" Dim intTotal As Integer = a + b TextBox1.Text = intTotal.ToString() Case "-" Dim inthiku As Integer = a - b TextBox1.Text = inthiku.ToString() Case "*" Dim intkakeru As Integer = a * b TextBox1.Text = intkakeru.ToString() Case "/" Dim intwaru As Integer = a \ b TextBox1.Text = intwaru.ToString() End Select taihi = TextBox1.Text End Sub Private Sub Form2_HandleDestroyed(sender As Object, e As EventArgs) Handles Me.HandleDestroyed End Sub Private Sub ButtonDiv_Click(sender As Object, e As EventArgs) Handles ButtonDiv.Click taihi = TextBox1.Text cmd = "/" mode = "/" End Sub Private Sub ButtonMul_Click(sender As Object, e As EventArgs) Handles ButtonMul.Click taihi = TextBox1.Text cmd = "*" mode = "*" End Sub
End Class
###試したこと
新たに保存しておく用の変数を作ろうとしたがうまく動かなかった。
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
「1+2+3+4+などの連続した計算処理」というのは、どのような動作を想定しているのでしょうか? 質問のコードを見ると、電卓のキーが押されるたびに処理が進むようなので、"1+2+3+4+"は八つの処理(八つのキーを押す操作)に分かれたものにしかならないと思われます。
回答2件
あなたの回答
tips
プレビュー