Display Date From Array Indexes

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 1262 Views - Last Post: 29 January 2013 - 08:23 AM Rate Topic: -----

#16 Jordan.Hickin91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 28-January 13

Re: Display Date From Array Indexes

Posted 29 January 2013 - 08:23 AM

View PostAdamSpeight2008, on 29 January 2013 - 07:50 AM, said:

What is the type of the parameter named sender?

Private Sub Date_Control(Sender As Object, e As EventArgs) Handles

It's Object and since object the base type for all other types. Sender could be anything. Since it could be anything it doesn't know if it has .Name at compile-time.

So you need to check to see if the sender is a control first.
If Not (TypeOf sender Is Control) Then End Sub
Dim c = DirectCast(sender,Control)

If it then directly cast to one.

Thanks for that. Worked a treat. :D Makes complete sense now lol

View Postandrewsw, on 29 January 2013 - 07:55 AM, said:

You are embedding, for example, "th" in your Format string-specifier. So, for example, your code equates to:

Format(Date1, "dddd 2thMMMM yyyy")
and the letters t and h are then used to format the date. MSDN

One way to handle this is to split it into three parts:

someString = Format(Date1, "dddd ")
someString = someString & CStr(getday(Date1.Day))
someString = someString & Format(Date1, " MMMM yyyy")

Thanks for the information... I managed to get this:

 Day_Box1.Text = Format(Date1, "dddd ") & CStr(getday(Date1.Day)) & Format(Date1, " MMMM yyyy") 

Works the same way just without the 3 lines :D

View Postlar3ry, on 28 January 2013 - 08:18 PM, said:

You are changing all the wrong things. Take a little time and think about what I've said...

Your getday() should look like this:
    Function getday(ByVal day As Integer) As String
        Select Case day

            Case Is = 1 Or 21 Or 31
                Return CStr(day) & "st"

            Case Is = 2 Or 22
                Return CStr(day) & "nd"

            Case Is = 3 Or 23
                Return CStr(day) & "rd"

            Case Else
                Return CStr(day) & "th"
        End Select
    End Function

The parameter should remain an integer (ByVal day as Integer)
The return value is a String ( As String )
You need the integer (day) for the Select Case
You need to convert the integer to a string to concatenate it with the suffix and to return the String.
"st", "nd", and "th" are already strings.

And you don't need to convert the return from getday() to an integer. You need it as a string to fill the TextBox, and it comes back from getday() as a string.

Thanks for all your help :D Was great
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2