Posts: 3
Threads: 2
Joined: Mar 2006
hi i am writting a program and would like the date to be displayed in the form for example
i want 03/21/2006
to read 21st march 2006
another problem i am having is that when i try put in a line it say illegal function call can anyone tell me what this means?
can any one help me at all
Posts: 3,368
Threads: 195
Joined: Jan 2003
For the first question, you must know about STR$() and SELECT CASE.. you should get each of the different elements "3", "21", "2006" into different variables, i.e. month1%, day1%, year1%. Then you use SELECT CASE to add in the appropriate string pieces to make a different string, e.g.:
Code: SELECT CASE day1%
case 1: day2$ = "1st"
case 2: day2$ = "2nd"
END SELECT
'...etc.
date$ = day2$+month2$+STR$(year1%)
Can you put up the code that you got with "illegal function call"? That just means you didn't type it as it should be..
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.
Posts: 488
Threads: 19
Joined: Sep 2005
Here ya go, it's of use to me so I don't mind posting it:
Code: ' Date converter
' By Axipher
DIM months$(1 TO 12)
months$(1) = "January"
months$(2) = "Febuary"
months$(3) = "March"
months$(4) = "April"
months$(5) = "May"
months$(6) = "June"
months$(7) = "July"
months$(8) = "August"
months$(9) = "September"
months$(10) = "October"
months$(11) = "November"
months$(12) = "December"
DIM days$(1 TO 31)
days$(1) = "1st"
days$(2) = "2nd"
days$(3) = "3rd"
days$(4) = "4th"
days$(5) = "5th"
days$(6) = "6th"
days$(7) = "7th"
days$(8) = "8th"
days$(9) = "9th"
days$(10) = "10th"
days$(11) = "11th"
days$(12) = "12th"
days$(13) = "13th"
days$(14) = "14th"
days$(15) = "15th"
days$(16) = "16th"
days$(17) = "17th"
days$(18) = "18th"
days$(19) = "19th"
days$(20) = "20th"
days$(21) = "21st"
days$(22) = "22nd"
days$(23) = "23rd"
days$(24) = "24th"
days$(25) = "25th"
days$(26) = "26th"
days$(27) = "27th"
days$(28) = "28th"
days$(29) = "29th"
days$(30) = "30th"
days$(31) = "31st"
CLS
PRINT DATE$
date1$ = DATE$
month1% = VAL(MID$(date1$, 1, 2))
month2$ = months$(month1%)
day1% = VAL(MID$(date1$, 4, 2))
day2$ = days$(day1%)
year1% = VAL(MID$(date1$, 7, 4))
year2$ = STR$(year1%)
date2$ = day2$ + " " + month2$ + " " + year2$
PRINT date2$
SLEEP
Quote:Example Output
03-28-2006
28th March 2006
It works fine in QBasic 4.5 and also in FreeBasic.
Posts: 3,368
Threads: 195
Joined: Jan 2003
I'll supply a "Thank you" to you, axipher.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.
Posts: 3,368
Threads: 195
Joined: Jan 2003
Aha, yes. That's right. Double standards. Ahem.
*clears throat*
Bad, bad axipher! It should not have been a 100% working program.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.
Posts: 488
Threads: 19
Joined: Sep 2005
Sorry, but I would have posted it any way, once I see a problem, I take a crack at it, if I get it I show the forum that I have changed from a useless spam posting know-it-all jerk to someone who submits answers to problems. He would have got it either way, and I'm sorry I posted the working code, I could have posted the original FB code which has and Code: dim months(1 to 12) as string * 9 => {[list here]}
, then he would to have done alot of work.
Posts: 3,368
Threads: 195
Joined: Jan 2003
Yeah that's ok... he probably won't even read this again, anyway.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.
Posts: 6,419
Threads: 74
Joined: Mar 2002
The thingo is that someone registers and its only post is asking for some homework to be done, and you do it for him, it's wrong.
Imagine that some guy is asked to solve 10 equations at school and his dad does them for him, instead of explaining him how to solve equations. Same thing.
Btw, the cardinal to ordinal conversion can be done in quite fewer lines:
Code: Function card2ord (number As Integer) As String
Dim res As String
Dim last As String
res = Str$(number)
last = Right$(res, 1)
Select Case last
Case "1": res = res + "st"
Case "2": res = res + "nd"
Case "3": res = res + "rd"
Case Else: res = res + "th"
End Select
card2ord = res
End Function
And it works for every number.
Posts: 488
Threads: 19
Joined: Sep 2005
not really, think of 11 to 19, they all have "th" at the end and 111 to 119 and 211 to 219...
|