Alpha Video Training
Results 1 to 17 of 17

Thread: How to automatically return to Main Menu

  1. #1
    Member
    Real Name
    Jeff Fried
    Join Date
    Aug 2000
    Posts
    589

    Default How to automatically return to Main Menu

    Perhaps this can't be done, but maybe some sharp Xbasic guru has an answer.

    On a network I want one and only one particular user to be in Alpha Five, all others out. The obvious reason is that certain indexes can be updated automatically, overnight, by the one user's computer being the only one open (because a script_schedule command will execute at a certain time), plus other events will take place. There are three tricky aspects to this.

    First, I want the one open user to be at the Main Menu, regardless of where he was when he left the office. The reason: I don't want him to have any data files open. How do I return him to the Main Menu from wherever he might have been, some screen, some menu, whatever? I don't want to close him out of Alpha, just to be sure the data files are all closed, implying the closing of any form or browse which would have data files open.

    Second, the script_schedule command, if you've ever used it, is great for scheduling the first running of a script, but I don't know of a way to continue to keep it running every day. Maybe using the script invoked by script_schedule to run that very script will in fact invoke it for the next day. Not sure. Maybe you know. The reason is that the one computer I wish to be open to the Main Menu each night may not be exited and restarted, i.e., a new session of Alpha may not be started. Since I am using the autoexec.scp to set the script_schedule events, I need to be sure it will trigger every night.

    Third, since I depend on this one computer to be open to Alpha, logged in as a specific user, then if Alpha happened to be closed at the end of the business day and not open to run the script_schedule events, is there a way to 1) detect that Alpha is not open on this computer via a Windows scheduled event 2) if not open, open Alpha using the specific user's login to arrive at the Main Menu. Obviously, I need to know that Alpha is not open first since I don't want to try opening another session of Alpha.

    Thank you if you're familiar with these nuances.

    Jeff Fried

  2. #2
    "Certified" Alphaholic
    Real Name
    Andrew Schone
    Join Date
    Dec 2005
    Location
    Kansas
    Posts
    1,047

    Default Re: How to automatically return to Main Menu

    This is a tall order, however it is possible to accomplish what you are asking.

    1) This script I believe I found in the code archive. Originally written by Martin Cole. This will close all open forms then shutdown Alpha5. However in your case you would want to remove the a5.close() line so that you do not shutdown Alpha5. Ideally you could replace that line with the line that would open you main menu form.
    Code:
    	'Date Created: 02-Aug-2007 09:55:50 PM
    'Last Updated: 05-Feb-2010 08:31:26 AM
    'Created By  : Administrator
    'Updated By  : martin cole
    on error goto errors
    	temp=""
    	loop: 
    	temp=a5.Form_Enum(2) 'get a list of all forms in the app
    	for i=1 to w_count(temp,crlf())
    		fname=word(temp,i,crlf())
    		if is_object(fname)
    			if fname="Menu_master"
    				:Menu_master.code.canexit="" 'override canexit setting
    			else
    				if eval(trim(fname) + ".mode_get()") <> "view"
    					eval(trim(fname) + ".activate()")
    					sys_send_keys("{esc}") 'this cancels possible pop-ups
    					sys_send_keys("{esc}") 'this cancels the current entry/edit
    					xbasic_wait_for_idle() 
    					if is_object(fname) 'may be closed here from esc
    						eval(":" + trim(fname) + ".cancel()")
    						eval(":" + trim(fname) + ".close()")			
    					end if 
    					goto next1 
    				end if 
    				eval(":" + trim(fname) + ".cancel()")
    				eval(":" + trim(fname) + ".close()")			
    			end if
    		end if 
    		next1: 
    	next
    	a5_close_all_windows()
    	temp=a5_list_open_windows()
    	for i=1 to w_count(temp,crlf())
    		eval(word(temp,i,crlf()) + ".cancel()")		
    		eval(word(temp,i,crlf()) + ".close()")
    	next
    	sleep(1/3)
    	if a5_is_runtime() .and. a5.Get_Master_Path()="" 'terminal services machine
    		if api_getmachinename()="martin"
    			msgbox("trapped restart")
    		else
    			sys_shell("shutdown /L")
    		end if 
    	end if 
    	a5.close()
    	end
    	errors:
    	err_msg = error_text_get(error_code_get())
    	line = error_line_number_get()
    	script = error_script_get()
    	ui_msg_box("Error", err_msg+" Error occurred at line "+alltrim(str(line,4,0))+ " in script: "+script)
    	end
    Andrew

  3. #3
    "Certified" Alphaholic
    Real Name
    Andrew Schone
    Join Date
    Dec 2005
    Location
    Kansas
    Posts
    1,047

    Default Re: How to automatically return to Main Menu

    2) Scheduling of a script with a reschedule
    Dr. Wayne wrote the starting of this and I modified it for my needs. You can find the original discussion here

    the script is called StatusCheck it is originally ran from the autoexec via the following command
    Code:
    script_play( "StatusCheck" )

    Code:
    'Date Created: 23-Aug-2010 04:52:28 PM
    'Last Updated: 24-Aug-2010 01:22:13 PM
    'Created By  : andy
    'Updated By  : andy
    DIM vMaintenanceL as L
    vMaintenanceL = lookupl("F",1,"Maintenance","control","Key")
    IF  vMaintenanceL = .t. THEN
    '	ui_msg_box("Maintenance","System is going into Maintenance Mode")
    	IF vgUserP.OverrideMaint = .f. THEN
    		f_shutdown(60)
    	END IF
    else
    	DIM vScriptRunTimeC as C
    	vScriptRunTimeC = totime( toseconds( time() ) + 60, 1 ,0 )
    	'ui_msg_box("",vScriptRunTimeC)
    	script_schedule( "StatusCheck", vScriptRunTimeC )
    END IF
    Andrew

  4. #4
    "Certified" Alphaholic
    Real Name
    Andrew Schone
    Join Date
    Dec 2005
    Location
    Kansas
    Posts
    1,047

    Default Re: How to automatically return to Main Menu

    3) For your third item I would approach that using VB script or a batch file that is ran via the windows scheduler. When configuring the scheduled task you and specify the user credentials that you want to use.

    Here is a quick VB Script to test if Notepad is running. In your case replace "Notepad.exe" with "Alpha5.exe"
    This was found here
    Code:
    set service = GetObject ("winmgmts:")
    
    for each Process in Service.InstancesOf ("Win32_Process")
    	If Process.Name = "notepad.exe" then
    		wscript.echo "Notepad running"
    		wscript.quit
    	End If
    next
    wscript.echo "notepad not running"
    To open Alpha5 you could use the following. This was found here
    Code:
    strProgramPath = "C:\Windows\system32\calc.exe"
    
    SET objShell = CREATEOBJECT("Wscript.Shell")
    
    objShell.Run strProgramPath
    Andrew

  5. #5
    Member
    Real Name
    Jeff Fried
    Join Date
    Aug 2000
    Posts
    589

    Default Re: How to automatically return to Main Menu

    Quote Originally Posted by aschone View Post
    This is a tall order, however it is possible to accomplish what you are asking.

    1) This script I believe I found in the code archive. Originally written by Martin Cole. This will close all open forms then shutdown Alpha5. However in your case you would want to remove the a5.close() line so that you do not shutdown Alpha5. Ideally you could replace that line with the line that would open you main menu form.
    Code:
    	'Date Created: 02-Aug-2007 09:55:50 PM
    'Last Updated: 05-Feb-2010 08:31:26 AM
    'Created By  : Administrator
    'Updated By  : martin cole
    on error goto errors
    	temp=""
    	loop: 
    	temp=a5.Form_Enum(2) 'get a list of all forms in the app
    	for i=1 to w_count(temp,crlf())
    		fname=word(temp,i,crlf())
    		if is_object(fname)
    			if fname="Menu_master"
    				:Menu_master.code.canexit="" 'override canexit setting
    			else
    				if eval(trim(fname) + ".mode_get()") <> "view"
    					eval(trim(fname) + ".activate()")
    					sys_send_keys("{esc}") 'this cancels possible pop-ups
    					sys_send_keys("{esc}") 'this cancels the current entry/edit
    					xbasic_wait_for_idle() 
    					if is_object(fname) 'may be closed here from esc
    						eval(":" + trim(fname) + ".cancel()")
    						eval(":" + trim(fname) + ".close()")			
    					end if 
    					goto next1 
    				end if 
    				eval(":" + trim(fname) + ".cancel()")
    				eval(":" + trim(fname) + ".close()")			
    			end if
    		end if 
    		next1: 
    	next
    	a5_close_all_windows()
    	temp=a5_list_open_windows()
    	for i=1 to w_count(temp,crlf())
    		eval(word(temp,i,crlf()) + ".cancel()")		
    		eval(word(temp,i,crlf()) + ".close()")
    	next
    	sleep(1/3)
    	if a5_is_runtime() .and. a5.Get_Master_Path()="" 'terminal services machine
    		if api_getmachinename()="martin"
    			msgbox("trapped restart")
    		else
    			sys_shell("shutdown /L")
    		end if 
    	end if 
    	a5.close()
    	end
    	errors:
    	err_msg = error_text_get(error_code_get())
    	line = error_line_number_get()
    	script = error_script_get()
    	ui_msg_box("Error", err_msg+" Error occurred at line "+alltrim(str(line,4,0))+ " in script: "+script)
    	end
    This looks interesting. I'll adapt it, test it, and let you know. Thanks.

    Jeff

  6. #6
    Member
    Real Name
    Jeff Fried
    Join Date
    Aug 2000
    Posts
    589

    Default Re: How to automatically return to Main Menu

    Andrew,

    Thank you for these three potential solutions. I need to study them and let you know.

    Jeff

  7. #7
    Member
    Real Name
    Jeff Fried
    Join Date
    Aug 2000
    Posts
    589

    Default Re: How to automatically return to Main Menu

    Quote Originally Posted by aschone View Post
    2) Scheduling of a script with a reschedule
    Dr. Wayne wrote the starting of this and I modified it for my needs. You can find the original discussion here

    the script is called StatusCheck it is originally ran from the autoexec via the following command
    Code:
    script_play( "StatusCheck" )

    Code:
    'Date Created: 23-Aug-2010 04:52:28 PM
    'Last Updated: 24-Aug-2010 01:22:13 PM
    'Created By  : andy
    'Updated By  : andy
    DIM vMaintenanceL as L
    vMaintenanceL = lookupl("F",1,"Maintenance","control","Key")
    IF  vMaintenanceL = .t. THEN
    '	ui_msg_box("Maintenance","System is going into Maintenance Mode")
    	IF vgUserP.OverrideMaint = .f. THEN
    		f_shutdown(60)
    	END IF
    else
    	DIM vScriptRunTimeC as C
    	vScriptRunTimeC = totime( toseconds( time() ) + 60, 1 ,0 )
    	'ui_msg_box("",vScriptRunTimeC)
    	script_schedule( "StatusCheck", vScriptRunTimeC )
    END IF
    Andrew,

    Regarding the 2nd of your suggested solutions, where a script_schedule needs to re-schedule itself in case the Alpha session is not re-booted (since script_schedule does not reset itself for the next day), I'm not sure I followed how Dr. Wayne's method applies to my situation. But I have now tested how it should work for me, in case anyone is interested and can benefit from this.

    The situation is this. I want certain procedures to run during the night automatically, let's say 3 a.m. To assure this is initially scheduled when Alpha is opened, I have placed the script_schedule command in autoexec.scp, but not the actual "script_schedule(<script name>,<time>)". Rather, I placed in the autoexec.scp the command to run a script that schedules the overnight procedures. Let's say the script that will run is called "sch_over", which has the only purpose in doing the following: script_schedule("Overnight","3:00"). The scheduled script is, as you see, named "Overnight". The "Overnight" script runs the various operations I want to accomplish, and the last line in "Overnight" is to run a script called "sch_over", which again schedules "Overnight" to run at the next "3:00". This should accomplish the goal of rescheduling every day if the original Alpha session remains open.

    Jeff

  8. #8
    VAR
    Real Name
    Martin W. Cole
    Join Date
    Apr 2000
    Location
    Terrell, Texas (near Dallas)
    Posts
    5,957

    Default Re: How to automatically return to Main Menu

    Another approach to a "nightly maintenance" routine is to create a new adb - like "maintenance"

    first set all users in th regular adb to close after a certain time

    in the maintenance adb you could add all the tables or all necessary tables and put in the routines, scripts, etc. you want to run. Make a history table for tracking that it ran, the date, etc.

    Set it to run everything when it opens, and then close.

    Then - set a scheduled task to run in windows at a certain time and run the maintenance.

    I've been using this approach for maybe 8 years. Mine rebuilds the indexes, compacts the tables, zips the tables, and then runs maintenance routines and reports for daily summations.
    Cole Custom Programming - Terrell, Texas
    972 524 8714
    martin_w_cole@msn.com

    ____________________
    "A young man who is not liberal has no heart, but an old man who is not conservative has no mind." GB Shaw

  9. #9
    Member
    Real Name
    Jeff Fried
    Join Date
    Aug 2000
    Posts
    589

    Default Re: How to automatically return to Main Menu

    Quote Originally Posted by martinwcole View Post
    Another approach to a "nightly maintenance" routine is to create a new adb - like "maintenance"

    first set all users in th regular adb to close after a certain time

    in the maintenance adb you could add all the tables or all necessary tables and put in the routines, scripts, etc. you want to run. Make a history table for tracking that it ran, the date, etc.

    Set it to run everything when it opens, and then close.

    Then - set a scheduled task to run in windows at a certain time and run the maintenance.

    I've been using this approach for maybe 8 years. Mine rebuilds the indexes, compacts the tables, zips the tables, and then runs maintenance routines and reports for daily summations.
    This sounds like it might be a better approach since I don't need to assure the main computer is in Alpha and at the Main Menu. Thanks for the advice.

  10. #10
    Member
    Real Name
    Jeff Fried
    Join Date
    Aug 2000
    Posts
    589

    Default Re: How to automatically return to Main Menu

    Martin,

    I now remember why I did not take the approach of exiting all users and running a separate maintenance routine. The reason is due to "... cannot be added to this database because it is secured and bound to another database". I know this is due to having a master password defined, but when I remove the master password, the individual logins for each user are no longer in effect.

    In your experience with your "nightly maintenance" routine, can I assume you had individual logins defined for each user but were still able to keep files unbound to the master database? Is it possible you can define logins without a master password, but if you defined them after creating a master password you cannot remove the master password without also disabling individual logins? I found that after putting back the master password, the user logins came back as they were.

    Thanks.

    Jeff

  11. #11
    Member
    Real Name
    Jeff Fried
    Join Date
    Aug 2000
    Posts
    589

    Default Re: How to automatically return to Main Menu

    Martin,

    Additional comments about the master password. Having just tried to experiment with a new database, I see that you cannot define users and groups unless you have a database password. This is a kind of catch-22 since the need for sharing files between databases appears not to be possible unless you eliminate the database (master) password, but without it you cannot control users and groups. Is there a solution to this?

    Thanks.

    Jeff

  12. #12
    VAR
    Real Name
    Martin W. Cole
    Join Date
    Apr 2000
    Location
    Terrell, Texas (near Dallas)
    Posts
    5,957

    Default Re: How to automatically return to Main Menu

    I have never used Alphas password system, so I don't know how you would deal with that.

    But, what you could do is close all forms, etc., and close all but one "machine" - in other words, the maintenance would be tied to one particular computer. I store the machine name in a global variable in my autoexec.
    Cole Custom Programming - Terrell, Texas
    972 524 8714
    martin_w_cole@msn.com

    ____________________
    "A young man who is not liberal has no heart, but an old man who is not conservative has no mind." GB Shaw

  13. #13
    Member
    Real Name
    Jeff Fried
    Join Date
    Aug 2000
    Posts
    589

    Default Re: How to automatically return to Main Menu

    Quote Originally Posted by martinwcole View Post
    I have never used Alphas password system, so I don't know how you would deal with that.

    But, what you could do is close all forms, etc., and close all but one "machine" - in other words, the maintenance would be tied to one particular computer. I store the machine name in a global variable in my autoexec.
    I always use individual and group security to control who has access to what. For example, when I am the user, I can click a hidden button on the Main Menu to gain access to the control panel.

    In an earlier post above, Andrew Schone provided me with code you had written that closes any open windows in Alpha prior to Alpha shutting down. I have not yet studied it, but I was wondering if you have implemented this and if it is stable, in your opinion. I'm also curious why, if you are going to exit Alpha, you wanted to go through the steps of exiting any open forms. Were you concerned that someone who left an entry mid-stream would lose their work when Alpha exit runs? I'm not sure what happens in those cases, whether Alpha leaves without saving or saving.

    Anyhow, I will need something like your windows-closing code to exit to the Main Menu so all data files will be available for index updating.

    Thank you.

    Jeff

  14. #14
    Member
    Real Name
    Jeff Fried
    Join Date
    Aug 2000
    Posts
    589

    Default Re: How to automatically return to Main Menu

    Quote Originally Posted by martinwcole View Post
    I have never used Alphas password system, so I don't know how you would deal with that.

    But, what you could do is close all forms, etc., and close all but one "machine" - in other words, the maintenance would be tied to one particular computer. I store the machine name in a global variable in my autoexec.
    Martin,

    Just to sum up how I solved this, I now have all computers shutting down Alpha in the evening with script_schedule. One computer, which also acts as the maintenance computer with scheduled tasks, shuts down Alpha in early morning since the user of that computer sometimes accesses it in the evening.

    The key was how I open Alpha on the maintenance computer and feed the user ID and password. I accomplished this using a keyboard macro, programmed with the proper timings to feed the user ID after the credentials dialog appears. Once open, the autoexec script takes over. It is set to run a series of overnight procedures in an Overnight.scp, which will only run if the time is in a certain time range, i.e., an early morning time range when the user would not be on the machine. Among the procedures run are index updates. After the procedures run (only a couple minutes), I have the computer shutting down, which is not really necessary but keeps it consistent with all the others. I also have emails sent to me just prior to Alpha opening, then as a next to last step within Alpha, telling me the process began, with the time, and the process ended, with the time. If anything were to go wrong, I would not receive at least the second email, and this would tell me to look at it after I check email. Of course the program that generates the second email within Alpha, which is also part of the autoexec.scp, also has the time range and user-specific conditions so it does not trigger during regular times.

    In addition, I developed a log file to capture every event that takes place within this overnight process (about 15 of them so far), including each index that was updated, the date and time, a description of the event, etc. As I add more overnight procedures, I will also add to this log and will thereby have an ongoing history of what took place.

    The original missing link was how to start up Alpha. I know you can have a Windows scheduled event to open Alpha, but I could not come up with a way to get through the login credentials using Alpha. It might be interesting to know how to do this, but the solution I have now works. The other approach that I could have taken if not for my use of individual login credentials for each user is the one you suggested, which is a separate application that opens, does its thing, and exits. As you now know, if you use a database password, your data files cannot be shared with another application.

    I thought you and anyone else who might be interested in developing overnight updates and other procedures might benefit from this.

    Thanks again to you and the others who contributed advice.

    Jeff

  15. #15
    Member MikeData's Avatar
    Real Name
    Mike Data
    Join Date
    Nov 2008
    Posts
    923

    Default Re: How to automatically return to Main Menu

    I know this is an thread, but I would like to have more info in the Keyboard macro.
    How is executed, any third part software?
    Please advise

  16. #16
    Member
    Real Name
    Jon P Moody
    Join Date
    Nov 2016
    Posts
    185

    Default Re: How to automatically return to Main Menu

    Why not start a new thread rather than have us wade through all the above?

  17. #17
    Volunteer Moderator
    Real Name
    Alan Buchholz
    Join Date
    Oct 2000
    Location
    Delavan, Wisconsin
    Posts
    9,628

    Default Re: How to automatically return to Main Menu

    Quote Originally Posted by armasoft View Post
    Why not start a new thread rather than have us wade through all the above?
    Jon

    2 issues

    1. Hijack threads - no comment about this one.

    2. Posts display order - ascending or descending.

    I have found a setting that changes the sort sequence for posts in a thread so the newest posts are first.
    Saves a bunch of time, but does require looking upside down. And I'm not in Australia ;) - my best regards to Pete..

    Menu - Forum Actions - General Settings

    ThreadOrder.jpg
    Al Buchholz
    Bookwood Systems, LTD
    Weekly QReportBuilder Webinars Thursday 1 pm CST

    Occam's Razor - KISS
    Normalize till it hurts - De-normalize till it works.
    Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
    When we triage a problem it is much easier to read sample systems than to read a mind.

Similar Threads

  1. Adding "Return to Main Menu" on Web Page
    By mcolucci in forum Web Application Server v7
    Replies: 2
    Last Post: 06-21-2006, 10:47 AM
  2. main menu help
    By diane novatnik in forum Alpha Five Version 5
    Replies: 5
    Last Post: 08-06-2003, 05:46 AM
  3. Help with Main Menu
    By Fred Daniel in forum Alpha Five Version 4
    Replies: 1
    Last Post: 01-15-2003, 01:18 AM
  4. Turning Query off, Return to Main Index
    By W. Horton in forum Alpha Five Version 4
    Replies: 1
    Last Post: 12-04-2002, 11:47 AM
  5. Main Menu DB
    By Ed Barley in forum Alpha Five Version 5
    Replies: 2
    Last Post: 11-04-2002, 09:08 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •