4 Replies - 594 Views - Last Post: 11 December 2011 - 05:44 PM Rate Topic: -----

#1 SteveG4274  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 18-June 11

Trouble with If Not and Then in lines 45-55

Posted 10 December 2011 - 01:13 PM

I am trying to ask the user the add personaly information in the text boxes. Then based on what the user clicks on the radio button precourse, the application will deterimine what the costs will be for the participant. Here is my code. I am not getting error messages in the objPreCurse or objParticpant class, but in the form on line 47-55 where the If and then statments appear.
Option Strict On

Public Class Form1

    Private Sub radNetwork_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radNetwork.CheckedChanged

    End Sub

    Private Sub lblTitle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblTitle.Click

    End Sub

    Private Sub btnCalculateCosts_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculateCosts.Click

        Dim objParticipant As Participant
        Dim objPreCourse As PreCourse
        Dim InputError As Boolean = False

        'Is participant ID entered properly
        If txtCorporationID.MaskFull = False Then
            MsgBox("Enter your Corporation ID in the Corporation ID Box", , _
                   "Error")
            txtCorporationID.Clear()
            txtCorporationID.Focus()
            InputError = True
            'Is Participant First Name entered correctly
        ElseIf txtFirst.TextLength < 1 Or _
            txtFirst.Text < "A" Then
            MsgBox("Enter your first Name in the Participant ID First Name Box", , "Error")
            txtFirst.Focus()
            txtFirst.Clear()
            InputError = True
            'Is Last Name entered correctly
        ElseIf txtLast.TextLength < 1 Or _
            txtLast.Text < "A" Then
            MsgBox("Enter your last name in the Participant Last Name Box", , "Error")
            txtLast.Clear()
            txtLast.Focus()
        ElseIf Not IsNumeric(txtNumberOfDays.Text) Then
            MsgBox("Enter the days in the Number of Days box", , "Error")
            txtNumberOfDays.Clear()
            txtNumberOfDays.Focus()
            InputError = True
        End If

        'If No input Error, process the registration costs
        If Not InputError Then
            If radPreConference.Checked Then
                objPreCourse = New PreCourse(txtCorporationID.Text, _
                                txtFirst.Text, txtLast.Text, txtNumberOfDays)
                lblCosts.Visible = True
                lblCosts.Text = "Total Conference Costs are: " _
                & (objPreCourse.ComputeCosts()).ToString("C2")
            Else
                objParticipant = New Participant(txtCorporationID.Text, _
                                txtFirst.Text, txtNumberOfDays.Text, )
                lblCosts.Visible = True
                lblCosts.Text = "Total Conference Costs are: " _
                    & (objParticipant.ComputeCosts()).ToString("C2")
            End If
        End If

    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        'This event handler is executed when the user clicks the
        'Clear Form button. It resets all objects on the user interface.

        txtCorporationID.Clear()
        txtFirst.Clear()
        txtLast.Clear()
        radPreConference.Checked = True
        radNetwork.Checked = True

    End Sub

    Private Sub grpCourses_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles grpCourses.Enter

    End Sub

    Private Sub radPreConference_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radPreConference.CheckedChanged
       
    End Sub
End Class


Option Strict On

Public Class Participant

    'Class Variables

    Protected _strCorporationID As String
    Protected _strFirst As String
    Protected _strLast As String
    Protected _intUnits As Integer
    Protected _decCost As Decimal
    Protected _decCostPerUnit As Decimal = 350D

    Dim objParticipantCostFile As ParticipantCostFile

    Sub New(ByVal strCorporationID As String, ByVal strFirst As String, _
            ByVal strLast As String, ByVal intUnits As String)

        'This subprocedure is a constructor for the Participant class. It is called
        'when the object is instantiated with the arguments

        'The following code assigns the arguments to class variables
        _strCorporationID = strCorporationID
        _strFirst = strFirst
        _strLast = strLast
        _intUnits = Convert.ToInt32(intUnits)

    End Sub
    Overridable Function ComputeCosts() As Decimal
        'This function computes the registration costs, writes a record,
        'in the participant costs file, and returns the participant costs

        'Calculate Costs
        _decCost = _intUnits * _decCostPerUnit

        'Writes the participant record
        objParticipantCostFile = New ParticipantCostFile(_strCorporationID, _
                                                         _strFirst, _strLast, _decCost)
        objParticipantCostFile.WriteRecord()

        'Return the calculated cost
        Return _decCost
    End Function
End Class



Option Strict On

