Results 1 to 3 of 3

Thread: [VS2008-][.Net 3.5-]A Real Beginners Guide to makeing a Simple Calculator

Threaded View

  1. #1

    Thread Starter
    Addicted Member spyk3's Avatar
    Join Date
    Apr 2009
    Location
    Dothan, AL
    Posts
    218

    [VS2008-][.Net 3.5-]A Real Beginners Guide to makeing a Simple Calculator

    This simple tutorial was just made to help some friends with a problem they were having in understanding basic principles of vb coding. Due to a lack of explanation, this basic calculator (presented in Ch.3 of their beginner book) was really giving them trouble. So I created one from scratch for them, that is a little bit more complicated, but only to show off many of the basics of coding in VB.
    Keep in mind, this is a "Real Beginner's Guide", so any critiquing should only relate to such.

    First, start a simple Vb project
    On your main form (i renamed mine frmMain) place the follwing: (all can be drag and dropped from toolbox)
    • Textbox named txtInput
    • Label named lblResult
    • RichTextbox named rtxShowWork
    • 1 Button named btnClear
    • 4 Buttons for Add, Subtract, Multiply, and Divide (name each as such with "btn" at beginning of the name)


    After you have some fun playing with the controls and setting them to look like however you want, right click 'frmMain' in the Solution Explorer
    Then select 'View Code' (NOT .designer code!)
    Select all automatically created text (press Ctrl+A) and then press your 'Del' key to delete it all
    Finally, start coding by following the code below, you don't need to include the comments, of course, which is every line that begins with a single quote.
    However, in order for the program to work without errors, you will need every single line of actual code.
    If you are a real beginner, please don't skip a step and get to know some of the easiest uses of Basic coding.

    EZ Calc Code Code:
    1. ''' <summary>
    2. ''' EZ Calc Tutorial
    3. ''' JD McKinstry
    4. ''' First, it should be noted, as you become a
    5. ''' more experienced coder, you will find this tutorial
    6. ''' to contain very simple, non-standard practices. The
    7. ''' purpose of this is not to teach you to be company ready,
    8. ''' it is simply to teach some very basic examples of the
    9. ''' Basic Coding Language. Should you find this tutorial
    10. ''' beneath your skillset, then I advise you check out MicroSoft's
    11. ''' Developer Studio online and look up the Intermidiate Tutorials.
    12. ''' </summary>
    13. Public Class frmMain
    14.  
    15.     ' This is simply the establishment of a Region
    16.     ' Regions are useful in dividing up sections of code into similar catagories
    17.     ' This is not extremely important for now, but helps to break down the compacted view,
    18.     ' making it easier to see all the items in your code.
    19. #Region "   Vars/Properties     "
    20.  
    21.     ''' <summary>
    22.     ''' First things first, to do simple XML Comments like this one,
    23.     ''' Simply place cursor 1 line above the method, property, or variable
    24.     ''' you wish to document/comment on. Then simply type 3 single quotes;
    25.     ''' such as the ones you see at the beggining of each line here.
    26.     ''' In Visual Studio, this will automatically create a simple XML
    27.     ''' Document/Comment layout!
    28.     ''' This is useful later, when looking at your Object Library, as each
    29.     ''' section in these comments is shown in an easy to read manner.
    30.     ''' </summary>
    31.     ''' <remarks>Notice, it doesn't add all featues, such as the 'example' feature seen below!</remarks>
    32.     ''' <example>ezXML_Documentation = "This is a String"</example>
    33.     Private ezXML_Documentation As String
    34.  
    35.     ''' <summary>
    36.     ''' Establish Enumerable for the 4 basic calculations.
    37.     ''' This will later be used to determine which function
    38.     ''' to use as your program "calculates"
    39.     ''' </summary>
    40.     Enum calc
    41.         Add
    42.         Subtract
    43.         Multiply
    44.         Divide
    45.     End Enum
    46.  
    47.     ''' <summary>
    48.     ''' This is a pre-.Net 4.0 standard for establishing a
    49.     ''' "root variable" for later established properties.
    50.     ''' This gives the Properties a variable to use for
    51.     ''' interaction.
    52.     ''' </summary>
    53.     Private _result As Double
    54.     Private _calcValue As calc
    55.  
    56.     ''' <summary>
    57.     ''' These are both public properties which will be
    58.     ''' used when 'doing the work' behind this calc program.
    59.     ''' This first property is simply used to maintain the value
    60.     ''' of our final result for each calcullation.
    61.     ''' </summary>
    62.     Public Property result() As Double
    63.         Get
    64.             Return _result
    65.         End Get
    66.         Set(ByVal value As Double)
    67.             _result = value
    68.         End Set
    69.     End Property
    70.     ''' <summary>
    71.     ''' This second property will be used to store the present
    72.     ''' value for the function being preformed. Remember our enum?
    73.     ''' As you notice this property is an establishment of that enum,
    74.     ''' meaning it can hold one value selected from that enum.
    75.     ''' </summary>
    76.     ''' <value></value>
    77.     ''' <returns></returns>
    78.     ''' <remarks></remarks>
    79.     Property calcValue() As calc
    80.         Get
    81.             Return _calcValue
    82.         End Get
    83.         Set(ByVal value As calc)
    84.             _calcValue = value
    85.         End Set
    86.     End Property
    87.  
    88. #End Region
    Last edited by spyk3; Jan 1st, 2011 at 02:54 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width