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
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