Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function building
#1
im trying my hand at building functions and im stuck on getting this one to return a string.

im trying to build a function that will give me the modify date of a file. i can get it to "out" the data correctly but it doesn't seem to pass the info to the macro that called it.

heres the macro
Code:
Copy      Help
str b
b=Get_File_Date("C:\qm\desktop\monday.mp3")

heres the function
Code:
Copy      Help
function$ $fn
SYSTEMTIME st
str a
lpstr s=GetFileInfo(fn 0 0 0 &st 0 0 1)
a.format("%u/%u/%u" st.wMonth st.wDay st.wYear)

any ideas where im going wrong?

Thanks...
#2
Local str variables are automatically destroyed when the function returns. If you want to return local str variable, declare the function as str.

Code:
Copy      Help
function'str $fn
SYSTEMTIME st
str a
lpstr s=GetFileInfo(fn 0 0 0 &st 0 0 1)
a.format("%u/%u/%u" st.wMonth st.wDay st.wYear)
ret a

or pass b by reference (recommended):

Code:
Copy      Help
str b
Get_File_Date("C:\qm\desktop\monday.mp3" b)
Code:
Copy      Help
function $fn str&a
SYSTEMTIME st
GetFileInfo(fn 0 0 0 &st 0 0 1)
a.format("%u/%u/%u" st.wMonth st.wDay st.wYear)

or create member function str.Get_File_Date:

Code:
Copy      Help
str b
b.Get_File_Date("$desktop$\led.txt")
Code:
Copy      Help
function $fn
SYSTEMTIME st
GetFileInfo(fn 0 0 0 &st 0 0 1)
format("%u/%u/%u" st.wMonth st.wDay st.wYear)
#3
AWESOME!!!
works great....
thanks...
#4
i have to say thank you too, because i almost forgot on how to return strings
when using a function.
pi


Forum Jump:


Users browsing this thread: 1 Guest(s)