Author Topic: A question for Don F.  (Read 3567 times)

Ponnfar

  • Full Member
  • ***
  • Posts: 149
    • View Profile
    • http://zabaware.com
A question for Don F.
« on: October 25, 2003, 11:41:51 pm »
Hi Don!
Thanks for all the great ideas you have shared in your posts.
I have really statred to enjoy some of the many plug-ins folks have created and am slowly stared to "get it" I have been
disceting a few scripts and becoming a bit, that is a bit,more familiar with the nomenclature.

Some time ago you created a "Datediff" routine. It seems straight forward and simple enough (simple is good) but maybe I am not "getting" as much as I thought [:)]
here is my argument:

If GetResponse(LastResponseTime) = False Then LastResponseTime = DateDiff

'Next we have the function subtract the variant's date and time from
'the current date and time, and let Hal say it out loud:

GetResponse = "It has been" & DateDiff("s", LastResponseTime) & " seconds since you last said something !"
LastResponseTime = Now
End

This whould work yes? yeah right...HELP!!
Thanks!!
Also, I am using this in another UHP, NOT my default brain, will that make a difference...I don't know...tripping the system timer or somehthing. Well before I big toe firmly down my throat, I'll stop. I think you get the point.
Ideally, I would like to have HAL comment after a specified time like say 2 hours or once I press enter waking up HAL and deactivating my screensaver. How might I go about scripting that? Well, again I think you get the idea.
Thanks in advance for you help.
P
« Last Edit: October 25, 2003, 11:47:35 pm by Ponnfar »
One Person can summon the future...

Don Ferguson

  • Sr. Member
  • ****
  • Posts: 303
    • View Profile
    • http://www.cortrapar.com
A question for Don F.
« Reply #1 on: October 26, 2003, 12:13:56 am »
Hi Ponnfar,

