How do I handle this

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian Shafer

    How do I handle this

    i have
    Public Function ShowMyDate(ByVa l dtmDate As Date, ByVal bytDate As Short) As
    String

    I get an error if the combobox is "". Which will lead me into the next
    question

    Me.Label7.Text = i.ShowMyDate(Da te.Today(), Me.ComboBox2.Te xt) in a form

    Where can i find info on custom errors?

    Brian

  • Chris Dunaway

    #2
    Re: How do I handle this

    Brian Shafer wrote:
    I get an error if the combobox is "". Which will lead me into the next
    question
    Are we supposed to guess what the error is? Inside your method, you
    will have to check that the arguments supplied are not blank or null
    (whichever is appropriate for your case).
    >
    Where can i find info on custom errors?
    >
    Generally speaking, you would create a class derived from
    ApplicationExce ption and then throw a new instance of that class when
    needed.

    Comment

    • tomb

      #3
      Re: How do I handle this

      Brian Shafer wrote:
      >i have
      >Public Function ShowMyDate(ByVa l dtmDate As Date, ByVal bytDate As Short) As
      >String
      >
      >I get an error if the combobox is "". Which will lead me into the next
      >question
      >
      >Me.Label7.Te xt = i.ShowMyDate(Da te.Today(), Me.ComboBox2.Te xt) in a form
      >
      >Where can i find info on custom errors?
      >
      >Brian
      >
      >
      >
      It would help if we knew what your function is doing, and why the second
      parameter is a short, and what the error is.

      T

      Comment

      • Samuel Shulman

        #4
        Re: How do I handle this


        Why can you not check that value of the combo is not ""

        Generally if you add Try, Catch block you can get error info

        hth,
        Samuel

        "Brian Shafer" <BrianShafer@di scussions.micro soft.comwrote in message
        news:43012E04-283B-4FC9-8F3B-E545ABBC59AD@mi crosoft.com...
        >i have
        Public Function ShowMyDate(ByVa l dtmDate As Date, ByVal bytDate As Short)
        As
        String
        >
        I get an error if the combobox is "". Which will lead me into the next
        question
        >
        Me.Label7.Text = i.ShowMyDate(Da te.Today(), Me.ComboBox2.Te xt) in a form
        >
        Where can i find info on custom errors?
        >
        Brian
        >

        Comment

        • Jim Wooley

          #5
          Re: How do I handle this

          Brian Shafer wrote:
          Generally speaking, you would create a class derived from
          ApplicationExce ption and then throw a new instance of that class when
          needed.
          MSFT has changed the recommendation on deriving from ApplicationExce ption
          and now recommend deriving from Exception and NOT using ApplicationExce ption.
          See http://blogs.msdn.com/kcwalina/archi...23/644822.aspx.

          Jim Wooley



          Comment

          • Jim Wooley

            #6
            Re: How do I handle this

            i have
            Public Function ShowMyDate(ByVa l dtmDate As Date, ByVal bytDate As
            Short) As
            String
            I get an error if the combobox is "". Which will lead me into the
            next question
            >
            Me.Label7.Text = i.ShowMyDate(Da te.Today(), Me.ComboBox2.Te xt) in a
            form
            Your ShowMyDate function is requiring a Short for the second parameter, but
            you are passing a string (me.combobox2.t ext). If you turn Option Strict On,
            this should become apparent at compile time rather than runtime. Additionally,
            you should always evaulate the validity of the parameters coming into your
            method to make sure the right type is being passed. Consider the following:

            public Function FormatFoo(ByVal foo as string) as string
            Return foo.ToUpper
            end function

            This method would fail if you pass it Nothing (which is possible if you send
            it the value of me.ComboBox2.Te xt when no value is selected). It is better
            to do the following:

            public Function FormatFoo(ByVal foo as string) as string
            if foo.IsNullOrEmp ty then
            Return String.Empty
            else
            Return foo.ToUpper
            end if
            end function

            In your case, I would recommend you evaluate dtmDate and bytDate to make
            sure they are not Nothing before trying to use them.
            Where can i find info on custom errors?
            Search (using your favorite search engine) "custom exception". Be aware that
            the recommendation has moved from inheriting from ApplicationExce ption toward
            inheriting from Exception.

            Jim Wooley



            Comment

            • Brian Shafer

              #7
              Re: How do I handle this

              ok, I could have been a bit more spicfic... here is my code in the form
              class....(runni ng from my form)
              Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
              System.EventArg s) Handles Button2.Click
              Dim i As GSCSchedule.Sch edules = New GSCSchedule.Sch edules
              Try

              Me.Label2.Text = i.ShowTeamKU(Da te.Today(), Me.ComboBox1.Te xt)
              Catch ex As GSCExceptions
              MessageBox.Show (ex.Message)
              Catch ex As Exception

              End Try
              i = Nothing

              End Sub

              Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As
              System.EventArg s) Handles Button3.Click
              Dim i As GSCSchedule.Sch edules = New GSCSchedule.Sch edules
              Try

              Me.Label7.Text = i.ShowTeamUT(Da te.Today(), Me.ComboBox2.Te xt)
              Catch ex As GSCExceptions
              MessageBox.Show (ex.Message)
              Catch ex As Exception
              'MessageBox.Sho w(ex.Message)
              End Try
              i = Nothing
              End Sub

              the show teams function is a dll and in that class is...
              Public Function ShowTeamKU(ByVa l dtmDate As Date, ByVal strTeam As
              String) As String
              Dim result As String = ""
              Dim strScheduled As String = ""

              Select Case strTeam.ToUpper
              Case Is = "A"
              result = ShiftSchedule_2 8(dtmDate).Subs tring(0, 1)
              Case Is = "B"
              result = ShiftSchedule_2 8(dtmDate).Subs tring(1, 1)
              Case Is = "C"
              result = ShiftSchedule_2 8(dtmDate).Subs tring(2, 1)
              Case Is = "D"
              result = ShiftSchedule_2 8(dtmDate).Subs tring(3, 1)
              Case Else
              Throw New GSCExceptions(s trTeam.ToUpper)
              End Select
              end function

              Public Function ShowTeamUT(ByVa l dtmDate As Date, ByVal bytTeam As
              Short) As String
              Dim result As String = ""
              Dim strScheduled As String = ""

              Select Case bytTeam
              Case Is = 1
              result = ShiftSchedule_3 5(dtmDate).Subs tring(0, 1)
              Case Is = 2
              result = ShiftSchedule_3 5(dtmDate).Subs tring(1, 1)
              Case Is = 3
              result = ShiftSchedule_3 5(dtmDate).Subs tring(2, 1)
              Case Is = 4
              result = ShiftSchedule_3 5(dtmDate).Subs tring(3, 1)
              Case Is = 5
              result = ShiftSchedule_3 5(dtmDate).Subs tring(4, 1)
              Case Else
              Throw New GSCExceptions(b ytTeam)

              End Select
              end function

              AND IN MY error trapping class...

              Public Class GSCExceptions
              Inherits ApplicationExce ption

              Private _strTeam As String
              Private _intTeam As Short

              Public ReadOnly Property strTeam() As String
              Get
              Return _strTeam
              End Get
              End Property

              Public ReadOnly Property intTeam() As Short
              Get
              Return _intTeam
              End Get
              End Property

              Public Sub New(ByVal Team As String)
              MyBase.New("Tea m '" & Team & "' does not exist")
              _strTeam = Team
              End Sub
              Public Sub New(ByVal Team As Short)
              MyBase.New("Tea m bb'" & Team & "' does not exist")
              _intTeam = Team
              End Sub

              End Class

              when I was calling the code to run the function with the combobox and
              passing ""
              I would get a covert from string to integer error.... which was outside of
              dll. Silly me, had a brain cramp... I should know that form error checking
              should be done their. I am just learning DotNet, so you'll get questions
              like this from me from time to time. ...


              "Chris Dunaway" wrote:
              Brian Shafer wrote:
              >
              I get an error if the combobox is "". Which will lead me into the next
              question
              >
              Are we supposed to guess what the error is? Inside your method, you
              will have to check that the arguments supplied are not blank or null
              (whichever is appropriate for your case).
              >

              Where can i find info on custom errors?
              >
              Generally speaking, you would create a class derived from
              ApplicationExce ption and then throw a new instance of that class when
              needed.
              >
              >

              Comment

              • Cor Ligthert [MVP]

                #8
                Re: How do I handle this

                Brian,

                As a lot is said, one little addition.

                If you need to pass string as well as short, than you can make an overloaded
                function.

                (I go for the option strict on answer normally)

                Cor

                "Brian Shafer" <BrianShafer@di scussions.micro soft.comschreef in bericht
                news:43012E04-283B-4FC9-8F3B-E545ABBC59AD@mi crosoft.com...
                >i have
                Public Function ShowMyDate(ByVa l dtmDate As Date, ByVal bytDate As Short)
                As
                String
                >
                I get an error if the combobox is "". Which will lead me into the next
                question
                >
                Me.Label7.Text = i.ShowMyDate(Da te.Today(), Me.ComboBox2.Te xt) in a form
                >
                Where can i find info on custom errors?
                >
                Brian
                >

                Comment

                Working...