What am I doing wrong here?

Mac OSX 10.12.6, Xojo 2015 Release 4.1

Dim mydate as New date
I have this code in a testField mouse down event…

[code]Dim dateStr as String

dateStr = mydate.ShortDate

Dim Day, Month as string

If Parsedate(dateStr, mydate) then
If month = “01” or month = “1” then
month = “Jan”
elseif month = “02” or month = “2” then
month = “Feb”
elseif month = “03” or month = “3” then
month = “Mar”
elseif month = “04” or month = “4” then
month = “Apr”
elseif month = “05” or month = “5” then
month = “May”
elseif month = “06” or month = “6” then
month = “Jun”
elseif month = “07” or month = “7” then
month = “Jul”
elseif month = “08” or month = “8” then
month = “Aug”
elseif month = “09” or month = “9” then
month = “Sep”
elseif month = “10” then
month = “Oct”
elseif month = “11” then
month = “Nov”
elseif month = “12” then
month = “Dec”
end if

end if

me.Text = Str(mydate.Day) + " " + Month + " " + Str(mydate.Year)[/code]

When I click the TextField I get "22 2018’, I am expecting “22 Jan 2018”

Thanks.

Lennox

You are not setting month to anything so it is returning “”.

Thanks Simon,

I had an oversight there.

Thanks again.

Lennox

and use SELECT CASE myDate.Month instead of a ton of ELSE statements

[code]
dateStr = mydate.ShortDate

Dim Day, Month as string

select case mydate.month
case 1
month = “Jan”
case 2
month = “Feb”
case 3
month = “Mar”
case 4
month = “Apr”
case 5
month = “May”
case 6
month = “Jun”
case 7
month = “Jul”
case 8
month = “Aug”
case 9
month = “Sep”
case 10
month = “Oct”
case 11
month = “Nov”
case 12
month = “Dec”
end select

me.Text = Str(mydate.Day) + " " + Month + " " + Str(mydate.Year)

[code]

or better yet

me.text=Str(mydate.Day) + " " + mid("JanFebMarAprMayJunJulAugSepOctNovDec",(mydate.month-1)*3+1,3) + " " + Str(mydate.Year)

Thanks Dave.
Lennox

or maybe:

month = NthField(“Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec”, “,”, mydate.month)