School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 339,903 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,544 people online right now. Registration is fast and FREE... Join Now!



Timed random quote from a text file

Timed random quote from a text file I'm scripring with MSAgent Rate Topic: -----

#1 Tw@in 28  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 4
  • Joined: 19-January 09


Dream Kudos: 0

Post icon  Posted 19 January 2009 - 02:18 PM

Hello there!
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 :rolleyes: ).

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))

:crazy:


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.... :P

This post has been edited by Tw@in 28: 19 January 2009 - 02:19 PM

Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month