Code Executes too quickly!

Hi - Looking for some more help!! (I can do things on my own…honest!!!)

Anyway, code efficiency is a good thing, and speed is a good thing. However, what do you do if the code you have runs too quickly??

I am sending a button in a mail to a user, I would like this user to click the button and for a view to open on the screen, print, and then CLOSE!

My problem, (different from my post yesterday), is to get the view to CLOSE! When I do get it to close, it runs too quickly and prints the mail out instead of the view!

Does anyone have any ideas as to how to slow this down or do it a different way?

Here is my code :

Sub Click(Source As Button)

'open the database

Dim workspace As New NotesUIWorkspace

Dim uiv As NotesUIView

Dim db As NotesDatabase

Dim s As New NotesSession



Call workspace.OpenDatabase _

( "SERVER", "folder\folder\name.nsf", "viewname", _

"Current", False, False )



Set uiv = workspace.CurrentView

Set db = s.CurrentDatabase



If db.IsOpen And db.Title = "NC System" Then

’

	keybd_event &h11,0,0,0 ' Ctrl key down

	keybd_event &h50,0,0,0 ' P key down

	keybd_event &h11,0,2,0 ' Ctrl key up

	keybd_event &h50,0,2,0 ' P key up

’

	keybd_event &h09,0,0,0 ' Tab key down

	keybd_event &h09,0,2,0 ' Tab key up

	keybd_event &h09,0,0,0 ' Tab key down

	keybd_event &h09,0,2,0 ' Tab key up

	keybd_event &h27,0,0,0 ' Right arrow key down

	keybd_event &h27,0,2,0 ' Right arrow key up	

	keybd_event &h27,0,0,0 ' Right arrow key down

	keybd_event &h27,0,2,0 ' Right arrow key up

	keybd_event &h27,0,0,0 ' Right arrow key down

	keybd_event &h27,0,2,0 ' Right arrow key up

	keybd_event &h27,0,0,0 ' Right arrow key down

	keybd_event &h27,0,2,0 ' Right arrow key up

	

	keybd_event &h10,0,0,0 ' Shift key down

	keybd_event &h09,0,0,0 ' Tab key down

	keybd_event &h10,0,2,0 ' Shift key up

	keybd_event &h09,0,2,0 ' Tab key up

	keybd_event &h10,0,0,0 ' Shift key down

	keybd_event &h09,0,0,0 ' Tab key down

	keybd_event &h10,0,2,0 ' Shift key up

	keybd_event &h09,0,2,0 ' Tab key up

	keybd_event &h10,0,0,0 ' Shift key down

	keybd_event &h09,0,0,0 ' Tab key down

	keybd_event &h10,0,2,0 ' Shift key up

	keybd_event &h09,0,2,0 ' Tab key up

’

	keybd_event &h27,0,0,0 ' Right arrow key down

	keybd_event &h27,0,2,0 ' Right arrow key up

’

	keybd_event &h12,0,0,0 ' Alt key down

	keybd_event &h41,0,0,0 ' A key down

	keybd_event &h12,0,2,0 ' Alt key up

	keybd_event &h41,0,2,0 ' A key up

’

	keybd_event &h0d,0,0,0 ' Enter key down

	keybd_event &h0d,0,2,0 ' Enter key up

	

	keybd_event &h12,0,0,0 ' Alt key down

	keybd_event &h31,0,0,0 ' 1 key down

	keybd_event &h12,0,2,0 ' Alt key up

	keybd_event &h31,0,2,0 ' 1 key up

End If



'I have tried this :

keybd_event &h12,0,0,0 ' Alt key down

keybd_event &h31,0,0,0 ' 1 key down

keybd_event &h12,0,2,0 ' Alt key up

keybd_event &h31,0,2,0 ' 1 key up



'And This :

keybd_event &h1b,0,0,0 ' Escape Key Down

keybd_event &h1b,0,2,0 ' Escape Key Up



'And this:

uiv.Close

End Sub

As you can see, I have tried many things, including a For Loop to create a pause, but it still doesn’t work.

Anyone have any ideas?

Thanks in Advance

F1H

Subject: Code Executes too quickly!!!

I’ve not read your previous posts so forgive me if I am saying something you’ve already heard but…

Why not use Formula?

@If(@Command([FileOpenDatabase] ; “server”:“database” ; “view”);

@Do(@Command([FilePrint]);@PostedCommand([FileCloseWindow])) ; “”)

Subject: Code Executes too quickly!!!

Hi,

Might not be any good, but I wonder if you use the execute command in LotusScript to to execute the code that performs all the keypresses and then the line to close the view, would it run in the right order?

Dim exString as String

exString = ||

Execute exString

Bit of a hack but maybe work a go?

Cheers,

Andrew.

Subject: RE: Code Executes too quickly!!!

Is the problem that there isn’t enough of a pause?

Try the sleep function.

sleep(number of seconds).

Subject: RE: Code Executes too quickly!!!

Hi,

Thanks for al replies. I am using LotusScript because I need to print the view in landscape, so i am using the keypresses to tab to the page options, change the orientation and then print.

I have tried the sleep function, but it seems to pause before even opening the view!! (weird). I will try your other suggestions out now, and let you know.

Thanks

F1H

Subject: RE: Code Executes too quickly!!!

I was trying out Andrew’s suggestions with the Execute and I think it may be the way forward…however, I cant seem to get it to run…its generating the folllowing error :

“$Execute$+3: Not a sub or function name: KEYBD_EVENT”

I am not sure if i have coded the execute stuff correctly…here is the code :

Sub Click(Source As Button)

'open the database

Dim workspace As New NotesUIWorkspace

Dim uiv As NotesUIView

Dim db As NotesDatabase

Dim s As New NotesSession

Dim exString As String

Dim exClose As String



Call workspace.OpenDatabase _

( "SERVER", "folder\folder\name.nsf", "viewname", _

"Current", False, False )



Set uiv = workspace.CurrentView

Set db = s.CurrentDatabase



exString = | If db.IsOpen And db.Title = "NC System" Then

’

	keybd_event &h11,0,0,0 ' Ctrl key down

	keybd_event &h50,0,0,0 ' P key down

	keybd_event &h11,0,2,0 ' Ctrl key up

	keybd_event &h50,0,2,0 ' P key up

’

	keybd_event &h09,0,0,0 ' Tab key down

	keybd_event &h09,0,2,0 ' Tab key up

	keybd_event &h09,0,0,0 ' Tab key down

	keybd_event &h09,0,2,0 ' Tab key up

	keybd_event &h27,0,0,0 ' Right arrow key down

	keybd_event &h27,0,2,0 ' Right arrow key up	

	keybd_event &h27,0,0,0 ' Right arrow key down

	keybd_event &h27,0,2,0 ' Right arrow key up

	keybd_event &h27,0,0,0 ' Right arrow key down

	keybd_event &h27,0,2,0 ' Right arrow key up

	keybd_event &h27,0,0,0 ' Right arrow key down

	keybd_event &h27,0,2,0 ' Right arrow key up

	

	keybd_event &h10,0,0,0 ' Shift key down

	keybd_event &h09,0,0,0 ' Tab key down

	keybd_event &h10,0,2,0 ' Shift key up

	keybd_event &h09,0,2,0 ' Tab key up

	keybd_event &h10,0,0,0 ' Shift key down

	keybd_event &h09,0,0,0 ' Tab key down

	keybd_event &h10,0,2,0 ' Shift key up

	keybd_event &h09,0,2,0 ' Tab key up

	keybd_event &h10,0,0,0 ' Shift key down

	keybd_event &h09,0,0,0 ' Tab key down

	keybd_event &h10,0,2,0 ' Shift key up

	keybd_event &h09,0,2,0 ' Tab key up

’

	keybd_event &h27,0,0,0 ' Right arrow key down

	keybd_event &h27,0,2,0 ' Right arrow key up

’

	keybd_event &h12,0,0,0 ' Alt key down

	keybd_event &h41,0,0,0 ' A key down

	keybd_event &h12,0,2,0 ' Alt key up

	keybd_event &h41,0,2,0 ' A key up

’

	keybd_event &h0d,0,0,0 ' Enter key down

	keybd_event &h0d,0,2,0 ' Enter key up

	

	'keybd_event &h12,0,0,0 ' Alt key down

	'keybd_event &h31,0,0,0 ' 1 key down

	'keybd_event &h12,0,2,0 ' Alt key up

	'keybd_event &h31,0,2,0 ' 1 key up

End If |



'I have tried this :

'keybd_event &h12,0,0,0 ' Alt key down

'keybd_event &h31,0,0,0 ' 1 key down

'keybd_event &h12,0,2,0 ' Alt key up

'keybd_event &h31,0,2,0 ' 1 key up



'And This :

'keybd_event &h1b,0,0,0 ' Escape Key Down

'keybd_event &h1b,0,2,0 ' Escape Key Up



'And this:

exClose = |uiv.Close|



Execute exString

Execute exClose

End Sub

Thanks for any help

F1H

Subject: RE: Code Executes too quickly!!!

If you have any includes you’ll need to put this in the execute string as the includes in your agent are outside of the scope of the code that runs.

At least I think that’s right…

If that doesn’t work, I wonder can you put the part of the code that closes the view in the execute code instead?

Cheers,

Andrew

Subject: RE: Code Executes too quickly!!!

Thanks for the reply Andrew, Unfortunately its not working, here is my code :

Sub Click(Source As Button)

'open the database

Dim workspace As New NotesUIWorkspace

Dim uiv As NotesUIView

Dim db As NotesDatabase

Dim s As New NotesSession

Dim exString As String

Dim exClose As String

Dim exPause As String



Call workspace.OpenDatabase _

( "PMPGLA7", "pmpgb\quality\ncsystem.nsf", "ReworkOpen", _

"Current", False, False )



Set uiv = workspace.CurrentView

Set db = s.CurrentDatabase



exString = |

Declare Sub keybd_event Lib "user32.dll" (Byval bVk As Integer, Byval bScan As Integer, Byval dwFlags As Integer,Byval dwExtraInfo As Integer)

Dim workspace As New NotesUIWorkspace

Dim uiv As NotesUIView

Dim db As NotesDatabase

Dim s As New NotesSession

Dim exString As String

Dim exClose As String



Set uiv = workspace.CurrentView

Set db = s.CurrentDatabase



	 If db.IsOpen And db.Title = "NC System" Then

’

	keybd_event &h11,0,0,0 ' Ctrl key down

	keybd_event &h50,0,0,0 ' P key down

	keybd_event &h11,0,2,0 ' Ctrl key up

	keybd_event &h50,0,2,0 ' P key up

’

	keybd_event &h09,0,0,0 ' Tab key down

	keybd_event &h09,0,2,0 ' Tab key up

	keybd_event &h09,0,0,0 ' Tab key down

	keybd_event &h09,0,2,0 ' Tab key up

	keybd_event &h27,0,0,0 ' Right arrow key down

	keybd_event &h27,0,2,0 ' Right arrow key up	

	keybd_event &h27,0,0,0 ' Right arrow key down

	keybd_event &h27,0,2,0 ' Right arrow key up

	keybd_event &h27,0,0,0 ' Right arrow key down

	keybd_event &h27,0,2,0 ' Right arrow key up

	keybd_event &h27,0,0,0 ' Right arrow key down

	keybd_event &h27,0,2,0 ' Right arrow key up

	

	keybd_event &h10,0,0,0 ' Shift key down

	keybd_event &h09,0,0,0 ' Tab key down

	keybd_event &h10,0,2,0 ' Shift key up

	keybd_event &h09,0,2,0 ' Tab key up

	keybd_event &h10,0,0,0 ' Shift key down

	keybd_event &h09,0,0,0 ' Tab key down

	keybd_event &h10,0,2,0 ' Shift key up

	keybd_event &h09,0,2,0 ' Tab key up

	keybd_event &h10,0,0,0 ' Shift key down

	keybd_event &h09,0,0,0 ' Tab key down

	keybd_event &h10,0,2,0 ' Shift key up

	keybd_event &h09,0,2,0 ' Tab key up

’

	keybd_event &h27,0,0,0 ' Right arrow key down

	keybd_event &h27,0,2,0 ' Right arrow key up

’

	keybd_event &h12,0,0,0 ' Alt key down

	keybd_event &h41,0,0,0 ' A key down

	keybd_event &h12,0,2,0 ' Alt key up

	keybd_event &h41,0,2,0 ' A key up

’

	keybd_event &h0d,0,0,0 ' Enter key down

	keybd_event &h0d,0,2,0 ' Enter key up

	

	'keybd_event &h12,0,0,0 ' Alt key down

	'keybd_event &h31,0,0,0 ' 1 key down

	'keybd_event &h12,0,2,0 ' Alt key up

	'keybd_event &h31,0,2,0 ' 1 key up

End If|



'And This :

'keybd_event &h1b,0,0,0 ' Escape Key Down

'keybd_event &h1b,0,2,0 ' Escape Key Up



'keybd_event &h12,0,0,0 ' Alt key down

'keybd_event &h31,0,0,0 ' 1 key down

'keybd_event &h12,0,2,0 ' Alt key up

'keybd_event &h31,0,2,0 ' 1 key up



'keybd_event &h1b,0,0,0 ' Escape Key Down

'keybd_event &h1b,0,2,0 ' Escape Key Up 



'And this:

exClose = |

Dim workspace As New NotesUIWorkspace

Dim uiv As NotesUIView

Dim db As NotesDatabase

Dim s As New NotesSession

Dim exString As String

Dim exClose As String

Dim exPause As String



Set uiv = workspace.CurrentView

Set db = s.CurrentDatabase



Call workspace.ViewRefresh

Call uiv.close|



Execute exString

Execute exClose

End Sub

I have tried everything - refresh the workspace, executes, sleeps…looks like the user will have to close the view for themselves…Thanks Anyway.

F1H

Subject: RE: Code Executes too quickly!!!

i am having a similar problem. the issue, i think, is that workspace doesnt update currentview property to the newly opened view. it keeps this property to its original value. thats why sleep etc wont work. let me know if u find some solution