Home All Groups Group Topic Archive Search About
Author
25 Jul 2006 7:40 PM
Brian Shafer
i have
Public Function ShowMyDate(ByVal 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(Date.Today(), Me.ComboBox2.Text) in a form

Where can i find info on custom errors?

Brian

Author
25 Jul 2006 8:26 PM
Chris Dunaway
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
ApplicationException and then throw a new instance of that class when
needed.
Author
25 Jul 2006 9:03 PM
Jim Wooley
> Brian Shafer wrote:
> Generally speaking, you would create a class derived from
> ApplicationException and then throw a new instance of that class when
> needed.

MSFT has changed the recommendation on deriving from ApplicationException
and now recommend deriving from Exception and NOT using ApplicationException.
See http://blogs.msdn.com/kcwalina/archive/2006/06/23/644822.aspx.

Jim Wooley
http://devauthority.com/blogs/jwooley
Author
25 Jul 2006 11:26 PM
Brian Shafer
ok, I could have been a bit more spicfic... here is my code in the form
class....(running from my form)
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
        Dim i As GSCSchedule.Schedules = New GSCSchedule.Schedules
        Try

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

        End Try
        i = Nothing

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
        Dim i As GSCSchedule.Schedules = New GSCSchedule.Schedules
        Try

            Me.Label7.Text = i.ShowTeamUT(Date.Today(), Me.ComboBox2.Text)
        Catch ex As GSCExceptions
            MessageBox.Show(ex.Message)
        Catch ex As Exception
            'MessageBox.Show(ex.Message)
        End Try
        i = Nothing
    End Sub

the show teams function is a dll  and in that class is...
    Public Function ShowTeamKU(ByVal 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_28(dtmDate).Substring(0, 1)
            Case Is = "B"
                result = ShiftSchedule_28(dtmDate).Substring(1, 1)
            Case Is = "C"
                result = ShiftSchedule_28(dtmDate).Substring(2, 1)
            Case Is = "D"
                result = ShiftSchedule_28(dtmDate).Substring(3, 1)
            Case Else
                Throw New GSCExceptions(strTeam.ToUpper)
        End Select
end function

    Public Function ShowTeamUT(ByVal 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_35(dtmDate).Substring(0, 1)
            Case Is = 2
                result = ShiftSchedule_35(dtmDate).Substring(1, 1)
            Case Is = 3
                result = ShiftSchedule_35(dtmDate).Substring(2, 1)
            Case Is = 4
                result = ShiftSchedule_35(dtmDate).Substring(3, 1)
            Case Is = 5
                result = ShiftSchedule_35(dtmDate).Substring(4, 1)
            Case Else
                Throw New GSCExceptions(bytTeam)

        End Select
end function

AND IN MY error trapping class...

Public Class GSCExceptions
    Inherits ApplicationException

    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("Team '" & Team & "' does not exist")
        _strTeam = Team
    End Sub
    Public Sub New(ByVal Team As Short)
        MyBase.New("Team 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.  ...


Show quoteHide quote
"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
> ApplicationException and then throw a new instance of that class when
> needed.
>
>
Author
25 Jul 2006 8:27 PM
Samuel Shulman
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

Show quoteHide quote
"Brian Shafer" <BrianSha***@discussions.microsoft.com> wrote in message
news:43012E04-283B-4FC9-8F3B-E545ABBC59AD@microsoft.com...
>i have
> Public Function ShowMyDate(ByVal 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(Date.Today(), Me.ComboBox2.Text) in a form
>
> Where can i find info on custom errors?
>
> Brian
>
Author
25 Jul 2006 8:27 PM
tomb
Brian Shafer wrote:

Show quoteHide quote
>i have
>Public Function ShowMyDate(ByVal 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(Date.Today(), Me.ComboBox2.Text) 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
Author
25 Jul 2006 9:11 PM
Jim Wooley
> i have
> Public Function ShowMyDate(ByVal 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(Date.Today(), Me.ComboBox2.Text) in a
> form

Your ShowMyDate function is requiring a Short for the second parameter, but
you are passing a string (me.combobox2.text). 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.Text when no value is selected). It is better
to do the following:

public Function FormatFoo(ByVal foo as string) as string
   if foo.IsNullOrEmpty 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 ApplicationException toward
inheriting from Exception.

Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
Author
26 Jul 2006 4:16 AM
Cor Ligthert [MVP]
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

Show quoteHide quote
"Brian Shafer" <BrianSha***@discussions.microsoft.com> schreef in bericht
news:43012E04-283B-4FC9-8F3B-E545ABBC59AD@microsoft.com...
>i have
> Public Function ShowMyDate(ByVal 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(Date.Today(), Me.ComboBox2.Text) in a form
>
> Where can i find info on custom errors?
>
> Brian
>