How to Create a Simple Calculator in Visual Basic 6.0

This wikiHow teaches you how to use Microsoft's Visual Basic 6.0 to create a simple calculator that can add, subtract, multiply, and divide. Keep in mind that Visual Basic 6.0 is no longer used by modern computers, so you'll need to have...

Part 1 of 5:

Creating a New Project

  1. Picture 1 of How to Create a Simple Calculator in Visual Basic 6.0
    Create a new folder for your calculator. To house all of your calculator's necessary files, do the following:
    1. Go to the location in which you want to save your VB6 calculator.
    2. Right-click a blank space.
    3. Select New in the drop-down menu.
    4. Click Folder.
    5. Type in Calculator and press Enter.
  2. Picture 2 of How to Create a Simple Calculator in Visual Basic 6.0
    Open Visual Basic 6. This will bring up the project selection page.
  3. Picture 3 of How to Create a Simple Calculator in Visual Basic 6.0
    Click Standard EXE. It's in the project selection field.
  4. Picture 4 of How to Create a Simple Calculator in Visual Basic 6.0
    Click Open. This is in the bottom-right corner of the window. Doing so creates a new project.
Part 2 of 5:

Creating the Calculator's Input Fields

  1. Picture 5 of How to Create a Simple Calculator in Visual Basic 6.0
    Open the "Text Box" tool. Click the ab button on the left-hand side of the window.
  2. Picture 6 of How to Create a Simple Calculator in Visual Basic 6.0
    Create a text box. Click and drag your mouse down and right to draw an outline of the text box, then release the mouse button when the text box is the proper size.
    1. Ideally, your text box will be significantly longer than it is tall.
  3. Picture 7 of How to Create a Simple Calculator in Visual Basic 6.0
    Copy the text box. Click once the text box to select it, then press Ctrl+C to copy it.
  4. Picture 8 of How to Create a Simple Calculator in Visual Basic 6.0
    Paste in the text box twice. Press Ctrl+V twice to do so. You should see your pasted text boxes appear in the upper-right side of the page.
    1. If prompted to create a new control array after pasting in a text box, click No.
  5. Picture 9 of How to Create a Simple Calculator in Visual Basic 6.0
    Arrange the text boxes in a stack. Click and drag the text box in the top-left side of the page down to the bottom slot, then move the second text box from the top-left side of the page into the middle slot. You should now have a stack of three text boxes.[1]
    1. The order in which you do this is important; if you place the text box you pasted second in the middle, it will cause your coding later to malfunction.
  6. Picture 10 of How to Create a Simple Calculator in Visual Basic 6.0
    Remove the text boxes' default text. To do so:
    1. Click a text box.
    2. Click the text field to the right of the "Text" heading in the "Properties" pane on the right side of the window.
    3. Press Delete.
    4. Repeat with the other two text boxes.
  7. Picture 11 of How to Create a Simple Calculator in Visual Basic 6.0
    Create three label boxes. Click the A button in the left-hand toolbar, then do the following:
    1. Resize the label box to your preferred size.
    2. Select the label box, then copy it.
    3. Paste twice the label box.
  8. Picture 12 of How to Create a Simple Calculator in Visual Basic 6.0
    Place the label boxes to the left of the text boxes. Click and drag each label box to sit to the left of each text box.
  9. Picture 13 of How to Create a Simple Calculator in Visual Basic 6.0
    Edit the top label box's caption. To do so:
    1. Click the top label box.
    2. Click the text box to the right of the "Caption" heading in the "Properties" pane on the right side of the window.
    3. Type in Number 1.
  10. Picture 14 of How to Create a Simple Calculator in Visual Basic 6.0
    Edit the other two label boxes' captions. You'll label them like so:
    1. Click the middle label box, then change its caption to Number 2.
    2. Click the bottom label box, then change its caption to Result.
  11. Picture 15 of How to Create a Simple Calculator in Visual Basic 6.0
    Make the label boxes transparent. This isn't necessary, but it will make your calculator more visually appealing:
    1. Select a label box.
    2. Click the "BackStyle" drop-down box in the "Properties" pane.
    3. Click Transparent in the drop-down menu.
  12. Picture 16 of How to Create a Simple Calculator in Visual Basic 6.0
    Title your calculator. To change the text that appears at the top of the calculator's window when you run it, do the following:
    1. Click a blank space on the form.
    2. Click the "Caption" header's text box in the "Properties" pane.
    3. Type in Simple Calculator (or whatever you want to name the calculator).
Part 3 of 5:

