Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add datetime variable 2

Status
Not open for further replies.

jezky82

MIS
Jul 7, 2012
39
0
0
ID
sorry I am a beginner in vf, wondering how I would add to the data at the datetime variable. and change for example 06/08/12 01:33:58 PM to 06/08/12 05:33:58 PM
. thank you
 
There are a variety of ways to 'execute over and over again' depending on the precision you need and the general approach you take.

One of the easiest ways is to compile your VFP application into an EXE and then use Windows Scheduled Task to run it periodically. Only you will be able to determine if the precision of the timing is acceptable to you.

Other ways include running your VFP application full-time in the background and having it periodically check on the time. Here too there are variations as to how that can be accomplished and that depends on how you architect your application.

Good Luck,
JRB-Bldr


 
While we all want to encourage using VFP for application development, it still seems like you might be trying to "Re-invent the Wheel" (that is - trying to create something that is already created and working in the world)

Have you done a Google search for:
internet cafe software manage

It might be worth you while to look into these software packages.

Good Luck,
JRB-Bldr
 
thank you all for helping me finally solved my problem.
Special thanks to jrbbldr patient wants to help me.

_screen.Caption="AUTO"
WOUT1=DATETIME()
WOUT2=DATETIME()
WOUT3=DATETIME()
WOUT4=DATETIME()
WOUT5=DATETIME()
WOUT6=DATETIME()

DO WHILE .T.
NOWTIME=DATETIME()
OPEN DATABASE c:\data1.dbc SHARED
USE c:\room.dbf SHARED
WOUT1=OUT1
WOUT2=OUT2
WOUT3=OUT3
WOUT4=OUT4
WOUT5=OUT5
WOUT6=OUT6
USE
IF NOWTIME=WOUT1
do offpc1
ENDIF
IF NOWTIME=WOUT2
do offpc2
ENDIF
IF NOWTIME=WOUT3
do offpc3
ENDIF
IF NOWTIME=WOUT4
do offpc4
ENDIF
IF NOWTIME=WOUT5
do offpc5
ENDIF
IF NOWTIME=WOUT6
do offpc6
ENDIF
ENDDO
 
Unless there is more code somewhere that you have not listed above, it looks like you will either shut down ALL PC's or NONE of the PC's everytime the application runs.

I think that you have the basic understanding of how to use the DATETIME() values, but you need to put some thought into how you are going to architect your application so that you get what you want.

You might possibly want 2 separate VFP applications.
1. A managerial EXE where the Shutdown DateTime values for each individual Workstation are entered into the Room data table.

2. An application which runs automatically from the Windows Scheduled Tasks utility and which analyses the current DateTime values against the previously entered Room data table values and Shuts down the PC's or not.

Good Luck,
JRB-Bldr
 
If running scheduled tasks, the idea would be to set them up programmatically to run at a certain time for powering a pc on or off, the only code the exe itself would need therefor is to either shut a pc on or off, the time checking is done by the taskscheduler, not by your app anymore.

Eg poweron.exe would expect a PC name or IP or NIC MAC address or whatever it takes to turn on a certain pc and poweroff.exe would take the same type of parameter to turn a pc off. Or make it two parameters pc and "on" or "off" to pass into some poweronoff.exe, whatever.

The logic tu run an app at a certain time and then check if that is the current time is bound to fail, because it will never exactly start at a predefined time. You would always need to check for the planned time being passed already. Startup of an exe is a thing taking up to a few seconds, also taskscheduler isn't precisely starting at a planned time. That inexactness shouldn't matter though, as you talk about hours a pc is rented and kept ON.

You won't need to cope with time calculation and comparison, that part of the task would be taken care of by the OS and the taskscheduler system.

Do you get the idea now? You don't need anything more or less then to do the action planned for that time in the exe the scheduled task calls.

Bye, Olaf.
 
Based on the code you wrote above, one thing I am still not sure you fully understand is how to determine the DateTime value for some time other than NOW.

You might want to look at:
How To Add or Subtract Time with a DateTime Data Type

Good Luck,
JRB-Bldr
 
creating a scheduled task.


It will run at ther predefined time. So here you put in the planned time.

You won't need to check whether a predefined time has arrived in the called exe, it is called at (about) that time. Not earlier, just with a few seconds lag.

And the to shut down a pc you can use this code:

But there is no way to power up a pc not running I know of.

This is just a minimal part of the problems an internet cafe software has to solve. Plus you will rather just lock a pc after the rented time and not shut it off.

Overall, I still recommend you look out for an already existing solution.

Bye, Olaf.
 
Another way that I have used to force the Shutdown of a PC is:

Code:
tcEXEFile = "C:\Windows\System32\Shutdown.exe"
tcParameters = "-s -t 1 -f"
tcCmd = "Open"
tcCmd = PROPER(m.tcCmd)

* --- API Call to communicate with an application based on the registered file-type. ---
DECLARE INTEGER ShellExecute ;
   IN SHELL32.DLL ;
   INTEGER nWinHandle,;
   STRING cOperation,;
   STRING cFileName,;
   STRING cParameters,;
   STRING cDirectory,;
   INTEGER nShowWindow

IF FILE(tcEXEFile)
   * --- If Old DOS Shutdown Exists, Run It To Shutdown Workstation ---
   lnFileStatus = ShellExecute(0,"&tcCmd",tcEXEFile,tcParameters,"",1)
ENDIF

Good Luck,
JRB-Bldr



 
Code:
tcEXEFile = "C:\Windows\System32\Shutdown.exe"

Except that, rather than hard-code the path, I would use SHGetSpecialFolderLocation() to locate the file.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top