Results 1 to 40 of 48

Thread: [RESOLVED] Advice needed for a message box if not enough data entered.

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2012
    Posts
    56

    Resolved [RESOLVED] Advice needed for a message box if not enough data entered.

    Hi all,

    I have created a program that solves the right-angled triangle by just needing to input two known quantities. I have adapted this code from some I found on another website, it never actually worked, so I spent two weeks figuring out how to get it to work. I have finally succeeded, what I would like to do is display a message box if the user has not entered the required two inputs and presses the 'Calculate' button (see image). I just want it to say "At least two known quantities are required".

    I have some code that clears all the text boxes so you can enter new data, but I have tried countless times to find a way of coding so the message box appears.

    I would appreciate it if someone could steer me in the right direction.

    Many thanks,

    Steve.

    Code:
    Imports System.String
    Imports System.Math
    Public Class Form1
        Dim angleA As Single = 90
        Dim angleB As Single
        Dim angleC As Single
        Dim sidea As Single
        Dim sideb As Single
        Dim sidec As Single
    
    
    #Region " If value is Null "
        Public Function isItNullString(ByVal value) As Boolean
            If value = "" Then
                Return True
            Else
                Return False
            End If
        End Function
    #End Region
    
    #Region " To find one side if two sides known - Pythagoras Theorem "
        Public Sub PythagoreanTheorem()
    
            If sidec <> 0 And sidea <> 0 And sideb = 0 Then
                sideb = Math.Sqrt((sidec * sidec) - (sidea * sidea))
                TextBoxSideb.Text = sideb
    
            ElseIf sideb <> 0 And sidea <> 0 And sidec = 0 Then
                sidec = Math.Sqrt((sideb * sideb) + (sidea * sidea))
                TextBoxSidec.Text = sidec
    
            ElseIf sidec <> 0 And sideb <> 0 And sidea = 0 Then
                sidea = Math.Sqrt((sidec * sidec) - (sideb * sideb))
                TextBoxSidea.Text = sidea
            End If
        End Sub
    #End Region
    
    #Region " Find Angle B or Angle C "
        Public Sub angleSums()
    
            If angleC = 0 And angleB <> 0 Then
                angleC = 180 - angleA - angleB
                TextBoxAngleC.Text = angleC
            End If
    
            If angleB = 0 And angleC <> 0 Then
                angleB = 180 - angleA - angleC
                TextBoxAngleB.Text = angleB
            End If
        End Sub
    #End Region
    
    #Region " Angle B and one side known "
        Public Sub angleBasWorkingAngle()
    
            'Angle B and side b known, find side c
            If angleB <> 0 And sideb <> 0 Then
                sidec = sideb / Sin(degreesToRadians(angleB))
                TextBoxSidec.Text = sidec
            End If
    
            'Angle B and side a known, find side b
            If angleB <> 0 And sidea <> 0 Then
                sideb = sidea * Tan(degreesToRadians(angleB))
                TextBoxSideb.Text = sideb
            End If
    
            'Angle B and side b known, find side a
            If angleB <> 0 And sideb <> 0 Then
                sidea = sideb / Tan(degreesToRadians(angleB))
                TextBoxSidea.Text = sidea
            End If
    
            'Angle B and side b known, find side a
            If angleB <> 0 And sidec <> 0 Then
                sidea = sidec * Cos(degreesToRadians(angleB))
                TextBoxSidea.Text = sidea
            End If
    
        End Sub
    #End Region
    
    #Region " Find Angle C "
        Public Sub findangleC()
    
            If angleC = 0 Then
                'cos
                angleC = radiansToDegrees(Acos(sideb / sidec))
                TextBoxAngleC.Text = angleC
            End If
    
        End Sub
    #End Region
    
    #Region " Feed Values "
    
        Public Sub feedValues()
    
            If Not isItNullString(TextBoxSideb.Text) Then
                sideb = TextBoxSideb.Text
            Else
                sideb = 0
            End If
    
            If Not isItNullString(TextBoxSidea.Text) Then
                sidea = TextBoxSidea.Text
            Else
                sidea = 0
            End If
    
            If Not isItNullString(TextBoxSidec.Text) Then
                sidec = TextBoxSidec.Text
            Else
                sidec = 0
            End If
    
            If Not isItNullString(TextBoxAngleC.Text) Then
                angleC = TextBoxAngleC.Text
            Else
                angleC = 0
            End If
    
            If Not isItNullString(TextBoxAngleB.Text) Then
                angleB = TextBoxAngleB.Text
            Else
                angleB = 0
            End If
        End Sub
    #End Region
    
    #Region " Convert Degrees to Radians "
        Public Function degreesToRadians(ByVal degrees As Double) As Double
            Dim radians As Double
            radians = (Math.PI * degrees) / 180
            Return radians
        End Function
    #End Region
    
    #Region " Convert Radians to Degrees "
        Public Function radiansToDegrees(ByVal radians As Double) As Double
            Dim degrees As Double
            degrees = radians * (180 / Math.PI)
            Return degrees
        End Function
    #End Region
    
    #Region " Calculate all Data "
        Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
            For aaa As Integer = 0 To 2 'I just repeated this 6 times because I have a lot of processing power
                'you can do it twice.
    
                feedValues()
    
                PythagoreanTheorem()
    
                angleSums()
    
                angleBasWorkingAngle()
    
                findangleC()
    
            Next
            
        End Sub
    #End Region
    
    #Region " Clear all input boxes "
        Public Sub ClearTextBox(ByVal root As Control)
            For Each ctrl As Control In root.Controls
                ClearTextBox(ctrl)
                If TypeOf ctrl Is TextBox Then
                    CType(ctrl, TextBox).Text = String.Empty
                End If
            Next ctrl
        End Sub
    #End Region
    
    #Region " Button to clear all Input boxes "
        Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
            ClearTextBox(Me)
        End Sub
    #End Region
    
    #Region " Button to Exit the program "
        Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
            Me.Close()
        End Sub
    #End Region
    
    End Class
    Attached Images Attached Images  
    Last edited by SteveHeather; Feb 16th, 2012 at 06:37 AM.

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