Better way to do it?

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

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
 
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.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

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 807,865 other people just like you!

Latest posts

Staff online

Top