Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > random message generator


Reply
 
Thread Tools Display Modes
  #1  
Old 09-12-2000, 12:25 AM
mojo
Guest
 
Posts: n/a
Question random message generator


I want to make a small random message generator. The messages can either me part of the code or better still, seperate in a text file.

Where to start?

ps I have searched the forums, but most posts seem to about random numbers.

Thanks mojo


Reply With Quote
  #2  
Old 09-12-2000, 03:36 AM
ruti_gl
Guest
 
Posts: n/a
Smile Re: random message generator

Who prevents you from creating message string array, which
elements according to their indexes you will process like
random numbers?

Good Luck!

Ruth Glushkin

Reply With Quote
  #3  
Old 09-12-2000, 11:43 AM
usetheforce2's Avatar
usetheforce2 usetheforce2 is offline
Senior Contributor

Retired Moderator
* Expert *
 
Join Date: Jul 2000
Location: Toronto, Ontario, Canada
Posts: 1,410
Smile Re: random message generator

an easy way to do that, would be as the previous post'r suggested, create an array(depending on how many messages, and how long you want them) then just call the different messages randomly

you could have a sql txt file and line input each line into different elements of the array. such as

in note pad just open a file and type somelines into it(as many as you want, hit return at the end of each linek)
save the file as File.txt in the app directory, then put this code into your form load
------------form load---------------
dim RandomString() as String
dim Counter as integer
open app.path + "File.txt" for input as #1
do while not eof(1)
redim preserve RandomString(counter)
line input #1, randomstring(counter)
counter = counter + 1
loop
close #1
-------------------------------------------------------
now that you have random messages in you array, you can call them

place this code into a command button
----------command1_click------------------
randomize
dim RandomNumber as integer
RandomNumber = 1 to (counter - 1) * rnd + 1
label1 = randomstring(randomnumber)
----------------------------------------------

i'm at school right now, and i haven't tested it it should work though (my appologies if it doesn't) feel free to email me if you have any question.

ps
i;m sure if i miss anything one of the other fine gentlemen
will correct my mistake.

Regards
Regan DeDiana

__________________
winsock siteHERE||EliteVBHERE||C++ & VB Markup UtilityHERE
Reply With Quote
  #4  
Old 09-12-2000, 01:34 PM
Dazz
Guest
 
Posts: n/a
Smile Re: random message generator

All looks ok to me, the only thing that I would add is that when you use 'Randomize' it creates a random number against a predefined seed. Because of this every time you run the code you would get the same sequence of returns, an idea may be to 'Randomize Timer' instead. This way you will get different results each time the code is run.

Hope it help!
Live2Give
Reply With Quote
  #5  
Old 09-14-2000, 12:40 AM
mojo
Guest
 
Posts: n/a
Default Re: random message generator

For some reason it gives me a Syntax error at the line

RandomNumber = 1 to (counter - 1) * rnd + 1

Any ideas?

Reply With Quote
  #6  
Old 09-14-2000, 04:39 AM
ruti_gl
Guest
 
Posts: n/a
Smile Re: random message generator

To which value your counter is equal?
If 0, it may be a problem.
Another problem could be in type,
if it is not number value, so how
have you declared it?
Or, maybe, you forgotten to declare it
at all?

Send the whole subroutine,
because it is not good to suggest.

With Full Respect,

Ruth Glushkin


Reply With Quote
  #7  
Old 09-14-2000, 02:03 PM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default Re: random message generator

I think whoever wrote this meant it as pseudocode rather than actual code.

Try:
RandomNumber = cint(counter * rnd())

where:
counter is the number of entries in your array and your array is zero based. This line will return a random value of RandomNumber that is between counter-1 and 0. Incidentally, the counter variable must be declared at the module level rather than procedural level.

"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #8  
Old 09-14-2000, 04:26 PM
usetheforce2's Avatar
usetheforce2 usetheforce2 is offline
Senior Contributor

Retired Moderator
* Expert *
 
Join Date: Jul 2000
Location: Toronto, Ontario, Canada
Posts: 1,410
Default Re: random message generator

sorry about the errors, did this at school just copy paste this into you app.
add one label1
add a command1
--------cut here---------------
Option Explicit
Dim RandomString() As String
Dim Counter As Integer
Dim RandomNumber As Integer
Private Sub Command1_Click()
Randomize
RandomNumber = (Counter - 1) * Rnd + 1
Label1 = RandomString(RandomNumber)
End Sub

Private Sub Form_Load()
Open App.Path + "File.txt" For Input As #1
Do While Not EOF(1)
Counter = Counter + 1
ReDim Preserve RandomString(Counter)
Line Input #1, RandomString(Counter)
Loop
Close #1
End Sub
------------------cut here-----------
just make sure to add a file in the directory call file.txt
enter some lines of whatever you want hit enter at the end of each line
that's it

sorry agian, it hard to get good help these days, "isn't it"

take care:
Regan DeDiana


__________________
winsock siteHERE||EliteVBHERE||C++ & VB Markup UtilityHERE
Reply With Quote
  #9  
Old 09-15-2000, 12:45 AM
mojo
Guest
 
Posts: n/a
Default Re: random message generator

Thanks

I'll try it out when I get home tonight (if I can tear myself away from the Olympic Opening Ceremony, sarcasm intended).

Will let you know


Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->