Source language: Translate to:

Displaying Contents of 2 Text Files in One Text Object

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Displaying Contents of 2 Text Files in One Text Object

Postby DantesGame » Fri Nov 28, 2014 10:43 pm

Hi all,

After a VERY long hiatus from NeoBook I've dusted off the program, purchased a spanky new upgrade, and have started to re-read the Help files, forums, and anything I can set my eyeballs to. The current challenge I'm trying to work through is how to pull two random values from two text files. File 1 is "first_names.txt" and File 2 is "last_names.txt". I want to have a single button that grabs a random first name and a random last name and displays them both in a Text Object.

I know how to do this with just one of the files. Here's how I'm currently accomplishing that:

Book | Book Properties | Actions
SetVar "[FirstNames]" "[PubDir]\first_names.txt"
SetVar "[LastNames]" "[PubDir]\last_names.txt”
FileLen "[FirstNames]" "[FirstNamesLen]"
FileLen "[LastNames]" "[LastNamesLen]"
Math "[FirstNamesLen]-1" "0" "[File12Max]"
Math "[LastNamesLen]-1" "0" "[File21Max]"

Button Object
Random "[File12Max]" "[File12Random]"
Math "[File12Random]+1" "0" "[File12Line]"
FileRead "[FirstNames]" "[File12Line]" "[FirstNameText]"

Text Object
[FirstNameText]

What I'm stuck on is how to pull from the second file and parse/concatenate the result to the FirstNameText holder. I've tried sticking the random results in a variable and pulling that down but couldn't get that working. Any help would be greatly appreciated.
DantesGame
 
Posts: 29
Joined: Sun Jun 08, 2008 1:15 pm

Re: Displaying Contents of 2 Text Files in One Text Object

Postby HPW » Sat Nov 29, 2014 12:22 am

Something like this:

Button Object
Random "[File12Max]" "[File12Random]"
Math "[File12Random]+1" "0" "[File12Line]"
FileRead "[FirstNames]" "[File12Line]" "[FirstNameText]"
Random "[File21Max]" "[File21Random]"
Math "[File21Random]+1" "0" "[File21Line]"
FileRead "[LastNames]" "[File21Line]" "[LastNameText]"
SetVar "[FinalNameText]" "[FirstNameText] [LastNameText]"
Hans-Peter
User avatar
HPW
 
Posts: 2516
Joined: Fri Apr 01, 2005 11:24 pm
Location: Germany

Re: Displaying Contents of 2 Text Files in One Text Object

Postby DantesGame » Sat Nov 29, 2014 9:48 am

Hans-Peter,

Thank you so much for the quick response and the help. This worked beautifully. I did something very similar but now I see where I went wrong; the arrangement of the elements was out of order.

I tried it like this:

SetVar "(WholeName)" '[FirstNameText] [LastNameText]"
Random (for the first file)
Random (for the second file)
Math (for the first file)
Math (for the second file)
FileRead (for the first file)
FileRead (for the second file)

The result I kept getting was that the button would only read the second file. Now I know why and see how close I was!

Thanks again.

-Efrem
DantesGame
 
Posts: 29
Joined: Sun Jun 08, 2008 1:15 pm


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 2 guests