Welcome, Guest
Username: Password: Remember me
This public forum is meant for questions and discussions about Visual FoxPro
  • Page:
  • 1

TOPIC:

Sys() function 26 Apr 2021 16:54 #18178

  • Karl-Heinz
  • Karl-Heinz's Avatar
  • Topic Author


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

    FUNCTION Start( ) AS VOID
    
    	? SYS ( 1 ) 
    	? SYS ( 2 ) 
    	?
    	? SYS ( 3 )	
    	? SYS ( 3 )	
    	? SYS ( 3 )		
    	?
    	? SYS ( 10 , Val(SYS(1)))	
    	? SYS ( 11 , Date()   )	
    
           RETURN    

    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

    Please Log in or Create an account to join the conversation.

    Last edit: by Karl-Heinz.

    Sys() function 27 Apr 2021 12:35 #18202

    • Karl-Heinz
    • Karl-Heinz's Avatar
    • Topic Author


  • Posts: 774
  • 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:\cavo28\bin", the results are:

    Fox-dialect curdrive() shows "C:"
    Fox-dialect curdir() shows "\CAVO28\BIN\"

    VO-dialect curdrive() still shows "c"
    VO-dialect curdir() still shows "cavo28\bin"


    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 ...

    hackfox.github.io/section4/s4g339.html

    regards
    Katl-Heinz

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1