Weekday

Blitz3D Forums/Blitz3D Beginners Area/Weekday

Tricky(Posted 2004) [#1]
Perhaps strange to see me posting here, since I'm everything but a beginner, but I don't know where to post it else.

One week ago I started to convert and old production I wrote in Visual Basic into Blitz. The huge RPG Game "Power Of The Rings II"... I encountered one problem, though.

This RPG game has a puzzle based on the days of the week, in which the clue lies in the setting of the computer clock, however Blitz does not appear to have a feature to get the day of the week (unless there's an undocumented feature for that, or my version is plainly too old).

Do you guys know any sort of trick to get that one solved?


semar(Posted 2004) [#2]
I guess a simple API call would do the trick, the problem is that I don't know actually which API to call...

However, if you need to retrieve the day of the week only at the beginning of the game, then you may run an external app first - like a VB app for example - which will write in a file the day of the week info, and then read that file from within your program.

Sergio.


maverick(Posted 2004) [#3]
there are comands in blitz to get both the current date and time

variable$=currentdate()
variable$=currenttime()


GfK(Posted 2004) [#4]
I'm sure Snarty wrote a set of functions to do this. Try the code archives on blitzcoder.com.


semar(Posted 2004) [#5]
There's also a vb script solution. If you put this line:
call msgbox(weekday(now))

in a .vbs file, and call it, it will provide a message box with a number between 1 and 7 (1 being sunday, and 7 saturday).

Would be easy to add some line and write a vbscript code that will write that info to a file...

Sergio.


Tricky(Posted 2004) [#6]
I'm sure Snarty wrote a set of functions to do this. Try the code archives on blitzcoder.com.


I'll surely take a look, thanks


@semar
Writing a VBScript code to write it into a file is easy, I've coded sites in VBScript (like the old version of TBBS, the current version is in php, but the old was in vbs), I'm not quite sure how to combine VBScript with Blitz, though...


Anyway, I'll keep the VB solution in mind as long as I don't have a better solution, but first I'll try GFK's idea to search the BlitzCoder archives...

Thank you for you quick responses, guys


semar(Posted 2004) [#7]
I'm not quite sure how to combine VBScript with Blitz, though

Just call it from within blitz, like you would do with an exe.. you can also use the CreateProcess command, and try to get the output from the external application.

Sergio.


Tricky(Posted 2004) [#8]
ExecFile I suppose, I can try that, and er, the "CreateProcess" is not taken as a command in the version of Blitz I use. Guess that is because I ain't got Blitz+, I only got Blitz2D and Blitz3D. (money problems )


semar(Posted 2004) [#9]
Yes, ExecFile is the command, while CreateProcess works only with Blitz+.

Here is a sample of a vbscript which writes in a file the day of week:

createfile(weekdayname(weekday(now)))

Sub CreateFile(day)
   Dim fso, tf
   'open the file
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set tf = fso.CreateTextFile(".\weekday.txt", True)
   ' Write a line with a newline character.
   tf.WriteLine(day)
   tf.Close
End Sub


However, I would use only the weekday function, and retrieve the number of the day of the week; this because on an english O.S. you get, for example, 'Thursday', while on a german, the string written on the file would be 'Donnerstag'.

Sergio.


soja(Posted 2004) [#10]
You guys are trying to hack your way through... why don't you just make a straight call to the Windows API?

Something like this:
;.lib "Kernel32.dll"
;GetDateFormat%(iLocale%, iFlags%, iDate%, iFormat$, oDateBuf*, iSizeBuf%):"GetDateFormatA"

date = CreateBank(256)
size = GetDateFormat(0, 0, 0, "dddd", date, BankSize(date))
Print BankToString(date, size)
Delay 1000
End

Function BankToString$(b, size)
	For i = 0 To size-2 ; (null-terminated)
		s$ = s$ + Chr$(PeekByte(b,i))
	Next
	Return "Today is "+s$+"."
End Function

Output:
Today is Thursday.

You can even specify different locales if you want. This works in Win95 and up.


semar(Posted 2004) [#11]
why don't you just make a straight call to the Windows API

Because I didn't know actually which API to call... now yes - thanks soja. :)

A question though.

Is there a list of all the functions (and descriptions) contained in the DLLs ?

For example, how do you know that the function GetDateFormat exists, and is located in the Kernel32.DLL ?

Or, to be more specific, is there a list of all the functions which are accessible from within each DLL ?

I think that there's a lack of such a documentation... or perhaps there *IS*, but... where the hell is it ?!?!?

Sergio.


soja(Posted 2004) [#12]
Well, I used DumpBin (included with VC++) to get a list of all the exported functions of a DLL. There are probably other programs that do this.

For just the WinAPI, you might try API-Guide from allapi.net. It has a search function so you can search on titles, etc.

You can also just search MSDN for any function (not method) in the Platform SDK. Any of them should list the library (i.e. dll) that they're included in.


Klaas(Posted 2004) [#13]
you can do it in Blitz aswell :
Dim splitresult$(100)
Dim monthname$(12)
monthname(1)="Jan"
monthname(2)="Feb"
monthname(3)="Mar"
monthname(4)="Apr"
monthname(5)="May"
monthname(6)="Jun"
monthname(7)="Jul"
monthname(8)="Aug"
monthname(9)="Sep"
monthname(10)="Okt"
monthname(11)="Nov"
monthname(12)="Dec"

Dim dayname$(7)
dayname(0)="Monday"
dayname(1)="Tuesday"
dayname(2)="Wednesday"
dayname(3)="Thursday"
dayname(4)="Friday"
dayname(5)="Saturday"
dayname(6)="Sunday"

;first split the currentdate into Day, month and year
split(" ",CurrentDate())

Global SDP_day = splitresult(0)
Global SDP_month = FindMonth(splitresult(1)) ;becaus month is not a number .. convert
Global SDP_year = splitresult(2)

days = weekday(SDP_day,SDP_month,SDP_year)
Print "Day: "+days
Print "Dayname:"+dayname(days)
WaitKey

Function FindMonth(fm$)
  For i=1 To 12
  If fm$=monthname(i) Then Return i
  Next
End Function

Function weekday(d,m,y)
  jd=( 1461 * ( y + 4800 + ( m - 14 ) / 12 ) ) / 4 + ( 367 * ( m - 2 - 12 * ( ( m - 14 ) / 12 ) ) ) / 12 - ( 3 * ( ( y + 4900 + ( m - 14 ) / 12 ) / 100 ) ) / 4 + d - 32075
  Return jd Mod 7
End Function

Function split(seperator$,txt$)
	pos=Instr(txt$,seperator$,1)	
	While (pos)
		splitresult(count)=Left(txt$,pos-Len(seperator))
		
		txt$=Right(txt$,Len(txt$)-pos-Len(seperator)+1)
		pos=Instr(txt$,seperator$,1)
		count=count+1
	Wend
	splitresult(count)=txt$
	
	Return count
End Function



Tricky(Posted 2004) [#14]
@Soja

Your method didn't compile in my Blitz. Is it because I don't have B+? (Never experimented with .dlls you see)

@Semar
That was the method I have in mind myself (Gives me rememberance when I coded TBBS in VBScript), since I couldn't get the API method on I think that is my best alternative... :-/

Thank you guys ;)

@Klaas (Put in later on, as I didn't see it when writing the messages above)
Hmmm.... That is quite some calculation you got there. If it works, I may take it :)


soja(Posted 2004) [#15]

Your method didn't compile in my Blitz.


It's probably because you didn't set up the .decls file. Create a plain text file with the extension name ".decls" (for example, "kernel32.decls") and put it in the blitz\userlibs folder. Then write these two lines:
.lib "Kernel32.dll"
GetDateFormat%(iLocale%, iFlags%, iDate%, iFormat$, oDateBuf*, iSizeBuf%):"GetDateFormatA"

(I'm assuming you don't already have a '.lib "Kernel32.dll"' line anywhere else in any other decls file.)

Once you put in that GetDateFormat declaration underneath the .lib declaration, it should compile and run fine, assuming your Blitz version is up-to-date.


Tricky(Posted 2004) [#16]
I see... I'll take a look into that, thank you ;)