...

function won't recognize parameters

Brett Bretterso
09-23-2005, 06:13 PM
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.)

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.

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

nikkiH
09-23-2005, 06:58 PM
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()

Brett Bretterso
09-23-2005, 07:07 PM
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.

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.

nikkiH
09-23-2005, 07:14 PM
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.

Brett Bretterso
09-23-2005, 08:48 PM
Gah! I can't believe I forgot that. Thank you.

Brett Bretterson



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum