ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Finished Programs

DONE: A script to display a random line from txt file

<< < (2/2)

dreats:
Hey it works. Better than I could ask for actually... ignoring lines without the syntax and everything.

I made a few little changes to the GUI to make it more windows-like.

Just one thing, could you add a little tag before the text, saying the real percentage, in 100% base denominator? So the text would read "[50%] foobar" instead of just "foobar"...

Thank you for this.


--- ---#NoTrayIcon

FileToRead = Todo.txt ;replace "FILE.txt" by the name of the file to read
Sum = 0
AutoTrim,Off
Loop, Read, %FileToRead%,,
{
  Flag=false
  Loop, parse, A_LoopReadLine, %A_Tab%
  {
    If Flag=true
      continue
    Sum +=%A_LoopField%
    Flag=true
  }
}
Random, Number, 1, Sum
Sum = 0
Line = 0
Loop, Read, %FileToRead%,,
{
  Line+=1
  Flag=false
  Loop, parse, A_LoopReadLine, %A_Tab%
  {
    If Flag=true
      If Sum>=%Number%
      {
Message=%A_LoopField%
        GoSub, Found
        Return
      }     
    Sum +=%A_LoopField%
    Probability=%A_LoopField% 
    Flag=true

  }
}
return
 
Found:
  Gui, Add, Picture, x11 y11 Icon5, user32.dll
  Gui, Add, Button, gSave x78 y66 w75 h23 +default,&OK
  Gui, Add, Button, gRetry x158 y66 w75 h23,&Retry
  Gui, Add, Button, gGuiClose x239 y66 w75 h23 , &Cancel
  Gui, Add, Edit, vNewProbability x10 y58 w32 h20 Limit4,%Probability%
  Gui, Font,  s12 w700, Verdana
  Gui, Add, Text, x61 y10 w327 h38,%Message%
  Gui, Show, xCenter yCenter h101 w395, RandomLine
Return

GuiClose:
ExitApp

Save:
  Gui,Submit
  FileRead,CompleteFile,%FileToRead%
  StringReplace,CompleteFileModified,CompleteFile,``n,`n,ReplaceAll
  StringReplace,CompleteFile,CompleteFileModified,%probability%%A_Tab%%message%,%NewProbability%%A_Tab%%message%
  FileDelete,%FileToRead%
  FileAppend,%CompleteFile%,%FileToRead%
  ExitApp

Retry:
Reload

jgpaiva:
I didn't quite understand what you meant, but please check if what you're looking for is something like this:

.exe version
.ahk version

dreats:
Precisely.

It is complete and working better than expected.

A BIG THANK YOU GOES TO JGPAIVA!

I'll be donating to the site later this week. What a great community.

jgpaiva:
You're welcome ;)

I'll be donating to the site later this week. What a great community.
-dreats (February 20, 2006, 05:05 PM)
--- End quote ---
:Thmbsup: :Thmbsup: :Thmbsup:

mouser:
jgpaiva, and all other people who write coding snacks and such:

set yourself up a little paypal button so that people can show their appreciation to you if you do little projects like this:
https://www.donationcoder.com/forum/index.php?topic=1283.0

it's wonderful when people donate to the site, but this forum is also about people donating to each other to help each other out, so you guys and gals should have a way to accept donations!

Navigation

[0] Message Index

[*] Previous page

Go to full version