Source language: Translate to:

Load

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Load

Postby Neobook » Sun Feb 11, 2007 7:39 am

Hi,

I have a Numbers.txt where there are a lot of numbers for example :

35654
13789
23455
08769
23456
45645


So, I want to load one of in the variable [Num]

I tried this but it's not working :

FileToVar "C:\Numbers.txt" "[k]"
StrParse "[k]" "[#34]" "" "[jhk]"
Random "[jhk]" "[gt]"

It telled me 0 or 1, I want a number (45645 for example).



Thanks


Alex
Neobook
 
Posts: 131
Joined: Sat Jul 01, 2006 7:07 am

Postby Sam Cox » Sun Feb 11, 2007 7:53 am

This will do the job:
Code: Select all
SetVar "[File]" "C:\Numbers.txt"
FileLen "[File]" "[LineCount]"
Random "[LineCount]-1" "[R]"
FileRead "[File]" "[R]+1" "[Num]"

It works by reading just one randomly selected line from the file.
User avatar
Sam Cox
 
Posts: 768
Joined: Fri Apr 01, 2005 7:30 am
Location: Loveland CO USA

Postby Neobook » Sun Feb 11, 2007 8:01 am

Thank you Sam Cox
Neobook
 
Posts: 131
Joined: Sat Jul 01, 2006 7:07 am

Postby Gaev » Sun Feb 11, 2007 8:11 am

NeoBook:
So, I want to load one of in the variable [Num]

I tried this but it's not working :

FileToVar "C:\Numbers.txt" "[k]"
StrParse "[k]" "[#34]" "" "[jhk]"
Random "[jhk]" "[gt]"

a) Where is [Num] in your posted code ? ... how did you expect the code to update [Num] ?

b) What do you expect this command to do ? ...
Code: Select all
StrParse "[k]" "[#34]" "" "[jhk]"

According to the (English) Help file for this command ...
StrParse

Purpose: Separate a string into multiple parts using a delimiter character.
Syntax: StrParse "source string" "delimiter" "array variable" "count variable"

You are using [#34] as the delimiter ... [#34] is code for the space character ... if your Numbers.txt file contains each of the numbers on a new line, your delimiter would be "[#13][#10]"

c) If you had used "[#13][#1] as your delimiter, [jhk] would tell you how many arrayed items were created during the parsing of the string ... if you then apply the Random command on this value, [gt] would contain a random numner between zero and the count [jhk] ... which is not what you are looking for.


Perhaps you should search this forum for solutions to your problem that have been asked (and solved) endless times before ... if you can't find them, take a look at the help file for these commands ...

FileSize
Random
FileRead

... you should then be able to

- get the size (count of numbers/lines) in your file
- get a random number between 1 and this size (note: Random command works between 0 and specified value)
- read into [Num] the line corresponding to the result of your Random command
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby Neobook » Sun Feb 11, 2007 8:13 am

Thanks Gaev
Neobook
 
Posts: 131
Joined: Sat Jul 01, 2006 7:07 am


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 2 guests