VB.Net Programming - Basic Calculator


VB.Net Programming - Basic Calculator.
[Video Demonstration and Source Code]

🎓 Master Visual Basic .NET and Access Database By Building the Point Of Sale System (POS).
ðŸ“ē Enroll Now: https://bit.ly/2WcbRhX

Visual Basic .Net Programming
» How to Create a Basic Calculator Using Structure.

[Screenshot]



What you will learn in this video tutorial.
  • Creating and Using Code File in VB .NET
  • Using Structure in VB .NET Project
  • Creating If-Then-ElseIf Statement
  • Using Select...Case Statement
  • Creating an array of buttons (AddHandler...AddressOf)
  • Constructing For...Next Statement (For Next Loop)
  • Using basic arithmetic operators in VB .NET
  • {
  • -              /, Obelus (Division)
  • -              *, Times (Multiplication)
  • -              -, Minus (Subtraction)
  • -              +, Plus (Addition)
  • }
  • Setting Form Caption Programmatically
  • Changing the Form Title Text Programmatically
  • Adding Comments in VB .Net Code
  • And much more!!!




Thank you for watching.
» Don't Forget to Like, Comment, Share and Subscribe to my Channel.

[Source Code]

1.>  Calculator.vb [Add Code File]

Option Explicit On
Option Strict On

Public Structure Calculator
    Private _a As Double
    Private _b As Double

    Public Property a() As Double
        Get
            Return _a
        End Get
        Set(value As Double)
            _a = value
        End Set
    End Property

    Public Property b() As Double
        Get
            Return _b
        End Get
        Set(value As Double)
            _b = value
        End Set
    End Property

    Public Function Add() As Double
        Return _a + _b
    End Function

    Public Function Subtract() As Double
        Return _a - _b
    End Function

    Public Function Multiply() As Double
        Return _a * _b
    End Function

    Public Function Divide() As Double
        Return _a / _b
    End Function
End Structure

2.> Form1.vb

Option Explicit On
Option Strict On
Public Class Form1
    Private _op As String
    Private _r As Double = 0.0
    Private _btn() As Button
    Private Const _cam As String = "VB.Net - Basic Calculator (Struct) - Code A Minute"
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Text = _cam
        _btn = {btnAdd, btnSubtract,
                btnMultiply, btnDivide}

        For i As Integer = 0 To _btn.Length - 1
            _btn(i).ForeColor = Color.Red
            AddHandler _btn(i).Click, AddressOf ShowOperator
        Next
    End Sub

    Private Sub ShowOperator(ByVal sender As Object, ByVal e As EventArgs)
        Dim btn As Button = CType(sender, Button)
        Dim str As String = btn.Text

        If (str = "+") Then
            _op = "+"
        ElseIf (str = "-") Then
            _op = "-"
        ElseIf (str = "x") Then
            _op = "x"
        ElseIf (str = "/") Then
            _op = "/"
        Else
            Exit Sub REM return;
        End If
        Me.LabelOperator.Text = str
    End Sub

    Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
        Dim c As Calculator
        c.a = Convert.ToDouble(txtNum1.Text.Trim())
        c.b = Convert.ToDouble(txtNum2.Text.Trim())

        Select Case (_op)
            Case "+"
                _r = c.Add()
            Case "-"
                _r = c.Subtract()
            Case "x"
                _r = c.Multiply()
            Case "/"
                _r = c.Divide()
            Case Else
                Exit Sub
        End Select

        Me.txtResult.Text = c.a & " " &
                            _op & " " &
                            c.b & " = " &
                            _r.ToString("F2")
        REM Thanks for watching
        ' Please Like comment and subscribe for more videos
        ' Thank you very much.
    End Sub
End Class

Visit me @:

#CodeAMinute #iBasskung #VisualBasicDotNet #Programming
#Calculator #YouTube #structure

Comments

  1. I like viewing web sites which comprehend the price of delivering the excellent useful resource free of charge. I truly adored reading your posting. Thank you! wazirx referral code

    ReplyDelete

Post a Comment