random line from file
Moderators: Dorian (MJT support), JRL
random line from file
hi!
i just started out doing some stuff with macros and need a function to work properly..
I´m tryin to read a random line from a file called question.ini and return the value of that random line, the function i have malfunctions sometimes and returns a strange value
in the macro i use
ReadIniFile>C:\random\question.ini,a,k
and then
Message>k
but sometimes it returns a,k
Can someone help me out with doing a correct random function?
Best regards
Jack
i just started out doing some stuff with macros and need a function to work properly..
I´m tryin to read a random line from a file called question.ini and return the value of that random line, the function i have malfunctions sometimes and returns a strange value
in the macro i use
ReadIniFile>C:\random\question.ini,a,k
and then
Message>k
but sometimes it returns a,k
Can someone help me out with doing a correct random function?
Best regards
Jack
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
You could use VB to generate a random number. Something like this:
Sample here generates from 00-99 with other lines provided as examples. Now you can use that number to generate a line number. Modify RND formula as needed to get the range of numbers that you want.VBSTART
Function NewNumber()
Randomize
'NewNumber =RND() 'Random 15 decimal number
'NewNumber =Int((RND*9)+1) 'Random number from 1 to 9
'NewNumber =Int(RND*10) 'Random number from 0 to 9
NewNumber =Int(RND*100) 'Random number from 00 to 99
End Function
VBEND
VBEVAL>NewNumber(),NewNumber
Message>%NewNumber%
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
Or you can use Macro Scheduler's own Random command:
Random>100,RndLineNumber
Random>100,RndLineNumber
MJT Net Support
[email protected]
[email protected]
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
Console utilities for Win32. These are Unix-like utilities to be used from the command line in a DOS box. They are true Win32 applications:
Count: Count bytes, characters, letters, vowels, consonants, words, lines sentences, words per sentence and letters per word.
Cpy: Copy and updates files. Enhanced xcopy command.
Cut: Extract some columns, rows, fields or bytes from a file.
Detab: Substitute spaces for Tabs.
Entab: Substitute Tabs for spaces.
FileComp: Compare lines from files.
Head: Dump the first few lines or characters of a file.
Paste: Merge lines from different files.
Sort: Enhanced sort and merge utility.
Tail: Dump the last few lines or characters of a file.
Trail: Fix end of lines.
Uniq: Delete repeated lines.
[Download]
----
Of course, you could do a line count and afterwards read the last detected line.
Count: Count bytes, characters, letters, vowels, consonants, words, lines sentences, words per sentence and letters per word.
Cpy: Copy and updates files. Enhanced xcopy command.
Cut: Extract some columns, rows, fields or bytes from a file.
Detab: Substitute spaces for Tabs.
Entab: Substitute Tabs for spaces.
FileComp: Compare lines from files.
Head: Dump the first few lines or characters of a file.
Paste: Merge lines from different files.
Sort: Enhanced sort and merge utility.
Tail: Dump the last few lines or characters of a file.
Trail: Fix end of lines.
Uniq: Delete repeated lines.
[Download]
----
Of course, you could do a line count and afterwards read the last detected line.
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
No time to provide all code right now, but you can use FIND with the TYPE command to get the number of lines in a file.
Redirect the output to a file. Read that file to get the Line Count.
Then you can do ReadLn> as Lumumba suggested, with the line count from the earlier steps.
Operates almost instantly, no need to run through all lines in a file.
Here are abbreviated primary line samples using variables:
Redirect the output to a file. Read that file to get the Line Count.
Then you can do ReadLn> as Lumumba suggested, with the line count from the earlier steps.
Operates almost instantly, no need to run through all lines in a file.
Here are abbreviated primary line samples using variables:
Hopefully this will be enought to get you started.Run Program>C:\WINNT\System32\cmd.exe /c find /c /v "%Seek2%" %Source%>>%CountFile%
ReadLn>%CountFile%,2,Result
//From Lumumba:
ReadLn>%Source%,%Result%,line
Message>Macro Scheduler proudly present the last line:%CRLF%line
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!