Page 2 of 2

Re: How to script a non-modal msg to the user?

Posted: 25 Sep 2014 21:55
by klownboy
Big +1 for this wish!

Another "very impressive" to you highend. I like the fact that it stays on top. I'll be able to make use of this in some existing scripts where currently a different technique is used.

Would there be any way to combine your stay-on-top VB script message with another VB script that provided a timed message (see below). The script was originally provided by Stefan here http://www.xyplorer.com/xyfc/viewtopic. ... age#p71980 So the message would stay on top but it would self destruct after a designated period. I'm thinking that if the user didn't respond (as in this example select the files required) within say 5 or 6 seconds the script would simple end, or possibly reload, or provide another message to say aborting or similar. If he selects the files and hits OK as he should, the script proceeds as normal.

Code: Select all

  global $t_msg;
  if (Get('CountSelected') < 2) {
    $t_msg = "Make sure that all the files and folders that you want to process are selected in the list. Click OK when your selection is complete.";
    Sub "_TIMED_MESSAGE";
  }
    Text Get('SelectedItemsPathNames'), /*width*/, /*height*/, 'You selected the following items:';
    end 1;
"_TIMED_MESSAGE";
  global $t_msg;		  
  $waitSec = 6;
  $out="";
  foreach($line, $t_msg, "<crlf>"){ $out = $out . chr(34) . $line . chr(34) . " & vbCRLF _<crlf> & ";}
  $out = replace($out, "&", "", ,strlen($out) -3, 1);

  //Create the VBS file:
  $VBS = <<<HEREDOC
text =  $out 
SET WS = CreateObject("WScript.Shell")
'//WshShell.Popup   strMessage [,intSecondsToWait] [,strTitle] [,intType]
WS.popup text, $waitSec
HEREDOC;
  writefile("<xyscripts>\tempVBS.vbs", $VBS);
  run ("wscript ""<xyscripts>\tempVBS.vbs"""), ,2,0;
Thanks,
Ken

Edit: See example below with a timed message which stays-on-top.

Re: How to script a non-modal msg to the user?

Posted: 25 Sep 2014 22:46
by highend
Easy...

Just replace:

Code: Select all

WS.popup text, $waitSec
with

Code: Select all

WS.popup text, $waitSec, , vbInformation+vbSystemModal
The title of that window must be put into the ", ," part (if necessary)

Re: How to script a non-modal msg to the user?

Posted: 26 Sep 2014 01:24
by klownboy
highend wrote:Easy...
:) Easy for you. I figured you'd use the same code as you did in your example, but where, that was the hard part

Anyway it worked great. This actually has a good practical use (see below). In this particular example, if after the message displays, I select the files and don't do anything the message goes away and the script would continue (i.e., without even hitting the OK button in the message box to proceed). If I pre-select the files, obviously no message at all. If no files are selected by the end of the timed message, the script would be reloaded and the message re-appears. Of course you could do whatever the script needed.

Code: Select all

  global $t_msg;
  if (Get('CountSelected') < 2) {
    $t_msg = "Make sure that all the files and folders that you want to process are selected in the list. Click OK when your selection is complete.";
    Sub "_TIMED_MESSAGE";
  }
  if (Get('CountSelected') >= 2) {
    Text Get('SelectedItemsPathNames'), /*width*/, /*height*/, 'You selected the following items:';
    end 1;   // or more commands
	} else {
	load(self("file"));}
"_TIMED_MESSAGE";
  global $t_msg;		  
  $waitSec = 6;
  $out="";
  foreach($line, $t_msg, "<crlf>"){ $out = $out . chr(34) . $line . chr(34) . " & vbCRLF _<crlf> & ";}
  $out = replace($out, "&", "", ,strlen($out) -3, 1);
 //Create the VBS file:
  $VBS = <<<HEREDOC
text =  $out 
SET WS = CreateObject("WScript.Shell")
'//WshShell.Popup   strMessage [,intSecondsToWait] [,strTitle] [,intType]
WS.popup text, $waitSec, , vbInformation+vbSystemModal
HEREDOC;
  writefile("<xyscripts>\tempVBS.vbs", $VBS);
  run ("wscript ""<xyscripts>\tempVBS.vbs"""), ,2,0;
Thanks again,
Ken

Re: How to script a non-modal msg to the user?

Posted: 26 Sep 2014 11:17
by nerdweed
A simple oneliner
run ('CMD /C "ECHO Message To Alert You && PAUSE"') ;