Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    function won't recognize parameters

    I made a function that would take a date, break it into month, day and year and return them as an arraylist. (Note: datum means date in Dutch. I speak Dutch as a second language and find it useful for naming variables.)

    Code:
     Private Function dateBreaker(ByVal datum As DateTime)
            'takes a date, breaks the date into mon, dy and yr and puts them into an arraylist
            Dim breaker As String = ""
            Dim datum2 As ArrayList
            datum2.Add(datum.ToString().Substring(0, datum.ToString().IndexOf("/")))
            breaker = datum.ToString().Substring(datum.ToString().IndexOf("/") + 1)
            datum2.Add(breaker.Substring(0, breaker.IndexOf("/")))
            breaker = breaker.Substring(breaker.IndexOf("/") + 1)
            datum2.Add(breaker.Substring(0, breaker.IndexOf(" ")))
            datum2.TrimToSize()
            Return datum2
        End Function
    It's used by another part that uses the parts to set selectedvalues of dropdownlists.

    Code:
    Response.Write(datum)
                Dim datum2 As ArrayList = dateBreaker(datum)
                placeMon.SelectedValue = datum2(0)
                placeDy.SelectedValue = datum2(1)
                placeYr.SelectedValue = datum2(2)
    My problem is that every time I run it it gives me an error: System.NullReferenceException: Object reference not set to an instance of an object. at oncall.editoncall.dateBreaker(DateTime datum) at oncall.editoncall.calLoad()

    I've tried doing all kinds of things like making it take a string instead of datetime and converting datum before passing it, but it still acts like there's nothing there, even though the response.write is displaying datum's value, so I know it's getting that far.

    It's been a while since I've done asp.net (I've been spending more time with javascript recently) so I could be doing something wrong with my functions.

    Any help would be much appreciated.

    Brett Bretterson

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    I use C# for .net, so I don't know if this is right, but in "normal" VB, to return a value in a function, you have to set the function to the value. There is no return statement.

    i.e.
    Private Function dateBreaker(ByVal datum As DateTime)

    dateBreaker = datum2

    End Function

    Edit:

    Oh, darn.
    Scratch that.
    It uses return now like a normal language. LOL

    This is the problem:
    Dim datum2 As ArrayList
    datum2.Add(d

    You need NEW before you can add. All that did was declare it as a type.
    Dim dataum2 as New ArrayList()
    Last edited by nikkiH; 09-23-2005 at 07:02 PM.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New Coder
    Join Date
    Aug 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried that and it had no effect. I think in VB.net it lets you do it either way. I've got another function working fine.

    Code:
    Private Function minToSelIndex(ByVal mins As Integer)
            Select Case mins
                Case 0, 59
                    Return 0
                Case 15
                    Return 1
                Case 30
                    Return 2
                Case 45
                    Return 3
            End Select
        End Function
    This one takes the minutes and turns it into the appropriate selectedIndex. It's working fine. I don't know why dateBreaker doesn't want to work.

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Did you see this comment?

    This is the problem:
    Dim datum2 As ArrayList
    datum2.Add(d

    You need NEW before you can add. All that did was declare it as a type.
    Dim dataum2 as New ArrayList()


    That's why it won't work.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #5
    New Coder
    Join Date
    Aug 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Gah! I can't believe I forgot that. Thank you.

    Brett Bretterson


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •