Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Visual Basic (https://www.askmehelpdesk.com/forumdisplay.php?f=469)
-   -   How to create a calculator in VB 6.0 (https://www.askmehelpdesk.com/showthread.php?t=54087)

  • Jan 12, 2007, 05:23 AM
    snaveenkumar123
    How to create a calculator in VB 6.0
    Hi! I'm Naveen
    I have a school project.
    Its 2 create a calculator in VB 6.0 using just basic or easy methods.
    Help me with the coding.
    Also I just need a simple coding , not a complex one or my teacher won't accept.
    Help!!
  • Jan 12, 2007, 07:03 AM
    ScottGem
    First may I call your attention to these guidelines on asking for homework help

    https://www.askmehelpdesk.com/langua...elp-board.html

    If you have a specific problem ask. Show us the code you have written and what doesn't work about it. We can then help.
  • Jul 2, 2007, 03:38 PM
    bloomer152000
    How to create a calculator in VB 6.0 ?
  • Jul 2, 2007, 04:52 PM
    ScottGem
    Please read the previous reply.
  • Aug 30, 2007, 01:21 AM
    corporateattitude
    Quote:

    Originally Posted by snaveenkumar123
    Hi! im Naveen
    i hav a school project.
    its 2 create a calculator in VB 6.0 using just basic or easy methods.
    help me with the coding.
    also i just need a simple coding , not a complex one or my teacher wont accept.
    Help!!!!

    you can so this:

    text1.text = int(text2.text) + int(text3.text)

    hope this help.
  • Nov 26, 2007, 12:21 AM
    Criza
    Crizhenrizh14
    Hi! I'm cRiza
    I have a project on how to create an calculator using the visual basic, can you tell me what is the code.. please . Thank you!
  • Nov 26, 2007, 09:27 AM
    ScottGem
    Quote:

    Originally Posted by Criza
    i hav a project on how to create an calculator using the visual basic, can you tell me what is the code..? please . thank you!

    Did you bother reading the replies before posting?
  • Nov 29, 2007, 08:45 PM
    Duane in Japan
    Instead of using int (integer) I have started to use val (value) as it automatically creates memory for complex numbers in case a decimal or other extended math is used.

    I know that in the old days, conserving memory was important and many programmers still code that way and YES it is still important but when speed is not an issue in small programs, In my opinion, val is a good cover all, just in case.

    Look through these sites for your homework needs, you still have to do the research, don't forget to take a Research class when you get to college.

    Visual Basic Explorer - VB Forums - Message Board - ezboard.com
    The Code Project - Free Source Code and Tutorials

    Don't copy, do your own work, tailor it to something simple when you locate a good sample.
  • Dec 29, 2010, 12:45 PM
    fsn0daka
    Option Explicit
    Dim first As String
    Dim second As String
    Dim operation As String
    Dim output As Double

    Private Sub Command1_Click(Index As Integer)
    Text1.Text = Text1.Text + Command1(Index).Caption
    End Sub
    Private Sub Command10_Click()
    If Len(Text1.Text) Then
    Text1.Text = Command10 * Text1.Text
    End If
    End Sub

    Private Sub Command11_Click()
    Text1.Text = " "
    operation = " "
    End Sub
    Private Sub Command12_Click()
    If Len(Text1.Text) Then
    Text1.Text = Left$(Text1.Text, Len(Text1.Text) - 1)
    End If
    End Sub

    Private Sub Command2_Click()
    If InStr(Text1.Text, ".") = 0 Then
    Text1.Text = Text1.Text & "."
    End If
    End Sub
    Private Sub Command3_Click()
    Dim yn As Integer
    yn = MsgBox("Are you sure you want to exit?", vbYesNo + vbQuestion, "Exit")
    If yn = vbYes Then
    Unload Me
    End If
    End Sub

    Private Sub Command4_Click()
    first = Text1.Text
    operation = "+"
    Text1.Text = " "
    End Sub

    Private Sub Command6_Click()
    If Len(Text1.Text) Then
    second = Text1.Text
    Select Case operation
    Case "+"
    output = CDbl(first) + CDbl(second)
    Text1.Text = output
    Case "-"
    output = CDbl(first) - CDbl(second)
    Text1.Text = output
    Case "*"
    output = CDbl(first) * CDbl(second)
    Text1.Text = output
    Case "/"
    If second = 0 Then
    Text1.Text = "ERROR"
    MsgBox "Cannot be Divided by Zero!", vbCritical, "Error"
    If vbOK Then
    Text1.Text = " "
    operation = " "
    End If
    Else
    Text1.Text = first / second
    End If
    End Select
    End If
    End Sub

    Private Sub Command7_Click()
    first = Text1.Text
    operation = "-"
    Text1.Text = " "
    End Sub

    Private Sub Command8_Click()
    first = Text1.Text
    operation = "*"
    Text1.Text = " "
    End Sub

    Private Sub Command9_Click()
    first = Text1.Text
    operation = "/"
    Text1.Text = " "
    End Sub

    Private Sub Timer1_Timer()
    If Label3.Left > -Label3.Width Then
    Label3.Move Label3.Left - 100
    Else
    Label3.Left = Form1.Width
    End If
    End Sub


    TRY THIS ONE!!
  • Dec 29, 2010, 12:47 PM
    fsn0daka
    Thanks 4 help! :))
  • Oct 23, 2011, 02:52 AM
    fazlulbcse
    MAKE A PROJECT OF CALCULATOR IN
    VISUAL BASIC
    First we select the Standard exe item in the view
    project dialog box,
    opening Visual
    Basic itself.
    Then we select the Textbox from the Toolbox and make
    a textbox on the form.
    Then we select the command button from the tool box
    from the tool box we make buttons 0, 1, 2, 3, 4 … 9, +,
    =,-,*, /, clear.
    After these all buttons are made. Then we need the
    buttons to be coded. Thus double click on the button
    numbered “1”, following coding is done:
    Private sub Command 1-Click ()
    Text1.Text = Text 1. Text + “1”
    End Sub
    Double clicking on the Button “2”
    Private sub Command 2-Click ()
    Text1.Text = Text 1. Text + “2”
    End Sub
    Double clicking on the Button “3”
    Private sub Command 3-Click ()
    Text1.Text = Text 1. Text + “3”
    End Sub
    Double clicking on the Button “4”
    Private sub Command 4-Click ()
    Text1.Text = Text 1. Text + “4”
    End Sub
    Double clicking on the Button “5”
    Private sub Command 5-Click ()

    Text1.Text = Text 1. Text + “5”
    End Sub
    Double clicking on the Button “6”
    Private sub Command 6-Click ()
    Text1.Text = Text 1. Text + “6”
    End Sub
    Double clicking on the Button “7”
    Private sub Command 7-Click ()
    Text1.Text = Text 1. Text + “7”
    End Sub
    Double clicking on the Button “8”
    Private sub Command 8-Click ()
    Text1.Text = Text 1. Text + “8”
    End Sub
    Double clicking on the Button “9”
    Private sub Command 9-Click ()
    Text1.Text = Text 1. Text + “9”
    End Sub
    Double clicking on the Button “0”
    Private sub Command 10-Click ()
    Text1.Text = Text 1. Text + “0”
    End Sub
    Double clicking on the Button “.”
    Private sub Command 11-Click ()
    Text1.Text = Text 1. Text + “.”
    End Sub
    Double clicking on the Button “+”
    Private sub Command 12-Click ()
    a= Text 1. Text
    Text1.Text = ”+”
    d=1
    End Sub
    Double clicking on the Button “-”
    Private sub Command 13-Click ()
    a= Text 1. Text
    Text1.Text =”-”
    d=3
    End Sub
    Double clicking on the Button “*”
    Private sub Command 14-Click ()
    a= Text 1. Text
    Text1.Text =”*”
    d=3
    End Sub
    Double clicking on the Button “/”
    Private sub Command 15-Click ()
    a= Text 1. Text
    Text1.Text =”/”
    d=4
    End Sub
    Double clicking on the Button “Square”
    Private sub Command 16-Click ()
    a= Text 1. Text
    Text1.Text =”*”
    C=a*a
    Text1.Text = c
    End Sub
    Double clicking on the Button “Factorial”
    Private sub Command 17-Click ()
    a= Text 1. Text
    Text1.Text =”i”
    e= 1
    for I = s to step-1
    e = e*i
    Text1.Text = e
    End Sub
    Double clicking on the Button “Clear”
    Private sub Command 18-Click ()
    Text1.Text ( )
    End Sub
    Double clicking on the Button “=”
    Private sub Command 19-Click ()
    b = Text1.Text
    Select case d%
    Case 1: c= a + b
    Text1.Text = c
    Case 2: c = a - b
    Text1.Text=c
    Case 3: c= a * b
    Text1.Text = c
    Case 4: c= a / b
    Text1.Text = c
    End Select
    End Sub
    Following figure shows how a
    calculator made in Visual Basic
    Looks :



  • Dec 8, 2011, 06:32 PM
    Rizannylle
    Code for Number button from 0-9:

    Private Sub command1_Click()
    Text1.Text = Text1.Text & "1"
    End Sub

    Private Sub Command10_Click()
    Text1.Text = Text1.Text & "0"
    End Sub

    Private Sub Command2_Click()
    Text1.Text = Text1.Text & "2"
    End Sub

    Private Sub Command3_Click()
    Text1.Text = Text1.Text & "3"
    End Sub

    Private Sub Command4_Click()
    Text1.Text = Text1.Text & "4"
    End Sub

    Private Sub Command5_Click()
    Text1.Text = Text1.Text & "5"
    End Sub

    Private Sub Command6_Click()
    Text1.Text = Text1.Text & "6"
    End Sub

    Private Sub Command7_Click()
    Text1.Text = Text1.Text & "7"
    End Sub

    Private Sub Command8_Click()
    Text1.Text = Text1.Text & "8"
    End Sub

    Private Sub Command9_Click()
    Text1.Text = Text1.Text & "9"
    End Sub

    Code For addition,subtraction.division and Multiplication:

    Private Sub Command13_Click()
    Label1.Caption = Val(Text1.Text) * Val(Text2.Text)
    End Sub

    Private Sub Command14_Click()
    Label1.Caption = Val(Text1.Text) / Val(Text2.Text)
    End Sub

    Private Sub Command11_Click()
    Label1.Caption = Val(Text1.Text) + Val(Text2.Text)
    End Sub

    Private Sub Command12_Click()
    Label1.Caption = Val(Text1.Text) - Val(Text2.Text)
    End Sub

    Exit code for Clear:

    Private Sub Command16_Click()
    Label1.Caption = ""
    Text1.Text = ""
    Text2.Text = ""
    End Sub

    Exit Code:

    Private Sub Command17_Click()
    Unload Me
    End Sub

    ANN...

  • All times are GMT -7. The time now is 07:41 PM.