New topic: 

RBScript: MsgBox? MessageDialog?

<http://forums.realsoftware.com/viewtopic.php?t=30570>

       Page 1 of 1
   [ 6 posts ]                 Previous topic | Next topic         Author  
Message       oleman108           Post subject: RBScript: MsgBox? 
MessageDialog?Posted: Tue Oct 20, 2009 11:21 am                               
Joined: Tue Sep 02, 2008 3:01 pm
Posts: 83
Location: Switzerland              Can a RBScript contain calls to MsgBox or 
MessageDialog? I took the following example from the RBScript Userguide. I have 
a pushbutton and a TextArea on Window1. The code in the action event is as 
follows:
Code:Dim source As String
source=TextArea1.Text
RbScript1.Source=source
RbScript1.Run

The script from the user guide seems to do nothing. No Dialog. No Error. What 
am I missing?
Code:Dim d as New MessageDialog //declare the MessageDialog object
Dim b as MessageDialogButton //for handling the result
d.icon= MessageDialog.GraphicCaution //display warning icon
d.ActionButton.Caption="Save"
d.CancelButton.Visible= True //show the Cancel button
d.CancelButton.Cancel= True//esc key works for Cancel
d.AlternateActionButton.Visible= True //show the “Don’t Save”
button
d.Message="Save changes before closing?"
d.Explanation="If you don't save your changes, you will lose " _
  +"all that important work you did since your last coffee break."
b=d.ShowModal //display the dialog
Select Case b //b is a MessageDialogButton
Case d.ActionButton //determine which button was pressed.
  //user pressed Save
Case d.AlternateActionButton
  //user pressed Don’t Save
Case d.CancelButton
  //user pressed Cancel
End Select
     
_________________
"Stop deluding yourself with wishful thinking and find a solution that works 
for what you need to do"
Tim Hare - on forums.realsoftware.com  
                            Top                Steve Garman           Post 
subject: Re: RBScript: MsgBox? MessageDialog?Posted: Tue Oct 20, 2009 11:26 am  
                             
Joined: Fri Sep 30, 2005 3:53 pm
Posts: 3055
Location: England              One way is to implement the rbscript1.Print 
event to produce a msgbox

Edit: otherwise implement something in your context class.     
_________________
Steve Garman
Using REALbasic 2008r2 Professional on Windows Vista Ultimate
and REALbasic 2009r4 Professional on Linux Ubuntu 9.04 Desktop
Occasional blog  
                            Top               Phil M           Post subject: 
Re: RBScript: MsgBox? MessageDialog?Posted: Tue Oct 20, 2009 12:23 pm           
             
Joined: Fri Sep 30, 2005 12:18 pm
Posts: 165              RBScript is sandboxed with very limited access to 
REALbasic objects.  It is designed this way so as to protect your application 
and the user... imagine someone posting a script on a public forum that 
advertised extending your application to do something neat, but the actual code 
accesses the hard drive and erases tons of files.  Who would you blame if you 
had no experience in programming if an application allowed all your user 
documents to be permanently lost?

So the disadvantage (in a way) is that RBScript only has the power that you 
give it... but that is also its advantage in security etc.  You have to 
implement a communication scheme between RBScripts and your application, but 
the RBScript side of the communication scheme does not need to be visible to 
your users... you can always prepend additional code to the RBScript.Source.

Also, you should be checking for CompilerError events to see if there is a 
problem... Accessing classes like MessageDialog should display an error saying 
"cannot implement MessageDialog because this item is not found" (or something 
like that) because the script has no idea what you are talking about.   
                            Top               oleman108           Post subject: 
Re: RBScript: MsgBox? MessageDialog?Posted: Tue Oct 20, 2009 12:41 pm           
                    
Joined: Tue Sep 02, 2008 3:01 pm
Posts: 83
Location: Switzerland              @Steve and Phil: Thanks for clarification!

"An example says more than 1000 words" - and the example on Steve's site is a 
big help:
http://www.garman.demon.co.uk/rb/rbscriptTest.rbp

The User-Guide (http://forums.realsoftware.com/viewtopic.php?f=11&t=26429) is 
obviously a work in progress. I hope. Already 124 pages and unfortunately still 
lacking working examples and tutorials. It takes some time for a RBScript 
Newbie like myself to figure out, that all those MsgBox calls shown in the 
Guide will actualy not work just like that...

Anyway, Steve's example gave me a kickstart. I think I know now how to 
implement and use RBScript in my current project.

Thanks!     
_________________
"Stop deluding yourself with wishful thinking and find a solution that works 
for what you need to do"
Tim Hare - on forums.realsoftware.com  
                            Top                Steve Garman           Post 
subject: Re: RBScript: MsgBox? MessageDialog?Posted: Tue Oct 20, 2009 1:27 pm   
                            
Joined: Fri Sep 30, 2005 3:53 pm
Posts: 3055
Location: England              oleman108 wrote:"An example says more than 1000 
words" - and the example on Steve's site is a big help:
http://www.garman.demon.co.uk/rb/rbscriptTest.rbp
I'm glad you like the demo but I hope you are aware that it goes all around the 
houses to display a message.

The project was specifically designed to test using namespaces in RBScript but 
there's no reason you can't use the contextClass's displayMessage method 
directly.

I've put a cutdown (yes even smaller and simpler) demo at 
http://www.garman.demon.co.uk/rb/rbscriptTest1.rbp     
_________________
Steve Garman
Using REALbasic 2008r2 Professional on Windows Vista Ultimate
and REALbasic 2009r4 Professional on Linux Ubuntu 9.04 Desktop
Occasional blog  
                            Top               oleman108           Post subject: 
Re: RBScript: MsgBox? MessageDialog?Posted: Tue Oct 20, 2009 1:34 pm            
                   
Joined: Tue Sep 02, 2008 3:01 pm
Posts: 83
Location: Switzerland              Steve Garman wrote:<..>I hope you are aware 
that it goes all around the houses to display a message.<...>there's no reason 
you can't use the contextClass's displayMessage method directly.Yes, using 
DisplayMessage directly was pretty much the first thing I was trying out, and 
seeing it working starts giving me ideas about how I can implement those things 
I'd like to see in my current app. Thanks again!

Edit:
And instead of 'displayMessage' I could allow the user to stay with familiar 
syntax, i.e. 'MsgBox' :
Code:
Class contextClass
  contextClass.MsgBox:
  Protected Sub MsgBox(msg As String)
  REALBasic.MsgBox msg
  End Sub
End Class
 It just requires a fully qualified name (REALBasic.MsgBox instead of MsgBox 
only), otherwise I'm getting a stack overflow. But like this I think I can add 
some methods an enrich RBScript programming within my app.     
_________________
"Stop deluding yourself with wishful thinking and find a solution that works 
for what you need to do"
Tim Hare - on forums.realsoftware.com  
                            Top            Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 6 posts ]     
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to