dupa

Author Topic: What's for lunch  (Read 4427 times)

lostbowyer

  • Full Member
  • ***
  • Posts: 105
    • View Profile
What's for lunch
« on: September 02, 2003, 05:09:54 pm »
Where does hal call the date/time function? Can that variable be entered into memory, or or called and compared?

While editing the pesonal question brain file created in Larry's script, I happened to think that it would be easy to add a subroutine so if a person asks hal for example "what are you having for lunch" the script would create a keyword by appending for example "lunch" with a random number from 1 to 10 and then searching a lunch brainfile for let's say "lunch7" and return whatever lunch number 7 might happen to be.

Now if I take that one step further, if I can pull in the day/date and can compare it, then I could have for example "thursdaylunch7" or "tuesdaylunch3" and one step further, comparing the time can return either "thursdaylunch7" or "thursdaydinner7" depending upon the time of day. All we need is the ability to access the time and date and compare it.
 

Don Ferguson

  • Sr. Member
  • ****
  • Posts: 303
    • View Profile
    • http://www.cortrapar.com
What's for lunch
« Reply #1 on: September 02, 2003, 11:00:08 pm »
Hello,

The following line of code would create a variant named "TestVariant01" and make it equal to the computer's current date:

TestVariant01 = Date

VBS has the ability to add dates, calculate the differences between dates, return numbers equal to the number of seconds since midnight, and many other handy things!  

Date-related VBS functions which can be called by name include the following:

Date
DateAdd
DateDiff
DatePart
DateSerial
DateValue
Day
Hour
Minute
Month
MonthName
Now
Second
Time
Timer
TimeSerial
TimeValue
Weekday
WeekdayName
Year

Some of these built-in VBS functions require you to provide "arguments" after them, in the right syntax, to make them work.  Others just work all by themselves, as does "Date."  These functions are all described in detail in the book I've recommended in several other postings, "VBScript in a Nutshell," published by O'Reilly.

Experiment, or if you can, get the book!  It really helped me!

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

lostbowyer

  • Full Member
  • ***
  • Posts: 105
    • View Profile
What's for lunch
« Reply #2 on: September 03, 2003, 10:22:19 am »
Don
Thanks for the information, my mind was out in left field and never gave it a thought to get it directly through VB Duh!

Glenn
 

lostbowyer

  • Full Member
  • ***
  • Posts: 105
    • View Profile
What's for lunch
« Reply #3 on: September 03, 2003, 12:34:05 pm »
Here's my first draft, it seems to be working fine. I'm going to try and attach a sample meals brain file. It has 9 choices for each meal (lunch and dinner) for the 7 days of the week. Most choices are currently the same as I cut and pasted to create the total entries required. Just edit the response lines with your favorite foods. There may be one bug, I'm not sure if my random number generator could produce a zero, if it can, then one more line needs to be added to each meal choice to accomodate the zero entry. I have not been able to produce a zero in my tests, but I'll keep checking and post if I do.

'What's for lunch
If InStr(1, UserSentence, " WHAT AM I HAVING FOR LUNCH ", 1) > 0 Then MyMeal = "lunch"
If InStr(1, UserSentence, " WHAT AM I HAVING FOR DINNER ", 1) > 0 Then MyMeal = "dinner"
If MyMeal = "lunch" Or MyMeal = "dinner" Then
RandomMeal = Int((Rnd * 10))
MyMeal = WeekdayName(Weekday(Date),True) & MyMeal & RandomMeal
HalUserBrain = HalBrain.QABrain(MyMeal, WorkingDir & "Meals" & ".brn", UserBrainRel)
GetResponse = HalUserBrain & vbCrLf
GetResponse = HalBrain.HalFormat(GetResponse)
End If

I hope you enjoy the script, if you cut and paste the above, note that the first 2 if statements line wrapped, make sure they are one line each after you paste.

Glenn

Download Attachment: Meals.brn
8.15 KB
 

lostbowyer

  • Full Member
  • ***
  • Posts: 105
    • View Profile
What's for lunch
« Reply #4 on: September 03, 2003, 05:10:58 pm »
The random number generator will produce a "0" afterall. The Meals.brn file will need one entry added for each day, lunch and dinner with the keywords "MONLUNCH0" "TUELUNCH0" etc....

I'm out of time today, I'll post an updated Meals.brn tomorrow with the additional 14 menu selections.

Glenn

PS The program does not error out if it generates the "0" it just doesn't return a meal.
 

lostbowyer

  • Full Member
  • ***
  • Posts: 105
    • View Profile
What's for lunch
« Reply #5 on: September 03, 2003, 05:32:25 pm »
I needed to make a slight fix to the script. It has been corrected below.
A slight addition to the script, if you ask hal what he had for lunch and it's after noontime, hal will tell you he's eaten but also tell you what he plans to eat for dinner.

'What's for lunch
If InStr(1, UserSentence, " WHAT AM I HAVING FOR LUNCH ", 1) > 0 Then MyMeal = "lunch"
GetResponse = ""
If MyMeal = "lunch" And Hour(Time) > 12 Then
MyMeal = "dinner"
GetResponse = "I've already eaten lunch, but for dinner, "
End If
If InStr(1, UserSentence, " WHAT AM I HAVING FOR DINNER ", 1) > 0 Then MyMeal = "dinner"
If MyMeal = "lunch" Or MyMeal = "dinner" Then
RandomMeal = Int((Rnd * 10))
MyMeal = WeekdayName(Weekday(Date),True) & MyMeal & RandomMeal
Timeday = Hour(Time)
HalUserBrain = HalBrain.QABrain(MyMeal, WorkingDir & "Meals" & ".brn", UserBrainRel)
GetResponse = GetResponse & HalUserBrain & TimeDay & MyMeal & vbCrLf
GetResponse = HalBrain.HalFormat(GetResponse)
End If

Here is an updated Meals.brn it has the "0" choices added. You still have to customize your food preferences but it is a complete.

Download Attachment: Meals.brn
8.78 KB
« Last Edit: September 04, 2003, 10:08:11 am by lostbowyer »
 

Larry

  • Sr. Member
  • ****
  • Posts: 266
    • View Profile
What's for lunch
« Reply #6 on: September 15, 2003, 12:29:52 pm »
quote:
Originally posted by Don Ferguson

Date-related VBS functions which can be called by name include the following:

Date
DateAdd
DateDiff
DatePart
DateSerial
DateValue
Day
Hour
Minute
Month
MonthName
Now
Second
Time
Timer
TimeSerial
TimeValue
Weekday
WeekdayName
Year

Some of these built-in VBS functions require you to provide "arguments" after them, in the right syntax, to make them work.  Others just work all by themselves, as does "Date."  



Don, Is there a web site with a quick ref of these things?
Of course I'm working on something...
quote:
'PROCESS: RECORD TIME
'Record the current time, so Hal knows the time in between sentences.
LastResponseTime = Now

I've done a search, and this is the only place LastResponseTime is used... I'd like to further this little gem...