There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer audio black screen boot bsod computer connection crash css dell display driver drivers email error ethernet excel explorer firefox firefox 3 game hard drive internet internet explorer itunes laptop lcd linux malware network networking nvidia outlook outlook 2003 outlook express partition printer problem router slow software sound trojan usb video virus vista windows windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Better way to do it?


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
dudeking's Avatar
Computer Specs
Senior Member with 350 posts.
 
Join Date: Feb 2007
Location: UK, Midlands
Experience: I'm Pro...
03-Nov-2007, 07:50 AM #1
Better way to do it?
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
Nok1's Avatar
Senior Member with 825 posts.
 
Join Date: Feb 2004
Experience: Smart Enough To Help You
06-Nov-2007, 04:10 AM #2
in VB for college? really?

my help would be to tell you to write helper methods and learn to use "OR" when evaluating expressions.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 12:04 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.