#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    4
    Rep Power
    0

    Smile Making Pythagoras Theorem App using VB .NET


    I just wanna share my apps in this forum and hopping for any feedback to help me improve on my programming skills. I had made an application on "Pythagoras Theorem" so to make it easier for those who having trouble finding the answer for your Pythagoras Theorem questions. Have fun Playing with it..

    Things Needed:

    6 Labels
    3 buttons
    2 text boxes


    Here are the CODE:

    Code:
    Function Pythagoras_Theorem(A As Double, B As Double, C As Double) As Double
     
          PythagorasTheorem = A ^ 2 + B ^ 2 = C ^ 2
     
    End Function
    
    Private Sub Command1_Click()
    Label6 = (Text1.Text ^ 2) + (Text2.Text ^ 2)
    Label6.Caption = Val(Label6 / 2)
    End Sub
    
    Private Sub Command2_Click()
    Form_Load
    
    End Sub
    
    Private Sub Command3_Click()
    End
    
    End Sub
    
    Private Sub Form_Load()
    Text1.Text = ""
    Text2.Text = ""
    Label6.Caption = ""
    
    End Sub
    
    Private Sub Label6_Click()
    
    End Sub
    Here are the attributes:

    Begin VB.Form Form1
    Caption = "Pythagoras Theorem"
    ClientHeight = 2955
    ClientLeft = 3360
    ClientTop = 2940
    ClientWidth = 3840
    LinkTopic = "Form1"
    ScaleHeight = 2955
    ScaleWidth = 3840

    Begin VB.CommandButton Command3
    Caption = "END"
    BeginProperty Font
    Name = "MS Sans Serif"
    Size = 8.25
    Charset = 0
    Weight = 700
    Underline = 0 'False
    Italic = 0 'False
    Strikethrough = 0 'False
    EndProperty
    Height = 375
    Left = 2520
    TabIndex = 10
    Top = 1800
    Width = 975
    End

    Begin VB.CommandButton Command2
    Caption = "Reset"
    BeginProperty Font
    Name = "MS Sans Serif"
    Size = 8.25
    Charset = 0
    Weight = 700
    Underline = 0 'False
    Italic = 0 'False
    Strikethrough = 0 'False
    EndProperty
    Height = 375
    Left = 1440
    TabIndex = 9
    Top = 1800
    Width = 975
    End

    Begin VB.CommandButton Command1
    Caption = "Calculate"
    BeginProperty Font
    Name = "MS Sans Serif"
    Size = 8.25
    Charset = 0
    Weight = 700
    Underline = 0 'False
    Italic = 0 'False
    Strikethrough = 0 'False
    EndProperty
    Height = 375
    Left = 360
    TabIndex = 8
    Top = 1800
    Width = 975
    End

    Begin VB.TextBox Text2
    Alignment = 2 'Center
    BeginProperty Font
    Name = "MS Sans Serif"
    Size = 9.75
    Charset = 0
    Weight = 700
    Underline = 0 'False
    Italic = 0 'False
    Strikethrough = 0 'False
    EndProperty
    Height = 375
    Left = 1440
    TabIndex = 1
    Top = 600
    Width = 375
    End

    Begin VB.TextBox Text1
    Alignment = 2 'Center
    BeginProperty Font
    Name = "MS Sans Serif"
    Size = 9.75
    Charset = 0
    Weight = 700
    Underline = 0 'False
    Italic = 0 'False
    Strikethrough = 0 'False
    EndProperty
    Height = 375
    Left = 720
    TabIndex = 0
    Top = 600
    Width = 375
    End

    Begin VB.Label Label6
    Alignment = 2 'Center
    BorderStyle = 1 'Fixed Single
    BeginProperty Font
    Name = "MS Sans Serif"
    Size = 9.75
    Charset = 0
    Weight = 700
    Underline = 0 'False
    Italic = 0 'False
    Strikethrough = 0 'False
    EndProperty
    Height = 375
    Left = 1440
    TabIndex = 7
    Top = 1200
    Width = 1695
    End

    Begin VB.Label Label5
    Alignment = 2 'Center
    BorderStyle = 1 'Fixed Single
    Caption = "C ="
    BeginProperty Font
    Name = "MS Sans Serif"
    Size = 9.75
    Charset = 0
    Weight = 700
    Underline = 0 'False
    Italic = 0 'False
    Strikethrough = 0 'False
    EndProperty
    Height = 375
    Left = 720
    TabIndex = 6
    Top = 1200
    Width = 615
    End

    Begin VB.Label Label4
    Alignment = 2 'Center
    BorderStyle = 1 'Fixed Single
    Caption = "Pythagoras Theorem"
    BeginProperty Font
    Name = "MS Sans Serif"
    Size = 9.75
    Charset = 0
    Weight = 700
    Underline = 0 'False
    Italic = 0 'False
    Strikethrough = 0 'False
    EndProperty
    Height = 375
    Left = 600
    TabIndex = 5
    Top = 120
    Width = 2655
    End

    Begin VB.Label Label3
    Alignment = 2 'Center
    BorderStyle = 1 'Fixed Single
    Caption = "= C^2"
    BeginProperty Font
    Name = "MS Sans Serif"
    Size = 12
    Charset = 0
    Weight = 700
    Underline = 0 'False
    Italic = 0 'False
    Strikethrough = 0 'False
    EndProperty
    Height = 375
    Left = 2160
    TabIndex = 4
    Top = 600
    Width = 975
    End

    Begin VB.Label Label2
    Alignment = 2 'Center
    BorderStyle = 1 'Fixed Single
    Caption = "^2"
    BeginProperty Font
    Name = "MS Sans Serif"
    Size = 12
    Charset = 0
    Weight = 700
    Underline = 0 'False
    Italic = 0 'False
    Strikethrough = 0 'False
    EndProperty
    Height = 375
    Left = 1800
    TabIndex = 3
    Top = 600
    Width = 375
    End

    Begin VB.Label Label1
    Alignment = 2 'Center
    BorderStyle = 1 'Fixed Single
    Caption = "^2"
    BeginProperty Font
    Name = "MS Sans Serif"
    Size = 12
    Charset = 0
    Weight = 700
    Underline = 0 'False
    Italic = 0 'False
    Strikethrough = 0 'False
    EndProperty
    Height = 375
    Left = 1080
    TabIndex = 2
    Top = 600
    Width = 375
    End

    End

    Attribute VB_Name = "Form1"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
  2. #2
  3. I <3 ASCII
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Aug 2003
    Posts
    2,400
    Rep Power
    1233
    Originally Posted by nightyeye
    I just wanna share my apps in this forum and hopping for any feedback to help me improve on my programming skills. I had made an application on "Pythagoras Theorem" so to make it easier for those who having trouble finding the answer for your Pythagoras Theorem questions. Have fun Playing with it..
    I don't know how much success you'll have getting code reviews on a site like this, but since I'm waiting for a code review of my own I figured I'd give it a swing:

    Function Pythagoras_Theorem(A As Double, B As Double, C As Double) As Double

    PythagorasTheorem = A ^ 2 + B ^ 2 = C ^ 2

    End Function
    This function isn't returning anything. Additionally the PythagorasTheorem variable (assuming it's declared elsewhere won't be a 'double' value it will be a boolean. With the equals sign between the B and the C clauses you're effictively asking if they're equal.


    [*] Readability will be greatly enhanced if you name your textboxes and buttons instead of text1 perhaps 'inputVariableA'
    [*] Remove the empty subs and functions. Unattach any form properties from them if it causes them to not compile.
    [*] Consider commenting your functions to aide readability, even if you're just learning. It will help you down the line if you ever come to revisit this. A lot of times when learning something you use it once, then tend to forget about it. If you comment your code you'll be able to pick it up quicker on the bounce.

    -MBirchmeier

IMN logo majestic logo threadwatch logo seochat tools logo