Creating the Calculator's Buttons

  1. Picture 17 of How to Create a Simple Calculator in Visual Basic 6.0
    Click the "Button" tool icon. It's a grey box icon below the ab option in the left-hand toolbar.
  2. Picture 18 of How to Create a Simple Calculator in Visual Basic 6.0
    Create a square button. Click and drag in a diagonal direction until you see a small square outline appear, then release the mouse button. You should see a grey button display on the form.
  3. Picture 19 of How to Create a Simple Calculator in Visual Basic 6.0
    Copy the button. Select the button you just created, then press Ctrl+C.
  4. Picture 20 of How to Create a Simple Calculator in Visual Basic 6.0
    Paste the button three times. Press Ctrl+V three times to do so. This will create a total of four buttons on your project.
    1. You may have to click No when prompted each time after pressing Ctrl+V.
  5. Picture 21 of How to Create a Simple Calculator in Visual Basic 6.0
    Arrange the buttons below the calculator's input fields. Click and drag each button so that you have a row of them below the "Result" text box.
  6. Picture 22 of How to Create a Simple Calculator in Visual Basic 6.0
    Edit the buttons' captions. You'll do this by changing the text for each button's "Caption" heading in the "Properties" pane on the right side of the window:
    1. Click the left-most button, then change its "Caption" text to +.
    2. Click the next button to the right, then change its "Caption" text to -.
    3. Click the next button to the right, then change its "Caption" text to x (or *).
    4. Click the right-most button, then change its "Caption" text to /.
Part 4 of 5:

Adding the Calculator's Code

  1. Picture 23 of How to Create a Simple Calculator in Visual Basic 6.0
    Double-click the + button. Doing so opens a code console.
  2. Picture 24 of How to Create a Simple Calculator in Visual Basic 6.0
    Enter the addition code. Type the following code into the console, directly below the "Private Sub" text and directly above the "End Sub" text.
    Text3.Text=val(Text1)+val(Text2) 
  3. Picture 25 of How to Create a Simple Calculator in Visual Basic 6.0
    Return to the calculator form. Double-click the Form1 option under the "Project1" heading on the right side of the page to do so.
  4. Picture 26 of How to Create a Simple Calculator in Visual Basic 6.0
    Double-click the - button. This will re-open the console.
  5. Picture 27 of How to Create a Simple Calculator in Visual Basic 6.0
    Enter the subtraction code. Type the following into the console:
    Text3.Text=val(Text1)-val(Text2) 
  6. Picture 28 of How to Create a Simple Calculator in Visual Basic 6.0
    Double-click the x or * button. This will re-open the console.
  7. Picture 29 of How to Create a Simple Calculator in Visual Basic 6.0
    Enter the multiplication code. Type the following into the console:
    Text3.Text=val(Text1)*val(Text2) 
  8. Picture 30 of How to Create a Simple Calculator in Visual Basic 6.0
    Double-click the / button. This will re-open the console.
  9. Picture 31 of How to Create a Simple Calculator in Visual Basic 6.0
    Enter the division code. Type the following into the console:
    Text3.Text=val(Text1)/val(Text2) 
Part 5 of 5:

Saving Your Calculator

  1. Picture 32 of How to Create a Simple Calculator in Visual Basic 6.0
    Save your project. Do the following:
    1. Press Ctrl+S.
    2. Select your "Calculator" folder as the save location.
    3. Click Save.
  2. Picture 33 of How to Create a Simple Calculator in Visual Basic 6.0
    Click File. It's in the upper-left side of the window. A drop-down menu will appear.
  3. Picture 34 of How to Create a Simple Calculator in Visual Basic 6.0
    Click Make [name] exe…. This option is in the drop-down menu. Doing so re-opens the "Save As" window.
  4. Picture 35 of How to Create a Simple Calculator in Visual Basic 6.0
    Enter a file name. Type "calculator" or something similar into the "File name" text box.
  5. Picture 36 of How to Create a Simple Calculator in Visual Basic 6.0
    Select your "Calculator" folder. Go to the folder in which you saved your "Calculator" folder, then click the "Calculator" folder to select it.
  6. Picture 37 of How to Create a Simple Calculator in Visual Basic 6.0
    Click OK. It's in the bottom-right corner of the window. This will save your calculator as an executable (EXE) file in the "Calculator" folder.
  7. Picture 38 of How to Create a Simple Calculator in Visual Basic 6.0
    Create a shortcut to your calculator's EXE file. You can create a desktop shortcut to your calculator's EXE file by doing the following:
    1. Open the "Calculator" folder.
    2. Right-click the EXE file.
    3. Select Send to in the drop-down menu.
    4. Click Desktop (create shortcut).
Update 05 March 2020
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile