I'm writing a small VB project just for fun: the idea is to realize a little app using MSAgent to throw up a random quote at a given interval, by reading them from a file (might even think about setting up a net repository for users to download the quotes from....but that's a long shot
Right now, I'm stuck at the random reading from my file.
Since I'm not yet familiar with the timer functions, I'm using a rightclick menu/"READ" option to read from a txt. I don't want to crypt anything, so it should be pretty straightforward to add new quotes manually to the textfile.
Here follows the code I wrote 'till now:
Private Sub Form_Load()
Form1.Hide
Dim CenterX As Long
Dim CenterY As Long
'Activate Merlin MSAgent'
CharPath = "j:\windows\msagent\chars\"
ctlAgent.Characters.Load "Merlin", "j:\windows\msagent\chars\merlin.acs"
Set Merlin = ctlAgent.Characters("Merlin")
Merlin.LanguageID = &H409 'set language for TTS functions'
Merlin.Show
With Screen
CenterX = Int((.Width / .TwipsPerPixelX) / 2)
CenterY = Int((.Height / .TwipsPerPixelY) / 2)
End With
Merlin.MoveTo CenterX, CenterY 'Merlin moves to the center of the screen....at least until I find a way of making him appear in the lower-right corner'
Merlin.Play "Wave"
Merlin.Speak "Hello there!"
Merlin.Play "Greet"
Merlin.Speak "I will be reading some random quotes"
Merlin.Play "Pleased"
Merlin.Speak "But to do that please right click me..."
Merlin.Play "GetAttention"
Merlin.Speak "and select the" + EMP + " read command."
Merlin.Play "Write"
Merlin.Speak "...Enjoy"
'Add Commands'
Merlin.Commands.Add "READ", "READ", "...READ...", True, True
Merlin.Commands.Add "EXIT", "EXIT", "...EXIT...", True, True
End Sub
'*******ENTERING THE ASSOCIATED RIGHTCLICK COMMANDS******'
Private Sub ctlAgent_Command(ByVal UserInput As Object)
Select Case UserInput.Name
Case "READ":
Set Merlin = ctlAgent.Characters("Merlin")
Dim txtline() As String 'Array for Text
Dim num As Integer 'random number
filepath = "J:\quotes.txt" 'temporary....should be App.Path + "\quotes.txt"
Open filepath For Input As #1
' inputs every line from file into an array
Do Until EOF(1)
ReDim Preserve txtline(x + 1)
Input #1, txtline(x)
x = x + 1
Loop
num = Int(x * rnd) + 1 ' random number between 1 and last index of array
Merlin.Speak (txtline(num)) ' gets that field from array
'can't make this to work....it seems something's wrong'
Case "EXIT":
End
Case Else:
Set Merlin = ctlAgent.Characters("Merlin")
Merlin.Play "Idle1_1"
End Select
End Sub
As you can see, what I really need is:
1rst: I need a little help with the arrays....it's the first program I write in VB, and I painfully reached this point to bang my head on a wall....basic'lly, I can't understand what's wrong with the lines above....debugger says "Run-time error -2147024809 (80070057)': incorrect parameter right at the line
Merlin.Speak (txtline(num))
my 2nd question is about the timers: since, as you read, I'd linke to get rid of the "Rightclick/READ" function, how do I specify my MSAgent to read a random quote every few minutes?
Hope someone can help me....
thanking in advance anyone contributing....
This post has been edited by Tw@in 28: 19 January 2009 - 02:19 PM

Start a new topic
Add Reply




MultiQuote
| 