Public Class PreCourse
    Inherits Participant

    'Class Variables
    Private _Network As Boolean
    Private _Conquer As Boolean
    Private _Moving As Boolean

    Dim objParticipantCostFile As ParticipantCostFile

    Sub New(ByVal CorporationID As String, ByVal First As String, _
            ByVal Last As String, ByVal Units As String, _
            ByVal Network As Boolean, ByVal Conquer As Boolean, _
            ByVal Moving As Boolean)
        'This subprocedure is a constructor for the Participant Class. It is called when
        'instantiated with arguments

        MyBase.New(CorporationID, First, Last, Units)

        'The follwoing code assigns the arguments to class variables
        _Network = Network
        _Conquer = Conquer
        _Moving = Moving

    End Sub

    Overrides Function ComputeCosts() As Decimal
        'This function computes the registration costs, writes a record
        'in the participant costs file, and returns the registration costs

        'Define variables
        Dim PreCourseCost As Decimal
        Const cdecNetworkCourseCost As Decimal = 675D
        Const cdecConquerCourseCost As Decimal = 675D
        Const cdecMovingCourseCost As Decimal = 675D

        'Calculate the cost
        If _Network Then
            PreCourseCost = cdecNetworkCourseCost
        ElseIf _Conquer Then
            PreCourseCost = cdecConquerCourseCost
        ElseIf _Moving Then
            PreCourseCost = cdecMovingCourseCost
        End If

        _decCost = (_intUnits * _decCostPerUnit) + PreCourseCost

        'Write the participant record
        objParticipantCostFile = New ParticipantCostFile(_strCorporationID, _
                                                         _strFirst, _strLast, _decCost)
        objParticipantCostFile.WriteRecord()

        'Return the calculated cost
        Return _decCost
    End Function
End Class


Public Class ParticipantCostFile

    Private _strCorporationID As String
    Private _strFirst As String
    Private _strLast As String
    Private _decCost As Decimal

    Sub New(ByVal strCorporationID As String, ByVal strFirst As String, ByVal strLast As String, ByVal decCost As Decimal)
        ' TODO: Complete member initialization 
        _strCorporationID = strCorporationID
        _strFirst = strFirst
        _strLast = strLast
        _decCost = decCost
    End Sub

    Sub WriteRecord()
        'This subprocedure opens the ParticipantsCost output text file and then
        'writes a record in the comma-delimited file

        Dim strNameandLocationOfFile As String = "C:\ParticipantCost.txt"

        Try
            Dim objWriter As IO.StreamWriter = _
                IO.File.AppendText(strNameandLocationOfFile)

            objWriter.Write(_strCorporationID & ",")
            objWriter.Write(_strFirst & ",")
            objWriter.Write(_strLast & ",")
            objWriter.WriteLine(_decCost)
            objWriter.Close()

        Catch ex As Exception
            MsgBox("No device available - program aborted", , "Error")
            Application.Exit()

        End Try
    End Sub

End Class

This post has been edited by modi123_1: 10 December 2011 - 01:19 PM
Reason for edit:: please use the code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Trouble with If Not and Then in lines 45-55

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9571
  • View blog
  • Posts: 36,243
  • Joined: 12-June 08

Re: Trouble with If Not and Then in lines 45-55

Posted 10 December 2011 - 01:20 PM

What's the error?
Was This Post Helpful? 0
  • +
  • -

#3 SteveG4274  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 18-June 11

Re: Trouble with If Not and Then in lines 45-55

Posted 10 December 2011 - 01:30 PM

Error 1 Argument not specified for parameter 'Conquer' of 'Public Sub New(CorporationID As String, First As String, Last As String, Units As String, Network As Boolean, Conquer As Boolean, Moving As Boolean)'. C:\Users\Steve\documents\visual studio 2010\Projects\Network Association\Network Association\Form1.vb 49 32 Network Association

Error 2 Argument not specified for parameter 'Moving' of 'Public Sub New(CorporationID As String, First As String, Last As String, Units As String, Network As Boolean, Conquer As Boolean, Moving As Boolean)'. C:\Users\Steve\documents\visual studio 2010\Projects\Network Association\Network Association\Form1.vb 49 32 Network Association

Error 3 Argument not specified for parameter 'Network' of 'Public Sub New(CorporationID As String, First As String, Last As String, Units As String, Network As Boolean, Conquer As Boolean, Moving As Boolean)'. C:\Users\Steve\documents\visual studio 2010\Projects\Network Association\Network Association\Form1.vb 49 32 Network Association

Error 4 Value of type 'System.Windows.Forms.TextBox' cannot be converted to 'String'. C:\Users\Steve\documents\visual studio 2010\Projects\Network Association\Network Association\Form1.vb 50 62 Network Association

Error 5 Argument not specified for parameter 'intUnits' of 'Public Sub New(strCorporationID As String, strFirst As String, strLast As String, intUnits As String)'. C:\Users\Steve\documents\visual studio 2010\Projects\Network Association\Network Association\Form1.vb 55 34 Network Association
Was This Post Helpful? 0
  • +
  • -

#4 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Trouble with If Not and Then in lines 45-55

Posted 11 December 2011 - 04:51 PM

You aren't specifying the parameters for the Boolean Network, Conquer and the String IntUnits - network could be true, conquer may be false and intUnits may equal "chicken". You aren't giving these variables a value.
Was This Post Helpful? 0
  • +
  • -

#5 SteveG4274  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 18-June 11

Re: Trouble with If Not and Then in lines 45-55

Posted 11 December 2011 - 05:44 PM

I figured it out on my own this afternoon. Thanks for anyone who responded and tried to help.

Thanks.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1