By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,057 Members | 1,407 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,057 IT Pros & Developers. It's quick & easy.

Reading files by line number

P: 99

I am developing a fun TTS program and I've run into a bit of a problem.

Basically I am bringing in a list of sentences into a database and randomly selecting them, at the same time keeping a database of sentences that have already been used until all of them have been used and then it resets itself. The problem is, 1. I don't like loading these all into an array because of memory purposes. 2. I don't want to have a limitation on how many sentences I can use which is currently 1000 for memory sake. Any advice on this? Code is below

Expand|Select|Wrap|Line Numbers
  1. 'This is the randomizer for random phrases
  3. 'If no phrases are found, exit.
  4. If RandCount <= 0 Then
  5.     Speak "I have nothing to say."
  6.     Exit Function
  7. End If
  9. 'Resets the count if all phrases have been used.
  10. If LastCount > RandCount Then
  11.     For LastLoop = 1 To 1000
  12.         LastPhrase(LastLoop) = ""
  13.     Next LastLoop
  14.     LastCount = 1
  15. End If
  17. 'Randomizes phrases and makes sure no repeats happen.
  19.     Randomize
  20.     RandGen = Int(Rnd * RandCount + 1)
  21.     If RandGen = 0 Then GoTo RANDPHRASE
  22.     If RandCount > 10 Then
  23.         For LastLoop = 1 To 1000
  24.             If RandomPhrase(RandGen) = LastPhrase(LastLoop) Then
  25.                 GoTo RANDPHRASE
  26.             End If
  27.         Next LastLoop
  28.     End If
  29.     Speak RandomPhrase(RandGen)
  30.     RepeatPhrase = RandomPhrase(RandGen)
  31.     If RandCount > 10 And LastCount <= 1000 Then
  32.         LastPhrase(LastCount) = RandomPhrase(RandGen)
  33.     End If
  34.     LastCount = LastCount + 1
Dec 22 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 5K+
P: 8,434
Sorry you don't seem to be getting any response to your question. What version of VB are you using?

In any case, perhaps the easiest thing would be to leave your sentences in the database, and just retrieve them one at a time. Your array need only hold the key value (or bookmark value, perhaps) for each sentence. This will make the memory usage much smaller.

By the way, how much RAM do you have? I wouldn't generally expect a few Mb to be much of an issue these days.
Dec 29 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.