Sys() function

This forum is meant for questions about the Visual FoxPro Language support in X#.

Post Reply
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am

Sys() function

Post by Karl-Heinz »

There are many informations available. As a starting point i added the settings 1, 2, 3 , 10 and 11.

Code: Select all

FUNCTION Start( ) AS VOID

	? SYS ( 1 ) 
	? SYS ( 2 ) 
	?
	? SYS ( 3 )	
	? SYS ( 3 )	
	? SYS ( 3 )		
	?
	? SYS ( 10 , Val(SYS(1)))	
	? SYS ( 11 , Date()   )	

       RETURN    

Code: Select all

FUNCTION SYS ( number AS INT , value := NIL AS USUAL ) AS USUAL
LOCAL STATIC oRandom AS System.Random

	
	SWITCH number 
		
 	CASE 1 	// "C" - current system date as a Julian day number
 		
 		RETURN ( (DWORD) Today() ):ToString()
		
		
 	CASE 2 	// "N" - seconds since midnight
 		
		RETURN (INT) XSharp.Core.Functions.Seconds() 
		
		
 	CASE 3  // "C" - Returns a legal file name that can be used to create temporary files.

		IF oRandom == NULL 
			oRandom := System.Random{}
		ENDIF 

 		RETURN oRandom:NEXT( 10000000 , 99999999 ):ToString() 		

	CASE 10  // "C" - String date from Julian day number
		
		IF ! IsNumeric ( value )
			THROW ArgumentException{"wrong parameter type", nameof ( value ) }
		ENDIF 	 	  
		
		RETURN DToC ( (DATE) (DWORD) value )
				
	CASE 11	// "C" - Converts a date expression or character string in date format
			//  	 to a Julian day number
		
		IF IsNil ( value ) 
			THROW ArgumentException{"parameter missing", nameof ( value ) }
		ENDIF 	 		
		
		IF IsDate ( value ) .OR. IsDateTime ( value ) 
	
			RETURN ( (DWORD) (DATE) value ):ToString()	
	
		ELSEIF IsString ( value ) 
	
			VAR d := CToD ( value ) 
	
			IF CToD ( value ) == NULL_DATE 
				RETURN "0" 
			ENDIF 
	
			RETURN ((DWORD ) d ):ToString() 		
	
		ELSE 
	
			THROW ArgumentException{"wrong parameter type", nameof ( value ) }
	
		ENDIF 
		
	OTHERWISE 
		
		RETURN NIL  			
	
	END SWITCH

regards
Karl-Heinz
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am

Sys() function

Post by Karl-Heinz »

Guys,

i also added SYS(5) - similar to CurDrive() - and SYS(2003). To be able to do that i modified the CurDir() and CurDrive() behaviour. The changes are only visible if the Foxpro dialect is used.

if the current dir is "c:cavo28bin", the results are:

Fox-dialect curdrive() shows "C:"
Fox-dialect curdir() shows "CAVO28BIN"

VO-dialect curdrive() still shows "c"
VO-dialect curdir() still shows "cavo28bin"


A root dir like "D:" results in:

Fox-dialect curdrive() shows "D:"
Fox-dialect curdir() shows ""

VO-dialect curdrive() still shows "D"
VO-dialect curdir() still shows ""


Before you run the attached viaef, make sure that the directories used by DirChange() exist. See: function TestDir(). When i get the time i'll have a look at the SET DEFAULT TO behaviour ...

https://hackfox.github.io/section4/s4g339.html

regards
Katl-Heinz
Attachments

[The extension viaef has been deactivated and can no longer be displayed.]

Post Reply