1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Better way to do it?

Discussion in 'Software Development' started by dudeking, Nov 3, 2007.

Thread Status:
Not open for further replies.
  1. dudeking

    dudeking Thread Starter

    Joined:
    Feb 7, 2007
    Messages:
    483
    Code:
    Public Class frmCalculator
        Dim d1 As Double
        Dim d2 As Double
        Dim dans As Double
        Dim sopp As String
    
        Private Sub butGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butGo.Click
            If IsNumeric(txt1.Text) = True Then
                If IsNumeric(txt2.Text) = True Then
                    If Double.Parse(txt1.Text) > 10000 Then
                        lblAns.Text = "Numbers must be between " & vbNewLine & " -10000 and +10000"
                        lblAns.Visible = True
                    ElseIf Double.Parse(txt1.Text) < -10000 Then
                        lblAns.Text = "Numbers must be between " & vbNewLine & " -10000 and +10000"
                        lblAns.Visible = True
                    ElseIf Double.Parse(txt2.Text) > 10000 Then
                        lblAns.Text = "Numbers must be between " & vbNewLine & " -10000 and +10000"
                        lblAns.Visible = True
                    ElseIf Double.Parse(txt2.Text) < -10000 Then
                        lblAns.Text = "Numbers must be between " & vbNewLine & " -10000 and +10000"
                        lblAns.Visible = True
                    Else
                        d1 = Double.Parse(txt1.Text)
                        d2 = Double.Parse(txt2.Text)
                        If radAdd.Checked = True Then
                            dans = d1 + d2
                            sopp = " + "
                        ElseIf RadTake.Checked = True Then
                            dans = d1 - d2
                            sopp = " - "
                        ElseIf radDev.Checked = True Then
                            dans = d1 / d2
                            sopp = " / "
                        ElseIf radTimes.Checked = True Then
                            dans = d1 * d2
                            sopp = " * "
                        End If
                        lblAns.Text = d1 & sopp & d2 & " = " & dans
                        lblAns.Visible = True
                    End If
                Else
                    lblAns.Text = "Please only enter numbers " & vbNewLine & " and don't leave fields blank."
                    lblAns.Visible = True
                End If
            Else
                lblAns.Text = "Please only enter numbers " & vbNewLine & " and don't leave fields blank."
                lblAns.Visible = True
            End If
        End Sub
    
        Private Sub radAdd_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radAdd.CheckedChanged
            butGo.Enabled = True
            lblOperator.Text = "+"
            lblOperator.Visible = True
        End Sub
    
        Private Sub RadTake_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadTake.CheckedChanged
            butGo.Enabled = True
            lblOperator.Text = "-"
            lblOperator.Visible = True
        End Sub
    
        Private Sub radDev_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radDev.CheckedChanged
            butGo.Enabled = True
            lblOperator.Text = "/"
            lblOperator.Visible = True
        End Sub
    
        Private Sub radTimes_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radTimes.CheckedChanged
            butGo.Enabled = True
            lblOperator.Text = "*"
            lblOperator.Visible = True
        End Sub
    End Class
    www.dudeking.co.uk/Calculator.zip

    Just have a play tell me what needs changing. I know its basic and stuff but its only for a college assignment.

    Thank you so much for any help :D:D
     
  2. Nok1

    Nok1

    Joined:
    Feb 15, 2004
    Messages:
    826
    in VB for college? really?

    my help would be to tell you to write helper methods and learn to use "OR" when evaluating expressions.
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/647229

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice