How to test that agent is running In Debug? - lotus-domino

Is there a way to know that an agent in running in debug mode (Tools/Debug LotusScript has been activated) ?
I found nothing in NotesAgent class, something like RunOnServer but RunInDebugger.
I need this to avoid using the progress bar function located in NNOTESWS.DLL, which pops over the debugger and prohib any click (step into, or watching variables). BTW if it occurs to someone you still can press F8 / F5, this help at least not to kill Notes.

There Is a very good example for doing this in OpenNTF. You can find it here.
And in fact it IS for the progress bar, so you can use tho whole class from there.
The trick is: you add a function with a stop statement. You measure the time before the stop statement and after. If the time passed is bigger than 100ms, than a user had to click on "continue", what he never manages to do in such a small amount of time. If debugger is not enabled, the stop is ignored - no delay...
Here is the function used in the linked openntf article:
Public Function IsDebugMode() As Boolean
Dim start As Variant
start = Getthreadinfo(6) ' LSI_THREAD_TICKS
Stop
If Getthreadinfo(6) - start > 100 Then IsDebugMode = True
' If you debug the application you will not be able to press the CONTINUE-Buton
' within less then 100 milliseconds, otherwise the STOP-statement is not in function
' and you will always be quicker then 100 milliseconds
End Function
Although the comment is in fact wrong (100 tics are not 100ms, you would have to devide by ticks per second to get that value), the code still works and does exactly what you want.

Related

Get state of SFX (spec. time) in XNA using VB.NET

I have a specific problem that might have a different solution than the one I'm thinking of (and included in the title). It is as follows:
My character revs up a chainsaw by pressing a button, keeps it going for as long as the player presses the button, and then revs down when the player releases the button. Now I want to add SFX to this. How can I smoothly go from SFX to SFX in order (revup, loop, revdown). Can I somehow check the SFX for timing, so that I wont end up with a gap between them. If I check
SFX.State = SoundState.Playing,
I might end up having a gap between the next being played. Alternatively, can I start/resume a SFX at a different time than it's real starting time? So that I can have revup/loop/revdown in the same SFX and just control what time of it plays.
Thanks for any insight into this!
/Christian
For the revup to loop part, you know the exact length of revup, so you can just time the start of loop using gameTime. For the revdown part, that's easy, when the button release is detected, simply stop revup or loop, whichever was playing and start revdown on the same frame.

Wait for 1 second before starting code again - VB.NET

I desperately need help with a game I am making. For a bit of context, i am making a memory game and i have the following piece of code that is being troublesome. I have a bunch of labels on the form, 16 to be exact, with 1 randomly generated symbol placed in each. Each symbol appears in the labels twice.
------------------------------Continued----------------------------------------
'MsgBox("hello") 'used to check if the second inccorect press shows up - it does show but instantly changes colour
'''''''''''''''''NEED SOME CODE THAT PAUSES IT HERE'''''''''''''''
labels(0).ForeColor = Color.DarkRed
sender.ForeColor = Color.DarkRed
End If
flips = 1
End If
End If
tmrmemory.Enabled = True ' starts the timer after the user clicks the first label
End Sub
What's supposed to happen is that when the labels clicked don't match, it should show both the clicked labels for a short period before changing them both back to "DarkRed" which is the colour of the form's background.
I have tried using a timer but then i can't use sender.forecolor=color.darkred because it is not declared globally.
I have also tried using the command Threading.Thread.Sleep(500) but it still doesn't show the second incorrect click. I know that the code i have used works because when i use the message box, i can see both symbols and when the two clicks are correct, it stays.
Threading.Thread.Sleep(500) will actually pause your code for half a second. However during this time it won't do anything, not even refresh your controls. To get the effect you want, you need to call the YourControl.Refresh method before calling Threading.Thread.Sleep to force the control to redraw immediately.
On a side note, I would advise you not to call Threading.Thread.Sleep on UI thread. It will give a feeling of program hang. Instead do your work on a separate thread. You can either do all the work yourself right from creating a separate thread to destroying it, or use the BackgroundWorker control which has all the functionality built in.
Here is the link to an article I wrote a long time ago regarding BackgroundWorker that might be useful for you:
http://www.vbforums.com/showthread.php?680130-Correct-way-to-use-the-BackgroundWorker
Declare a variable outside the sub that stores what label should be flipped when the timer ends.
Label click sets
storedLabel = sender
Timer tick sets storedLabel.ForeColor = Color.DarkRed

Mouse click/release psychopy

