Hi everyone! This is a simple calculator which programmed by me on Visual studio. Worked out on .NET 2.0 framework and used Visual Basic as the programming language. This calculator is absolutely looks like (and also the functionality) the windows calculator on accessories menu.
The code block for button click events is as below.
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 | '2010-08-14 Calculator Solution By Rasan Public Class frmMain Dim lastbtn As String = "oprt" Dim lastoprt As String Dim result As Double = 0 Dim ram As Double = 0 Dim mplus As Double = 0 Dim num As Integer Dim isdec As Boolean = False Dim upperval As Double = 0 Dim lowerval As Double = 0 Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastbtn = "oprt" Or lastbtn = "sqrt" Or txtDisplay.Text = "0." Then txtDisplay.Text = "." End If If isdec = False Then num = txtDisplay.Text.Length - 1 txtDisplay.Text = txtDisplay.Text.Insert(num, "1") Else If txtDisplay.Text = "." Then txtDisplay.Text = "0." End If num = txtDisplay.Text.Length txtDisplay.Text = txtDisplay.Text.Insert(num, "1") End If lastbtn = "in" End If End Sub Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastbtn = "oprt" Or lastbtn = "sqrt" Or txtDisplay.Text = "0." Then txtDisplay.Text = "." End If If isdec = False Then num = txtDisplay.Text.Length - 1 txtDisplay.Text = txtDisplay.Text.Insert(num, "2") Else If txtDisplay.Text = "." Then txtDisplay.Text = "0." End If num = txtDisplay.Text.Length txtDisplay.Text = txtDisplay.Text.Insert(num, "2") End If lastbtn = "in" End If End Sub Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastbtn = "oprt" Or lastbtn = "sqrt" Or txtDisplay.Text = "0." Then txtDisplay.Text = "." End If If isdec = False Then num = txtDisplay.Text.Length - 1 txtDisplay.Text = txtDisplay.Text.Insert(num, "3") Else If txtDisplay.Text = "." Then txtDisplay.Text = "0." End If num = txtDisplay.Text.Length txtDisplay.Text = txtDisplay.Text.Insert(num, "3") End If lastbtn = "in" End If End Sub Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastbtn = "oprt" Or lastbtn = "sqrt" Or txtDisplay.Text = "0." Then txtDisplay.Text = "." End If If isdec = False Then num = txtDisplay.Text.Length - 1 txtDisplay.Text = txtDisplay.Text.Insert(num, "4") Else If txtDisplay.Text = "." Then txtDisplay.Text = "0." End If num = txtDisplay.Text.Length txtDisplay.Text = txtDisplay.Text.Insert(num, "4") End If lastbtn = "in" End If End Sub Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastbtn = "oprt" Or lastbtn = "sqrt" Or txtDisplay.Text = "0." Then txtDisplay.Text = "." End If If isdec = False Then num = txtDisplay.Text.Length - 1 txtDisplay.Text = txtDisplay.Text.Insert(num, "5") Else If txtDisplay.Text = "." Then txtDisplay.Text = "0." End If num = txtDisplay.Text.Length txtDisplay.Text = txtDisplay.Text.Insert(num, "5") End If lastbtn = "in" End If End Sub Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastbtn = "oprt" Or lastbtn = "sqrt" Or txtDisplay.Text = "0." Then txtDisplay.Text = "." End If If isdec = False Then num = txtDisplay.Text.Length - 1 txtDisplay.Text = txtDisplay.Text.Insert(num, "6") Else If txtDisplay.Text = "." Then txtDisplay.Text = "0." End If num = txtDisplay.Text.Length txtDisplay.Text = txtDisplay.Text.Insert(num, "6") End If lastbtn = "in" End If End Sub Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastbtn = "oprt" Or lastbtn = "sqrt" Or txtDisplay.Text = "0." Then txtDisplay.Text = "." End If If isdec = False Then num = txtDisplay.Text.Length - 1 txtDisplay.Text = txtDisplay.Text.Insert(num, "7") Else If txtDisplay.Text = "." Then txtDisplay.Text = "0." End If num = txtDisplay.Text.Length txtDisplay.Text = txtDisplay.Text.Insert(num, "7") End If lastbtn = "in" End If End Sub Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastbtn = "oprt" Or lastbtn = "sqrt" Or txtDisplay.Text = "0." Then txtDisplay.Text = "." End If If isdec = False Then num = txtDisplay.Text.Length - 1 txtDisplay.Text = txtDisplay.Text.Insert(num, "8") Else If txtDisplay.Text = "." Then txtDisplay.Text = "0." End If num = txtDisplay.Text.Length txtDisplay.Text = txtDisplay.Text.Insert(num, "8") End If lastbtn = "in" End If End Sub Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastbtn = "oprt" Or lastbtn = "sqrt" Or txtDisplay.Text = "0." Then txtDisplay.Text = "." End If If isdec = False Then num = txtDisplay.Text.Length - 1 txtDisplay.Text = txtDisplay.Text.Insert(num, "9") Else If txtDisplay.Text = "." Then txtDisplay.Text = "0." End If num = txtDisplay.Text.Length txtDisplay.Text = txtDisplay.Text.Insert(num, "9") End If lastbtn = "in" End If End Sub Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastbtn = "oprt" Or lastbtn = "sqrt" Or txtDisplay.Text = "0." Then txtDisplay.Text = "." End If If isdec = False Then If txtDisplay.Text <> "0." Then num = txtDisplay.Text.Length - 1 txtDisplay.Text = txtDisplay.Text.Insert(num, "0") End If Else If txtDisplay.Text = "." Then txtDisplay.Text = "0." End If num = txtDisplay.Text.Length txtDisplay.Text = txtDisplay.Text.Insert(num, "0") End If lastbtn = "in" End If End Sub Private Sub btnDot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDot.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastbtn = "oprt" Or lastbtn = "sqrt" Then txtDisplay.Text = "0." End If isdec = True lastbtn = "in" End If End Sub Private Sub btnPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlus.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastoprt <> "plus" Or lastbtn = "in" Then ram = txtDisplay.Text If lastoprt = "eq" Then result = txtDisplay.Text End If If lastbtn <> "oprt" Then If lastoprt = "plus" Then result = result + ram ElseIf lastoprt = "minus" Then result = result - ram ElseIf lastoprt = "mul" Then result = result * ram ElseIf lastoprt = "dev" Then result = result / ram Else result = result + ram End If End If lastbtn = "oprt" lastoprt = "plus" txtDisplay.Text = result If txtDisplay.Text.Contains(".") Then txtDisplay.Text = result Else txtDisplay.Text = result & "." End If isdec = False End If End If End Sub Private Sub btnMinus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMinus.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastoprt <> "minus" Or lastbtn = "in" Then ram = txtDisplay.Text If lastoprt = "eq" Then result = txtDisplay.Text End If If lastbtn <> "oprt" Then If lastoprt = "plus" Then result = result + ram ElseIf lastoprt = "minus" Then result = result - ram ElseIf lastoprt = "mul" Then result = result * ram ElseIf lastoprt = "dev" Then result = result / ram Else result = result + ram End If End If lastbtn = "oprt" lastoprt = "minus" txtDisplay.Text = result If txtDisplay.Text.Contains(".") Then txtDisplay.Text = result Else txtDisplay.Text = result & "." End If isdec = False End If End If End Sub Private Sub btnMul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMul.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastoprt <> "mul" Or lastbtn = "in" Then ram = txtDisplay.Text If lastoprt = "eq" Then result = txtDisplay.Text End If If lastbtn <> "oprt" Then If lastoprt = "plus" Then result = result + ram ElseIf lastoprt = "minus" Then result = result - ram ElseIf lastoprt = "mul" Then result = result * ram ElseIf lastoprt = "dev" Then result = result / ram Else result = result + ram End If End If lastbtn = "oprt" lastoprt = "mul" txtDisplay.Text = result If txtDisplay.Text.Contains(".") Then txtDisplay.Text = result Else txtDisplay.Text = result & "." End If isdec = False End If End If End Sub Private Sub btnDev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDev.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastoprt <> "dev" Or lastbtn = "in" Then ram = txtDisplay.Text upperval = ram If lastoprt = "eq" Then result = txtDisplay.Text End If If lastbtn <> "oprt" Then If lastoprt = "plus" Then result = result + ram ElseIf lastoprt = "minus" Then result = result - ram ElseIf lastoprt = "mul" Then result = result * ram ElseIf lastoprt = "dev" Then result = result / ram Else result = result + ram End If End If lastbtn = "oprt" lastoprt = "dev" txtDisplay.Text = result If txtDisplay.Text.Contains(".") Then txtDisplay.Text = result Else txtDisplay.Text = result & "." End If isdec = False End If End If End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load txtDisplay.Text = "0." End Sub Private Sub btnEq_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEq.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else ram = txtDisplay.Text If lastoprt = "plus" Then result = result + ram ElseIf lastoprt = "minus" Then result = result - ram ElseIf lastoprt = "mul" Then result = result * ram ElseIf lastoprt = "dev" Then result = result / ram Else result = ram End If lastbtn = "oprt" lastoprt = "eq" txtDisplay.Text = result If txtDisplay.Text.Contains(".") Then txtDisplay.Text = result Else txtDisplay.Text = result & "." End If isdec = False End If End Sub Private Sub btnNeg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNeg.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else ram = txtDisplay.Text If ram <> 0 Then If txtDisplay.Text.Contains("-") Then txtDisplay.Text = txtDisplay.Text.Remove(0, 1) Else txtDisplay.Text = txtDisplay.Text.Insert(0, "-") End If End If End If End Sub Private Sub btnC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnC.Click txtDisplay.Text = "0." lastbtn = "oprt" lastoprt = "" isdec = False result = 0 ram = 0 mplus = 0 lowerval = 0 upperval = 0 lblDisplay.Text = "" End Sub Private Sub btnCe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCe.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then result = 0 ram = 0 End If txtDisplay.Text = "0." lastbtn = "oprt" isdec = False End Sub Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Or lastbtn <> "in" Then Beep() Else num = txtDisplay.Text.Length If txtDisplay.Text.Chars(num - 1) = "." Then If isdec = True Then isdec = False Else txtDisplay.Text = txtDisplay.Text.Remove(num - 2, 1) End If Else txtDisplay.Text = txtDisplay.Text.Remove(num - 1, 1) End If If num = 2 Or (txtDisplay.Text.Contains("-") And num = 3) Then txtDisplay.Text = "0." isdec = False lastbtn = "oprt" End If End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMplus.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else ram = txtDisplay.Text mplus = mplus + ram lblDisplay.Text = "M" End If lastbtn = "oprt" End Sub Private Sub btnSqrt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSqrt.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else Dim sqrt As Double = 0 ram = txtDisplay.Text lastbtn = "sqrt" lastoprt = "sqrt" sqrt = ram ^ (1 / 2) txtDisplay.Text = sqrt If txtDisplay.Text.Contains(".") Then txtDisplay.Text = sqrt Else txtDisplay.Text = sqrt & "." End If isdec = False End If End Sub Private Sub btnMminus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMminus.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else mplus = 0 lblDisplay.Text = "" End If lastbtn = "oprt" End Sub Private Sub btnMr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMr.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else txtDisplay.Text = mplus If txtDisplay.Text.Contains(".") Then txtDisplay.Text = mplus Else txtDisplay.Text = mplus & "." End If End If lastbtn = "oprt" End Sub Private Sub btnUndreone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUndreone.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else Dim undrone As Double = 0 ram = txtDisplay.Text lastbtn = "sqrt" lastoprt = "sqrt" undrone = 1 / ram txtDisplay.Text = undrone If txtDisplay.Text.Contains(".") Then txtDisplay.Text = undrone Else txtDisplay.Text = undrone & "." End If isdec = False End If End Sub Private Sub btnMs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMs.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else mplus = txtDisplay.Text lblDisplay.Text = "M" End If lastbtn = "oprt" End Sub Private Sub btnPercentage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPercentage.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else lowerval = txtDisplay.Text If lowerval = 0 Then result = 0 Else result = upperval / lowerval * 100 End If txtDisplay.Text = result If txtDisplay.Text.Contains(".") Then txtDisplay.Text = result Else txtDisplay.Text = result & "." End If lastbtn = "oprt" End If End Sub Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click End End Sub Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click frmAbout.Show() End Sub End Class |
'2010-08-14 Calculator Solution By Rasan Public Class frmMain Dim lastbtn As String = "oprt" Dim lastoprt As String Dim result As Double = 0 Dim ram As Double = 0 Dim mplus As Double = 0 Dim num As Integer Dim isdec As Boolean = False Dim upperval As Double = 0 Dim lowerval As Double = 0 Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastbtn = "oprt" Or lastbtn = "sqrt" Or txtDisplay.Text = "0." Then txtDisplay.Text = "." End If If isdec = False Then num = txtDisplay.Text.Length - 1 txtDisplay.Text = txtDisplay.Text.Insert(num, "1") Else If txtDisplay.Text = "." Then txtDisplay.Text = "0." End If num = txtDisplay.Text.Length txtDisplay.Text = txtDisplay.Text.Insert(num, "1") End If lastbtn = "in" End If End Sub Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastbtn = "oprt" Or lastbtn = "sqrt" Or txtDisplay.Text = "0." Then txtDisplay.Text = "." End If If isdec = False Then num = txtDisplay.Text.Length - 1 txtDisplay.Text = txtDisplay.Text.Insert(num, "2") Else If txtDisplay.Text = "." Then txtDisplay.Text = "0." End If num = txtDisplay.Text.Length txtDisplay.Text = txtDisplay.Text.Insert(num, "2") End If lastbtn = "in" End If End Sub Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastbtn = "oprt" Or lastbtn = "sqrt" Or txtDisplay.Text = "0." Then txtDisplay.Text = "." End If If isdec = False Then num = txtDisplay.Text.Length - 1 txtDisplay.Text = txtDisplay.Text.Insert(num, "3") Else If txtDisplay.Text = "." Then txtDisplay.Text = "0." End If num = txtDisplay.Text.Length txtDisplay.Text = txtDisplay.Text.Insert(num, "3") End If lastbtn = "in" End If End Sub Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastbtn = "oprt" Or lastbtn = "sqrt" Or txtDisplay.Text = "0." Then txtDisplay.Text = "." End If If isdec = False Then num = txtDisplay.Text.Length - 1 txtDisplay.Text = txtDisplay.Text.Insert(num, "4") Else If txtDisplay.Text = "." Then txtDisplay.Text = "0." End If num = txtDisplay.Text.Length txtDisplay.Text = txtDisplay.Text.Insert(num, "4") End If lastbtn = "in" End If End Sub Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastbtn = "oprt" Or lastbtn = "sqrt" Or txtDisplay.Text = "0." Then txtDisplay.Text = "." End If If isdec = False Then num = txtDisplay.Text.Length - 1 txtDisplay.Text = txtDisplay.Text.Insert(num, "5") Else If txtDisplay.Text = "." Then txtDisplay.Text = "0." End If num = txtDisplay.Text.Length txtDisplay.Text = txtDisplay.Text.Insert(num, "5") End If lastbtn = "in" End If End Sub Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastbtn = "oprt" Or lastbtn = "sqrt" Or txtDisplay.Text = "0." Then txtDisplay.Text = "." End If If isdec = False Then num = txtDisplay.Text.Length - 1 txtDisplay.Text = txtDisplay.Text.Insert(num, "6") Else If txtDisplay.Text = "." Then txtDisplay.Text = "0." End If num = txtDisplay.Text.Length txtDisplay.Text = txtDisplay.Text.Insert(num, "6") End If lastbtn = "in" End If End Sub Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastbtn = "oprt" Or lastbtn = "sqrt" Or txtDisplay.Text = "0." Then txtDisplay.Text = "." End If If isdec = False Then num = txtDisplay.Text.Length - 1 txtDisplay.Text = txtDisplay.Text.Insert(num, "7") Else If txtDisplay.Text = "." Then txtDisplay.Text = "0." End If num = txtDisplay.Text.Length txtDisplay.Text = txtDisplay.Text.Insert(num, "7") End If lastbtn = "in" End If End Sub Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastbtn = "oprt" Or lastbtn = "sqrt" Or txtDisplay.Text = "0." Then txtDisplay.Text = "." End If If isdec = False Then num = txtDisplay.Text.Length - 1 txtDisplay.Text = txtDisplay.Text.Insert(num, "8") Else If txtDisplay.Text = "." Then txtDisplay.Text = "0." End If num = txtDisplay.Text.Length txtDisplay.Text = txtDisplay.Text.Insert(num, "8") End If lastbtn = "in" End If End Sub Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastbtn = "oprt" Or lastbtn = "sqrt" Or txtDisplay.Text = "0." Then txtDisplay.Text = "." End If If isdec = False Then num = txtDisplay.Text.Length - 1 txtDisplay.Text = txtDisplay.Text.Insert(num, "9") Else If txtDisplay.Text = "." Then txtDisplay.Text = "0." End If num = txtDisplay.Text.Length txtDisplay.Text = txtDisplay.Text.Insert(num, "9") End If lastbtn = "in" End If End Sub Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastbtn = "oprt" Or lastbtn = "sqrt" Or txtDisplay.Text = "0." Then txtDisplay.Text = "." End If If isdec = False Then If txtDisplay.Text <> "0." Then num = txtDisplay.Text.Length - 1 txtDisplay.Text = txtDisplay.Text.Insert(num, "0") End If Else If txtDisplay.Text = "." Then txtDisplay.Text = "0." End If num = txtDisplay.Text.Length txtDisplay.Text = txtDisplay.Text.Insert(num, "0") End If lastbtn = "in" End If End Sub Private Sub btnDot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDot.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastbtn = "oprt" Or lastbtn = "sqrt" Then txtDisplay.Text = "0." End If isdec = True lastbtn = "in" End If End Sub Private Sub btnPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlus.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastoprt <> "plus" Or lastbtn = "in" Then ram = txtDisplay.Text If lastoprt = "eq" Then result = txtDisplay.Text End If If lastbtn <> "oprt" Then If lastoprt = "plus" Then result = result + ram ElseIf lastoprt = "minus" Then result = result - ram ElseIf lastoprt = "mul" Then result = result * ram ElseIf lastoprt = "dev" Then result = result / ram Else result = result + ram End If End If lastbtn = "oprt" lastoprt = "plus" txtDisplay.Text = result If txtDisplay.Text.Contains(".") Then txtDisplay.Text = result Else txtDisplay.Text = result & "." End If isdec = False End If End If End Sub Private Sub btnMinus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMinus.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastoprt <> "minus" Or lastbtn = "in" Then ram = txtDisplay.Text If lastoprt = "eq" Then result = txtDisplay.Text End If If lastbtn <> "oprt" Then If lastoprt = "plus" Then result = result + ram ElseIf lastoprt = "minus" Then result = result - ram ElseIf lastoprt = "mul" Then result = result * ram ElseIf lastoprt = "dev" Then result = result / ram Else result = result + ram End If End If lastbtn = "oprt" lastoprt = "minus" txtDisplay.Text = result If txtDisplay.Text.Contains(".") Then txtDisplay.Text = result Else txtDisplay.Text = result & "." End If isdec = False End If End If End Sub Private Sub btnMul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMul.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastoprt <> "mul" Or lastbtn = "in" Then ram = txtDisplay.Text If lastoprt = "eq" Then result = txtDisplay.Text End If If lastbtn <> "oprt" Then If lastoprt = "plus" Then result = result + ram ElseIf lastoprt = "minus" Then result = result - ram ElseIf lastoprt = "mul" Then result = result * ram ElseIf lastoprt = "dev" Then result = result / ram Else result = result + ram End If End If lastbtn = "oprt" lastoprt = "mul" txtDisplay.Text = result If txtDisplay.Text.Contains(".") Then txtDisplay.Text = result Else txtDisplay.Text = result & "." End If isdec = False End If End If End Sub Private Sub btnDev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDev.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else If lastoprt <> "dev" Or lastbtn = "in" Then ram = txtDisplay.Text upperval = ram If lastoprt = "eq" Then result = txtDisplay.Text End If If lastbtn <> "oprt" Then If lastoprt = "plus" Then result = result + ram ElseIf lastoprt = "minus" Then result = result - ram ElseIf lastoprt = "mul" Then result = result * ram ElseIf lastoprt = "dev" Then result = result / ram Else result = result + ram End If End If lastbtn = "oprt" lastoprt = "dev" txtDisplay.Text = result If txtDisplay.Text.Contains(".") Then txtDisplay.Text = result Else txtDisplay.Text = result & "." End If isdec = False End If End If End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load txtDisplay.Text = "0." End Sub Private Sub btnEq_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEq.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else ram = txtDisplay.Text If lastoprt = "plus" Then result = result + ram ElseIf lastoprt = "minus" Then result = result - ram ElseIf lastoprt = "mul" Then result = result * ram ElseIf lastoprt = "dev" Then result = result / ram Else result = ram End If lastbtn = "oprt" lastoprt = "eq" txtDisplay.Text = result If txtDisplay.Text.Contains(".") Then txtDisplay.Text = result Else txtDisplay.Text = result & "." End If isdec = False End If End Sub Private Sub btnNeg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNeg.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else ram = txtDisplay.Text If ram <> 0 Then If txtDisplay.Text.Contains("-") Then txtDisplay.Text = txtDisplay.Text.Remove(0, 1) Else txtDisplay.Text = txtDisplay.Text.Insert(0, "-") End If End If End If End Sub Private Sub btnC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnC.Click txtDisplay.Text = "0." lastbtn = "oprt" lastoprt = "" isdec = False result = 0 ram = 0 mplus = 0 lowerval = 0 upperval = 0 lblDisplay.Text = "" End Sub Private Sub btnCe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCe.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then result = 0 ram = 0 End If txtDisplay.Text = "0." lastbtn = "oprt" isdec = False End Sub Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Or lastbtn <> "in" Then Beep() Else num = txtDisplay.Text.Length If txtDisplay.Text.Chars(num - 1) = "." Then If isdec = True Then isdec = False Else txtDisplay.Text = txtDisplay.Text.Remove(num - 2, 1) End If Else txtDisplay.Text = txtDisplay.Text.Remove(num - 1, 1) End If If num = 2 Or (txtDisplay.Text.Contains("-") And num = 3) Then txtDisplay.Text = "0." isdec = False lastbtn = "oprt" End If End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMplus.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else ram = txtDisplay.Text mplus = mplus + ram lblDisplay.Text = "M" End If lastbtn = "oprt" End Sub Private Sub btnSqrt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSqrt.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else Dim sqrt As Double = 0 ram = txtDisplay.Text lastbtn = "sqrt" lastoprt = "sqrt" sqrt = ram ^ (1 / 2) txtDisplay.Text = sqrt If txtDisplay.Text.Contains(".") Then txtDisplay.Text = sqrt Else txtDisplay.Text = sqrt & "." End If isdec = False End If End Sub Private Sub btnMminus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMminus.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else mplus = 0 lblDisplay.Text = "" End If lastbtn = "oprt" End Sub Private Sub btnMr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMr.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else txtDisplay.Text = mplus If txtDisplay.Text.Contains(".") Then txtDisplay.Text = mplus Else txtDisplay.Text = mplus & "." End If End If lastbtn = "oprt" End Sub Private Sub btnUndreone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUndreone.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else Dim undrone As Double = 0 ram = txtDisplay.Text lastbtn = "sqrt" lastoprt = "sqrt" undrone = 1 / ram txtDisplay.Text = undrone If txtDisplay.Text.Contains(".") Then txtDisplay.Text = undrone Else txtDisplay.Text = undrone & "." End If isdec = False End If End Sub Private Sub btnMs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMs.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else mplus = txtDisplay.Text lblDisplay.Text = "M" End If lastbtn = "oprt" End Sub Private Sub btnPercentage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPercentage.Click If txtDisplay.Text.Contains("Infinity.") Or txtDisplay.Text.Contains("NaN.") Then Beep() Else lowerval = txtDisplay.Text If lowerval = 0 Then result = 0 Else result = upperval / lowerval * 100 End If txtDisplay.Text = result If txtDisplay.Text.Contains(".") Then txtDisplay.Text = result Else txtDisplay.Text = result & "." End If lastbtn = "oprt" End If End Sub Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click End End Sub Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click frmAbout.Show() End Sub End Class
How does it looks? OK. just feel free to download the source code from the below link, study it and improve it.
Download: Calculator VS Project