Source language: Translate to:

Help with Random Text

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Re: Help with Random Text

Postby dpayer » Wed Jul 12, 2006 8:59 am

GaReb wrote:I have searched this site for help and found several useful posts, but I must have my stupid hat on, so I will probably need this spelled out verbatim for me. Sorry in advance :-)

Here is what I am TRYING to do.

I want to click on a button that will generate random words from a text file I have created into a text box on my application.

Please feel free to email me. I will need this spelled out and shown to me EXACTLY what it should look like.

Thanks
Jay


I am not good at doing "exact" descriptions because then I would need to write the app for you. Here is how I would approach it.

1) get a list of acceptable words. Find a dictionary somewhere that is open source which you can use.

2) You say "text file" so I cannot assume it is words but just a bunch of letters.

3) Count how many of each letter of the alphabet is in your text file. You would use the string functions of NB. Summarize your totals

4) Start utilizing the largest words of your dictionary and work down from there. From the list of letters, see if the list of letters in the words can be matched in the larger text file, if so, use that word and subtract the number of each letter from the totals you generated earlier

5) When you get to the end, you may have some letters left over but a list of acceptable words as well!

Is this the right concept?

D
User avatar
dpayer
 
Posts: 1380
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Postby dpayer » Wed Jul 12, 2006 9:10 am

GaReb wrote:No I already have a list of words that I want to use saved as a txt file. I want to click on a button and have those words show up, at random, in a text field on my application.


OK.

Create an array filled with the words. Determine the number of entries. Select a random number between 1 and the number of entries. Insert the word associated with the random number entry.

This is the direction you are looking for?

D
User avatar
dpayer
 
Posts: 1380
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Postby Cipolla » Wed Jul 12, 2006 9:13 am

Hello GaReb and welcome to the forum.

I will need this spelled out and shown to me EXACTLY what it should look like.

First of all, i don´t think you will find someone here who is willing to
programm all details or let´s say who does the complete work for you.
I tell you that because i understand your question like that.

Here is a short tipp to start:

If your textfile looks like this:

Text1
Text2
Text3
...

Use this script:

Put this i.e. in the page entry actions:
Code: Select all
FileRead "textfile.txt" "All" "[AllWords]"


...and this in a button:

Code: Select all
.Parse the whole file into array (delimiter is carriage return = [#13][#10]
StrParse "[AllWords]" "[#13][#10]" "[RandomWords]" "[NumberOfWords]"
.Get the random number here between 0! and all words
Random "[NumberOfWords]" "[Number]"
.Because we don´t need the 0 check it here
If "[Number]" "=" "0"
 SetVar "[Number]" "1"
EndIf
SetVar "[Result]" "[RandomWords[Number]]"


Now place the variable [result] in the textbox.

If you push the button the random word will be shown in the textbox. It is the content of the var [Result].

If your textfile looks like this:

"This is a textfile with some words in it..."

use a blank for the delimiter instead the carriage return.

Btw. i couldn´t test it yet, but i think this should work.
Greetings from Germany
Klaus
User avatar
Cipolla
 
Posts: 166
Joined: Fri Apr 01, 2005 1:45 am
Location: Germany

Postby Cipolla » Wed Jul 12, 2006 1:32 pm

GaReb,

i dont want you understanding me wrong. Here are a lot of people, including me, who are really willing to help where they can.

But, it is really importand for you to understand the basics of neobook scripting and how this programm works.

- Do I need to put a link in showing where the file is on my computer?


This is what i mean. Of course you need to specify where your file is located on your harddisk. This could also be the path where your publication is saved. But as i said, this are the basics!

The command could look like this:
Code: Select all
FileRead "c:\mypath\textfile.txt" "All" "[AllWords]"

or
Code: Select all
FileRead "[pubdir]textfile.txt" "All" "[AllWords]"

and [pubdir] means neobook is looking in the working directory of your app for the file. Both are basics!

Also what do I put in the brackets here?


Please use the tutorials comming with your neobook copy. There you will learn how to use variables (wich are named between the brackets).

So i hope you see, that my first post was not to cross you.
Please, make a new publication, place a button and a text object on it.

The copy & paste the code for the button and place it in the buttons action section.

Copy the script for the FileRead into the page entry action. Then double click the FileRead command. Then you can specify the location of your textfile.

Finaly write the variable [Result] (with brackets) in the textBox as the content.

Then run your application and press the button. When everything is right after every button press you should see another random text displayed in the textbox.

After this is working study the script to learn how this works. Including the help file and the tutorials.
Greetings from Germany
Klaus
User avatar
Cipolla
 
Posts: 166
Joined: Fri Apr 01, 2005 1:45 am
Location: Germany

Postby Wrangler » Sun Jul 16, 2006 8:05 am

FileLen "MyTextFile.txt" "[NumOfLines]"
Random "[NumOfLines]" "[RandomNumber]"
FileRead "MyTextFile.txt" "[RandomNumber]" "[ReadWord]"


This will work, but there is nothing in place to prevent duplicates. If you have a text file with 10 lines, the odds are you will get a duplicate, or the same number twice in a row. You would need a setvar to record the last number randomly chosen, and check it against the next number chosen. If it is the same as the last, randomly select another one until it is different. If you wanted NO duplicates period, you could write the chosen number to a text file, read it for comparison, and then delete the file when all 10 numbers have been used, and start over again.
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1505
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA

Postby Alberto_Meyer » Sun Jul 16, 2006 8:58 am

You have to create an array to put the alredy sorted numbers after the randomize.

Create an array of words
Create an array to store the results

Randomize

search in array for that number
if yes
randomize
else
put an array
verify if the randomize ends
randomize again

I think that is
User avatar
Alberto_Meyer
 
Posts: 385
Joined: Tue May 03, 2005 5:14 am


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest