shell.run only once in a set timescale.

Sorry for the vague header.

I have the following code:

Sub OnCall (State, Name, Number)
Shell.Run "C:\YACTextSend @CALL" & Name & "~" & Number
End Sub

Which enables a prog called Float's Mobile Agent to send incoming mobile phone caller id info to a prog called YAC eventually to be displayed as a caller ID pop-up in Media Center by MCE-YAC.

It works but for one problem. OnCall is invoked at each ring so my added snippet above launches YACTextSend and pops up a caller ID window at each ring of an incoming call.

I am not skilled enough to rewrite Float's prog (written in Delphi) so I have to work with the above code. Is it possible to modify my code to run YACTextSend only once in say a 20 second period.

Thanks, Craig

[811 byte] By [installer69] at [2007-12-28]
# 1

Hi,

Look at DateTime and subtracting one from the other as follows.>>

Subtracts a specified date and time from another specified date and time, yielding a time interval.

[Visual Basic]

returnValue = DateTime.op_Subtraction(d1, d2)

[C#]

public static TimeSpan operator -(

DateTime d1,

DateTime d2

);

[C++]

public: static TimeSpan op_Subtraction(

DateTime d1,

DateTime d2

);

[JScript]

returnValue = d1 - d2;

[Visual Basic] In Visual Basic, you can use the operators defined by a type, but you cannot define your own. You can use the Subtract method instead of the DateTime subtraction operator.

[JScript] In JScript, you can use the operators defined by a type, but you cannot define your own.

Arguments [Visual Basic, JScript]

d1

A DateTime (the minuend).

d2

A DateTime (the subtrahend).

Parameters [C#, C++]

d1

A DateTime (the minuend).

d2

A DateTime (the subtrahend).

Return Value

A TimeSpan that is the time interval between d1 and d2; that is, d1 minus d2.

Example

[Visual Basic, C#, C++] The following sample demonstrates the Subtract method and operator.

[Visual Basic] 

Dim date1 As New System.DateTime(1996, 6, 3, 22, 15, 0)

Dim date2 As New System.DateTime(1996, 12, 6, 13, 2, 0)

Dim date3 As New System.DateTime(1996, 10, 12, 8, 42, 0)

Dim diff1 As System.TimeSpan

' diff1 gets 185 days, 14 hours, and 47 minutes.

diff1 = date2.Subtract(date1)

Dim date4 As System.DateTime

' date4 gets 4/9/1996 5:55:00 PM.

date4 = date3.Subtract(diff1)

Dim diff2 As System.TimeSpan

' diff2 gets 55 days 4 hours and 20 minutes.

diff2 = System.DateTime.op_Subtraction(date2, date3)

Dim date5 As System.DateTime

' date5 gets 4/9/1996 5:55:00 PM.

date5 = System.DateTime.op_Subtraction(date1, diff2)

 
I would use a STATIC variable in your Sub to hold the previous DateTime to compare
the value of datetime.Now with the previous DateTime as in>>
Static lastTime As DateTime=Datetime.Now
 
See an explanation by DMAN1 on STATIC variables here.>>
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1076220&SiteID=1
You would need to use String functions to compare the minutes and seconds portions.
 
Regards,
S_DS
 
 
 
Spidermans_DarkSide at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

It sounds as though you need some form of state variable which when this is called is set and after a specific time interval is reset. In which case the on-call would set the state variable and start the timer which would be set to a duration say 10 seconds and it would then reset the state variable.

I'll show a similar sort of concept using a button click event instead of an on-call. I want to click the button and display something, but for 10 seconds afterward I dont want the button to do anything, irrespective of how many times I hit it.

Something like the following. So click the button and the time of the click is displayed - you can click the button as many times as you want the label wont chnage until after 10 seconds from the first click has occured. Instead of changing the label in a button click event you can shell.run (although I'd probably prefer to use a process.start)


Public Class Form1
Dim bStateVariable As Boolean = False

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If bStateVariable = False Then
bStateVariable = True
Me.Label1.Text = "Button Pressed" & Now.Second
Me.Timer1.Start()
End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = "Initial State"
Me.Timer1.Interval = 10000 '10 sec
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = "Initial State"
bStateVariable = False
Me.Timer1.Stop()
End Sub
End Class


spotty at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3

Thanks for the help.

Spotty, here is where I took it but my scripting is at the 'I use PHP so how hard can VBS be?' stage - ie. very limited.

Sub OnCall(State, Name, Number) Handles OnCall
If bStateVariable = False Then
bStateVariable = True
Me.Shell.Run "C:\YACTextSend @CALL" & Name & "~" & Number
Me.Timer1.Start()
End if
End Sub

Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Shell.Run = "Initial State"
Me.Timer1.Interval = 10000 '10 sec
End Sub

Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Shell.Run = "Initial State"
bStateVariable = False
Me.Timer1.Stop()
End Sub

installer69 at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic General...