PDF download Download Article PDF download Download Article

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 it installed and running on your computer in order to be able to use it.

Part 1
Part 1 of 5:

Creating a New Project

PDF download Download Article
  1. To house all of your calculator's necessary files, do the following:
    • Go to the location in which you want to save your VB6 calculator.
    • Right-click a blank space.
    • Select New in the drop-down menu.
    • Click Folder .
    • Type in Calculator and press Enter .
  2. This will bring up the project selection page.
    Advertisement
  3. It's in the project selection field.
  4. This is in the bottom-right corner of the window. Doing so creates a new project.
  5. Advertisement
Part 2
Part 2 of 5:

Creating the Calculator's Input Fields

PDF download Download Article
  1. Click the ab button on the left-hand side of the window.
  2. 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.
    • Ideally, your text box will be significantly longer than it is tall.
  3. Click once the text box to select it, then press Ctrl + C to copy it.
  4. Press Ctrl + V twice to do so. You should see your pasted text boxes appear in the upper-right side of the page.
    • If prompted to create a new control array after pasting in a text box, click No .
  5. 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]
    • 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. To do so:
    • Click a text box.
    • Click the text field to the right of the "Text" heading in the "Properties" pane on the right side of the window.
    • Press Delete .
    • Repeat with the other two text boxes.
  7. Click the A button in the left-hand toolbar, then do the following:
    • Resize the label box to your preferred size.
    • Select the label box, then copy it.
    • Paste twice the label box.
  8. Click and drag each label box to sit to the left of each text box.
  9. To do so:
    • Click the top label box.
    • Click the text box to the right of the "Caption" heading in the "Properties" pane on the right side of the window.
    • Type in Number 1 .
  10. You'll label them like so:
    • Click the middle label box, then change its caption to Number 2 .
    • Click the bottom label box, then change its caption to Result .
  11. This isn't necessary, but it will make your calculator more visually appealing:
    • Select a label box.
    • Click the "BackStyle" drop-down box in the "Properties" pane.
    • Click Transparent in the drop-down menu.
  12. To change the text that appears at the top of the calculator's window when you run it, do the following:
    • Click a blank space on the form.
    • Click the "Caption" header's text box in the "Properties" pane.
    • Type in Simple Calculator (or whatever you want to name the calculator).
  13. Advertisement
Part 3
Part 3 of 5:

Creating the Calculator's Buttons

PDF download Download Article
  1. It's a grey box icon below the ab option in the left-hand toolbar.
  2. 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. Select the button you just created, then press Ctrl + C .
  4. Press Ctrl + V three times to do so. This will create a total of four buttons on your project.
    • You may have to click No when prompted each time after pressing Ctrl + V .
  5. Click and drag each button so that you have a row of them below the "Result" text box.
  6. 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:
    • Click the left-most button, then change its "Caption" text to + .
    • Click the next button to the right, then change its "Caption" text to - .
    • Click the next button to the right, then change its "Caption" text to x (or * ).
    • Click the right-most button, then change its "Caption" text to / .
  7. Advertisement
Part 4
Part 4 of 5:

Adding the Calculator's Code

PDF download Download Article
  1. Doing so opens a code console.
  2. 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. Double-click the Form1 option under the "Project1" heading on the right side of the page to do so.
  4. This will re-open the console.
  5. Type the following into the console:
     Text3 
     . 
     Text 
     = 
     val 
     ( 
     Text1 
     ) 
     - 
     val 
     ( 
     Text2 
     ) 
    
  6. This will re-open the console.
  7. Type the following into the console:
     Text3 
     . 
     Text 
     = 
     val 
     ( 
     Text1 
     ) 
     * 
     val 
     ( 
     Text2 
     ) 
    
  8. This will re-open the console.
  9. Type the following into the console:
     Text3 
     . 
     Text 
     = 
     val 
     ( 
     Text1 
     ) 
     / 
     val 
     ( 
     Text2 
     ) 
    
  10. Advertisement
Part 5
Part 5 of 5:

Saving Your Calculator

PDF download Download Article
  1. Do the following:
    • Press Ctrl + S .
    • Select your "Calculator" folder as the save location.
    • Click Save .
  2. It's in the upper-left side of the window. A drop-down menu will appear.
  3. This option is in the drop-down menu. Doing so re-opens the "Save As" window.
  4. Type "calculator" or something similar into the "File name" text box.
  5. Go to the folder in which you saved your "Calculator" folder, then click the "Calculator" folder to select it.
  6. 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. You can create a desktop shortcut to your calculator's EXE file by doing the following:
    • Open the "Calculator" folder.
    • Right-click the EXE file.
    • Select Send to in the drop-down menu.
    • Click Desktop (create shortcut) .
  8. Advertisement

Community Q&A

Search
Add New Question
  • Question
    How do I code a calculator in VB?
    Community Answer
    Start by designing the interface of your calculator, then you start your coding by declaring the values you are using, such as a,b,c, for each command you have open in your interface. a=val(Text1.Text) b=val(Text2.Text) c=a+b Text3.Text=c a= the value you enter in text1(text box) b= the value you enter in text2(text box) c= the label to display your answer
  • Question
    How can I become an expert in programming?
    Community Answer
    Practice as much as possible and always challenge yourself to learn more and more complex things.
  • Question
    Any number divide by 0 is = 1? How I can fix that?
    Community Answer
    You might want to code in an error message because officially, dividing by 0 is UNDEFINED.
See more answers
Ask a Question
      Advertisement

      Tips

      • You can change your calculator's background color by clicking a blank space on the form, clicking the "BackColor" drop-down box (in the "Properties" pane), and clicking the color you want to use.
      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Name
      Please provide your name and last initial
      Thanks for submitting a tip for review!
      Advertisement

      Warnings

      • Visual Basic 6.0 is no longer updated on modern computers, so you may encounter errors if attempting to install or use it on a 64-bit system (e.g., Windows 10).
      Advertisement

      About This Article

      Thanks to all authors for creating a page that has been read 760,569 times.

      Reader Success Stories

      • Sinikiwe Ngwenya

        Jun 23, 2016

        "It showed me specific steps and codes for designing a calculator. Really great stuff."
      Share your story

      Is this article up to date?

      Advertisement