I am using the .isPressedIn() function see if the mouse click is in a target shape. However, whenever you click on the target shape, it will say the response is incorrect. However, whenever you hold the mouse button down in the target shape, it will say the mouse was clicked on the target. I'm not sure how to fix the mouse button release. I tried using CustomMouse, but I am unable to get that to click inside a shape (unless I am mistaken). Any suggestions would be greatly appreciated.
Thanks!
stimDuration = 5 #stimuli are on the screen for 5 seconds
potential_target = [shape1, shape2, shape3] #shapes that may be a target
target = random.sample(potential_target, 1) #randomly select a target
myMouse = event.Mouse() #define mouse
if clock.getTime() >= stimDuration
ResponsePrompt.draw() #message to indicate to participant to select target
win.flip()
core.wait(2)
if myMouse.isPressedIn(target[0]):
print "correct"
else:
print "incorrect"
The problem is that the line myMouse.isPressedIn(target[0]) checks the state of the mouse exactly when that line is run. Since it is preceeded by a core.wait(2) it does not react to mouse clicks in those two seconds and consequently only collects the mouse response of you still hold it down after two seconds.
I would instead have a tight loop around the myMouse.isPressedIn which runs thousands of times per second. So skipping your first lines:
ResponsePrompt.draw() # message to indicate to participant to select target
win.flip() # show that message
while True: # keep looping. We will break this loop on a mouse press
if myMouse.isPressedIn(target[0]): # check if click is within shape
print "correct"
break # break loop if this condition was met
elif myMouse.getPressed(): # check if there was any mouse press at all, no matter location
print "incorrect"
break # break while loop if this condition was met
In that code, you are using the expression if myMouse.isPressedIn(target[0]), but are only evaluating that expression after some time has elapsed (stimDuration). This means that isPressedIn() will be typically be evaluated well after the actual click happened. At that point, the mouse may no longer be within target[0], or may not longer be being pressed down by the subject. So I think what you are seeing is the correct (expected) behavior.
So to obtain the behavior that you want, you need to do keep track of whether then mouse was pressed in the shape on every frame.
Also, I am not sure how you are using the code you posted. Some looks appropriate for every frame, but some looks like it should be run only once (Begin routine). You might want to review that--things should not be initialized every frame (like target or myMouse).

Showing the updates being performed by macro

So I have seen all the ways to hide the screen updating in excel, what I'm looking for is a data problem, so I WANT to see the screen update. Is there a way to code the screen to update during the macro slowly? I tried the following:
'//////adding screen updating to watch what's happening
Application.ScreenUpdating = True
Application.Wait Now + TimeValue("00:00:01")
'/////
and all I got was screen flicker.
Thanks for being excellent unto me.
What you're after is a better method of debugging your errors. ScreenUpdating property of the Application is not what you want :)
Instead, set a breakpoint in your code using F9, at or before where you suspect the error is happening. If necessary, you can put this on your first line of code (if you literally have no idea where the error happens).
Here is a breakpoint, it's the red/maroon highlighted line:
Then, using the F8 key, you can step through the code line by line.
You can add as many breakpoints as you want. Pressing F5 will execute the code only up to the next breakpoint, then you would have to F8 or F5 to resume execution.
Some additional things to help you debug
Use the Locals window.
This shows you the vairables in scope, and you can click on them to view their properties/etc. As you can see, I have a shitload of variables in a fairly complicated application. I've found the immeidates window is very helpful for Object variables and arrays. Here is what it looks like when I expand an array variable, so that I can see all its contents:
Use the Immediate window to query variables or execute statements outside of your code, this is equivalent to Debug.Print statements. For example, let's check to see if the value of some variable is "9", you can:
?someVar = 9 and then press enter. It will show you True or False. You could query the value directly by ?someVar and it would print the value.
In this screenshot, I am checking the value of a boolean, and it shows me that the value is False. I could also verify this in the Locals window.
The screen updating must be set only once, at the start of the code.
But the Wait you will need to put inside your loop, or spread between your code lines.

Display time left when running

I have a form with a few buttons which execute code when pressed like running validations on the database.
Some code can run for a few minutes so is there any way to show the time remaining or a message to display the % of process completed?
Or pop out a message when code evaluation starts and the message should disappear once code running is completed?
What you are probably looking for is a "Progress Bar".
I've used the Microsoft ProgressBar control (you can find it under Insert->ActiveX Control), and it's not that hard to use. Just set the value of it to a percentage (as an integer, not a decimal).
'foo, being the ProgressBar
me.foo = 70 '70%
There is some good info here on another method: http://www.granite.ab.ca/access/progressbar.htm
In order to do this the "normal" way, you'd need to run your validation in another thread and have it report its progress back to the UI thread. However, I don't believe VBA supports any kind of multithreading.
If your validation routines involve a loop, or even just many separate discrete operations, you can try inserting a DoEvents statement in between loop iterations (or operations), and then have your progress display updated periodically (say, in an Application_OnTime event handler).
I usually have a form I name frmProgress or whatever, with a cancel button and a label for displaying a status message. Then embedded in the form code I have a boolean called bCancel, and when you hit the cancel button it simply sets bCancel as true.
Also in this code I have a routine called ShowPercDone( Idx , NumIdc ) where Idx is the step the code is on, and NumIdc is the number of steps the code will take (assuming each step takes the same amount of time). This works well when I'm running through a for loop, but basically any time I want to display a status update I just call the routine in the form with my message, which I should add runs the doevents command for me.
So that's how the status form works. In the macro I run, I start out by just calling frmProgress.show (0) so that it lets you click the cancel button. Then in my loop when I update the status message I then check frmProgress.bCancel and if it's true I exit out of the macro.
Hope that helps.
Finally to be simple i decided to use the method given here
http://oreilly.com/pub/h/3330#code