Skip to main content

VB Program No: 1


           Create an application in vb.net that perform live calculator using difference 10 digits buttons, 4 operators (+ , - , * , / ), put some scientific calculations facilities .



Public Class Form1
    Dim no1, no2 As Double
    Dim x As Integer
    Dim op As Char
    Dim b = False, c As Boolean = False
    Dim d As Boolean = True

‘---------------------- 1-9 Buttons --------------------
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click, Button8.Click, Button7.Click, Button6.Click, Button5.Click, Button4.Click, Button3.Click, Button2.Click, Button1.Click
       
If x = 1 Then
            TextBox1.Clear()
            x = 0
        End If
        b = True
        If d = True Then
            If Me.TextBox1.Text.IndexOf(".") = 1 Or                         Me.TextBox1.Text.IndexOf(".") = 0 Then
                Me.TextBox1.Text += sender.text
            Else
                Me.TextBox1.Text = sender.text
                d = False
            End If
        Else
            Me.TextBox1.Text += sender.text
        End If

    End Sub

‘------------------- operators( +, - ,*, /) -----------------
Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click, Button15.Click, Button14.Click, Button13.Click

        If c = True Then
            no2 = Me.TextBox1.Text
            Select Case op
                Case "+"
                    Me.TextBox1.Text = no1 + no2
                    no1 = Me.TextBox1.Text
                    op = sender.text
                Case "-"
                    Me.TextBox1.Text = no1 - no2
                    no1 = Me.TextBox1.Text
                    op = sender.text
                Case "*"
                    Me.TextBox1.Text = no1 * no2
                    no1 = Me.TextBox1.Text
                    op = sender.text
                Case "/"
                    Me.TextBox1.Text = no1 / no2
                    no1 = Me.TextBox1.Text
                    op = sender.text
            End Select
           
            d = True
        Else

            If x = 0 Then
                no1 = Me.TextBox1.Text
                op = sender.text
                c = True
                x = 1
            End If
          
        End If

    End Sub

‘---------------------- (=) coding --------------------------
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        If Me.TextBox1.Text = "" Then
        Else
            no2 = Me.TextBox1.Text
            Select Case op
                Case "+"
                    Me.TextBox1.Text = no1 + no2
                Case "-"
                    Me.TextBox1.Text = no1 - no2
                Case "*"
                    Me.TextBox1.Text = no1 * no2
                Case "/"
                    Me.TextBox1.Text = no1 / no2
            End Select
            c = False
        End If
      
    End Sub

‘-------------------- point(.) -----------------------------
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        If Me.TextBox1.Text.IndexOf(".") = -1 Then
            Me.TextBox1.Text += Me.Button10.Text
        End If
    End Sub


‘----------------------- 0 Button --------------------------
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        If Me.TextBox1.Text = "0" Then
        Else
            If b = False Then
                Me.TextBox1.Text = Me.Button11.Text
            Else
                Me.TextBox1.Text += Me.Button11.Text
            End If
        End If
 End Sub

‘---------------------- C ----------------------------
Private Sub Button23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button23.Click
        Me.TextBox1.Clear()
End Sub

‘----------------- sqrt button -----------------------
Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
        Me.TextBox1.Text = Math.Sqrt(Me.TextBox1.Text)
End Sub

 ‘------------------- 1/X button ---------------------------
 Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click
        Me.TextBox1.Text = 1 / Me.TextBox1.Text
 End Sub

‘-------------- BACKSPACE -----------------------------
Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click
        Dim s As String
        If Me.TextBox1.Text = "" Then
        Else
    s = Me.TextBox1.Text.Remove(Me.TextBox1.Text.Length - 1, 1)
            Me.TextBox1.Text = s
            c = False
        End If
 End Sub
‘----------------------- -/+ Button ---------------------------
Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click
        Me.TextBox1.Text = -1 * Me.TextBox1.Tex
End Sub

 ‘----------------- CE ------------------------------- 
Private Sub Button22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button22.Click
        Me.TextBox1.Text = ""
        no1 = Val("")
        op = ""
 End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.TextBox1.Text = "0"
    End Sub

‘-----------------  sin --------------------------  
 Private Sub Button24_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button24.Click
        Me.TextBox1.Text = Math.Sin(Me.TextBox1.Text)
    End Sub

‘-----------------  cos --------------------------
    Private Sub Button25_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button25.Click
        Me.TextBox1.Text = Math.Cos(Me.TextBox1.Text)
    End Sub

‘-----------------  tan --------------------------
    Private Sub Button26_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button26.Click
        Me.TextBox1.Text = Math.Tan(Me.TextBox1.Text)
    End Sub

‘-----------------  log --------------------------
    Private Sub Button27_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button27.Click
        Me.TextBox1.Text = Math.Log(Me.TextBox1.Text)
    End Sub

  
    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        e.Handled = True
    End Sub



Made By: Yadav Roshani R. from Third Year of BCA
               
 

Comments

Popular posts from this blog

Characteristics of a Good Programming Language

Till now there are many high level languages which are very popular, and there are others, which could not become so popular in-spite of being very powerful. There might be many reasons for the success of a language, but one obvious reason is the characteristics of the language. Several characteristics believed to be important with respect to making a programming language good are briefly discussed below. Simplicity A good programming language must be simple and easy to learn and use. For example, BASIC is liked by many programmers only because of its simplicity. Thus, a good programming language should provide a programmer with a clear, simple and unified set of concepts which can be easily grasped. It is also easy to develop and implement a compiler or an interpreter for a programming language that is simple. However, the power needed for the language should not be sacrificed for simplicity. The overall simplicity of a programming language strongly affects the readability of the pr...

Angular 4 and Firebase Authentication: Setup

If you have come to this article, it means you are keen to learn new technology and that too Firebase. I love Firebase because it provides all basic but important features of any web application. Take for example, authentication, which is cumbersome and risky if not implemented with utmost care. And when we have the integration of Angular and Firebase, it becomes a lot easier for a developer to build such crucial modules in less time with minimal efforts. In this article we will create a simple Angular application using Firebase. I am going ahead with the understanding that you know the benefits of Firebase and have little knowledge about it. There are plenty of posts out on the web if you are behind. Step 1: Install Angular CLI (if not installed). npm install -g angular-cli Step 2: Create new Angular 4 project. By default now angular CLI will create Angular 4 project so you need not fret. ng new firebase-authentication Step 3: Check whether the ne...

Switch-case, simple calculator . . .

11.      Write a program to perform some mathematic functions with the help of “switch-case” statement. #include<stdio.h> #include<conio.h> void main() { int a,b,ans; char c; clrscr(); printf("\ Enter a and b:"); scanf("%d%d",&a,&b); printf("\n Enter operator:"); fflush(stdin); scanf("%c",&c); switch(c) { case'+':ans=a+b;       break; case'-':ans=a-b;       break; case'*':ans=a*b;       break; case'/':ans=a/b;       break; } printf("\n ans %d",ans); getch(); } 12.      Print the Fibonacci series #include<stdio.h> #include<conio.h> void main() { int a=1,b=1,s=3,c,ch; clrscr(); printf("how many steps="); scanf("%d",&ch); printf("%5d%5d",a,b); for(s=3;s<=ch;s++) {       c=a+b;       printf("%5d",c);       a=b;    ...