When I am adding original new code to a brain (in addition to all the backups and safety precautions that I've described in earlier postings), I open the script in one window, and Hal in the other, and test each little building block "live."  This is what I recommend for you.

For instance, put your new routine toward the end of the GetResponse function in the script, and start with this one line of code:

GetResponse = Now

Hit "Save" and toggle to Hal, and see if you can get Hal to say the current date and time.  If so, you have one little building block that works, and you can go back and try another:

LastResponseTime = Now
GetResponse = LastResponseTime

(Remember that the LEFT variant will be changed to match the RIGHT variant, not the other way around.)

Hit "Save" again, toggle to Hal, and see if Hal says what you expect him to say.  If that works, you have created another little building block.

In your particular example, I'm not sure I'm understanding the following line of your code:

If GetResponse(LastResponseTime) = False Then LastResponseTime = DateDiff
 
I could be wrong (because I DON'T have "VBScript in a Nutshell" memorized and I don't have it in front of me), but I think that "GetResponse" followed by an argument in parenthesis wouldn't make any sense.  GetResponse is a variant, so it wouldn't work that way.  On the other hand, DateDiff is a function, and it DOES need arguments after it.

Please do me a favor and try cutting and pasting code from my posting and/or my sample brain regarding DateDiff and see if you can make "building blocks" work for you, and make sense for you, as I described above.

In the meantime, I'll look back at that earlier posting myself. We'll get you where you want to go.

Sincerely,

Don
Don Ferguson
E-mail: fergusonrkfd@prodigy.net
Website: www.cortrapar.com
Don's other forum posts: http://www.zabaware.com/forum/search.asp?mode=DoIt&MEMBER_ID=274

Don Ferguson

  • Sr. Member
  • ****
  • Posts: 303
    • View Profile
    • http://www.cortrapar.com
A question for Don F.
« Reply #2 on: October 26, 2003, 01:10:02 am »
Okay, Ponnfar, we're back:

The code that you asked me about contained two issues:

1.  As I mentioned, since GetResponse is a variant (like a memory bank with a name), it doesn't take "arguments" in parenthesis.

2.  In the code line where you used "DateDiff", which IS a function, the "arguments" must take a specific pattern of: unit switch, date formatted variant, date formatted variant.  You only had one date formatted variant after the function.

I am very interested in you and other members of this forum becoming as proficient programmers as you want to be!  To give you a little more help on the "datediff" function, I wrote a new and improved demo brain and it is attached.

However, I also ask that you eyeball the code and see if it makes sense to you.  I added a LOT more annotation remarks than I usually do, so I would like your feedback.

The section of demo code follows below, and it is also in the new attached demo brain.  The demo brain will compliment the user for responding quickly, make a remark in seconds-units for waits over 20 seconds, make a remark in minutes-units for waits over 2 minutes, and make a remark in hours-units for waits over 2 hours.  I specifically wrote this for you to analyze and hopefully enjoy!

Here is the code section:

'-----------------------------

'BEGIN SPECIAL DEMO AREA FOR QUALIFIED DATEDIFF
'
'THIS IS A DEMONSTRATION OF THE "DATEDIFF" FUNCTION.
'THE FIRST ARGUMENT AFTER DATEDIFF
'TELLS THE FUNCTION WHAT UNITS TO USE.
'USE "S" FOR SECONDS, "D" FOR DAYS.
'THE SECOND AND THIRD ARGUMENTS MUST BE VARIANTS IN DATE FORMAT.
'(CERTAIN FUNCTIONS REQUIRE ARGUMENTS IN PARENTHESIS
'AND SEPARATED BY COMMAS TO WORK,
'AND "DATEDIFF" IS ONE OF THEM.)
'THE DATEDIFF FUNCTION RETURNS A NUMBER EQUAL TO THE
'DIFFERENCE BETWEEN THE SECOND AND THIRD ARGUMENTS PRESENTED TO IT.
'ALL POSSIBLE ARGUMENTS ARE LISTED IN THE "VBS IN A NUTSHELL" BOOK!

'First we prevent error messages by making sure that
'our variant "LastResponseTime" is actually
'in date format.  We do this by
'testing whether the variant "LastResponseTime" is
'equal to the date format, using the function "IsDate."

'If the answer it true, we don't need to do anything.
'If the answer is false, we'll initialize the value
'of "LastResponseTime" to the computer's system time,
'which is the function "Now".

If IsDate(LastResponseTime) = False Then LastResponseTime = Now

'Next we'll obtain the number of seconds since the
'last exchange with the user.  We do this using
'the "DateDiff" function and the required
'arguments that pertain to that function,
'and we create a variant named "HowLongBeen"
'to hold the number of seconds:

HowLongBeen = DateDiff("s", LastResponseTime, Now)

'Now we give Hal something to say as a "default":

GetResponse = "It's nice when you respond to me quickly."

'Next we do a little simple math to see if the wait
'has been greater than 20 seconds:

If HowLongBeen > 20 Then BeenLongTime = True

'Now we give Hal an impatient thing to say, if the variant
'we called "BeenLongTime" is "True"!

If BeenLongTime = True Then
    GetResponse = "It has been " & HowLongBeen & " seconds since you spoke!"
End If

'Now, suppose that we wanted a special remark if the wait has been
'more than two minutes!  Examine and analyze the code below:
'(Remember that the "Int" function returns an integer with
'any decimal places simply dropped, not rounded.)

HowManyMinutes = Int(HowLongBeen/60)
If HowManyMinutes > 1 Then
    GetResponse = "It has been over " & HowManyMinutes & " minutes since you last spoke to me, and that is too long! "
End If

'Now, suppose that we wanted a special remark if the wait has been
'more than two hours!  Examine and analyze the code below:

HowManyHours = Int(HowManyMinutes/60)
If HowManyHours > 1 Then
    GetResponse = "It has been over " & HowManyHours & " hours since you last spoke to me, and that is way, way, way too long <UserName>!"
End If

'Finally we record the new time for the next round:

LastResponseTime = Now

'That completes this demo routine.


'------------------------------------------------------------------

Have a great day, and let me know if this makes this particular function and routine clear!

Sincerely,

Don

Download Attachment: Date Difference Qualified Demo.uhp
12.35 KB
« Last Edit: October 26, 2003, 01:13:04 am by Don Ferguson »
Don Ferguson
E-mail: fergusonrkfd@prodigy.net
Website: www.cortrapar.com
Don's other forum posts: http://www.zabaware.com/forum/search.asp?mode=DoIt&MEMBER_ID=274

Ponnfar

  • Full Member
  • ***
  • Posts: 149
    • View Profile
    • http://zabaware.com
A question for Don F.
« Reply #3 on: October 26, 2003, 01:28:13 am »
Dude! you have Definitely earned some mucho cool points! I will download and keep you posted!!
Thanks!
P
One Person can summon the future...