RE: Convert Month number to a string of the Month
Posted: 12/10/2004 3:16:19 PM
By: Comfortably Anonymous
Times Read: 2,797
0 Dislikes: 0
Topic: Programming: .NET Framework
Parent Message
OK, that was pretty stupid of me. Just found out that there is a built-in VB.Net function called MonthName() that does the exact same thing and even supports abbreviations... Duh...

Returns a String value containing the name of the specified month.

Public Function MonthName( _
   ByVal Month As Integer, _
   Optional ByVal Abbreviate As Boolean = False _
) As String

Parameters:

- Month
Required. Integer. The numeric designation of the month, from 1 through 13; 1 indicates January and 12 indicates December. You can use the value 13 with a 13-month calendar. If your system is using a 12-month calendar and Month is 13, MonthName returns an empty string.

- Abbreviate
Optional. Boolean value that indicates if the month name is to be abbreviated. If omitted, the default is False, which means the month name is not abbreviated.
Rating: (You must be logged in to vote)
Discussion View:
Replies:

RE: Convert Month number to a string of the Month
Posted: 12/10/2004 3:16:19 PM
By: Comfortably Anonymous
Times Read: 2,797
0 Dislikes: 0
Topic: Programming: .NET Framework
Anyone have an example of anyone/anywhere who uses a 13 month calendar?
Rating: (You must be logged in to vote)

RE: Convert Month number to a string of the Month
Posted: 12/10/2004 3:16:19 PM
By: Comfortably Anonymous
Times Read: 2,797
0 Dislikes: 0
Topic: Programming: .NET Framework
Here's another example of trying to re-invent the wheel (The NullToString function, not the IsDBNull function, or at least I don't think so anyway :) ). Post your redundant code here too, so that we can all learn from our mistakes

Protected Function IsDBNull(ByVal DBVal) As Boolean

  ' Checks if value passed from Database is Null
  ' Returns True if passed value is Null
  ' Returns False is passed value is Not Null

  Return DBVal Is DBNull.Value

End Function

Protected Function NullToString(ByVal DBVal) As String

  ' Returns empty string is value passed from database is Null
  ' Converts value to a string if Not Null

  ' *************************************************************************************
  ' ** Turns out that if you just use the .ToString method of returned values, it will **
  ' ** do the same thing automatically. So consider this function deprecated.          **
  ' *************************************************************************************

  If IsDBNull(DBVal) Then
    Return ""
  Else
    Return DBVal.ToString
  End If

End Function
Rating: (You must be logged in to vote)