Jump to content

Recommended Posts

Posted

Hello everyone!

I have a new task that I would like help with. I would like to read random text into a GUI lable that scrolls and repeats with a different line from the text. It does grab different lines from the file, but only one and replays it. I have picked and gleened information from other people's posts. Thnaks everyone for unknowingly helping me so far!

Please let me know how to fix this...

#include <windowsconstants.au3>
#include <StaticConstants.au3>
#include <SendMessage.au3> ;Needed for _SendMessage function.
#include <ProgressConstants.au3>
#Include <File.au3>

global $Count = _FileCountLines(@scriptdir & "\randomText.txt")
global $file = FileOpen(@scriptdir & "\randomText.txt")

global $line = FileReadLine($file, int(random(1, $count)))

$gui = GUICreate("demo ")
$ch = GUICreate("",100,30,20,80,$WS_CHILD,-1,$gui)
GUICtrlCreateProgress(15, 15, 400, 20, $PBM_SETMARQUEE)
_SendMessage(GUICtrlGetHandle(-1), $PBM_SETMARQUEE, True, 50) ; final parameter is update time in ms
$lbl = GUICtrlCreateLabel($line,0,0)
GUISetState(@SW_SHOW,$gui)
GUISetState(@SW_SHOW,$CH)
AdlibRegister("slide",50)
Global $px = 0
while 1
    if GUIGetMsg() = -3 then Exit
WEnd


func  slide()
    $px -= 1
    GUICtrlSetPos($lbl,$px,0)
    if $px < -250 then $px = 400

EndFunc

"so much work, so little brains..."

Posted

Thanks for your reply. I guess I don't understand how to select and show more lines? What do I need to change?

"so much work, so little brains..."

Posted

You need to make it so that the label text is changed after your label is done "sliding".

#include <windowsconstants.au3>
#include <StaticConstants.au3>
#include <SendMessage.au3> ;Needed for _SendMessage function.
#include <ProgressConstants.au3>
#Include <File.au3>

Opt("MustDeclareVars", 1)

Global $filename = @ScriptDir & "\randomText.txt"
Global $lines
_FileReadToArray($filename, $lines) ;read text file into array
If @error Then
    MsgBox(0x2000, "Error", "Unable to process text file!")
    Exit
EndIf

SRandom(TimerInit()) ;set seed of random number generator
Global $line = $lines[Random(1, $lines[0], 1)] ;select random array element as text
Global $gui = GUICreate("demo ")
Global $ch = GUICreate("",100,30,20,80,$WS_CHILD,-1,$gui)
GUICtrlCreateProgress(15, 15, 400, 20, $PBM_SETMARQUEE)
_SendMessage(GUICtrlGetHandle(-1), $PBM_SETMARQUEE, True, 50) ; final parameter is update time in ms
Global $lbl = GUICtrlCreateLabel($line,0,0)
GUISetState(@SW_SHOW,$gui)
GUISetState(@SW_SHOW,$ch)
AdlibRegister("slide",50)
Global $px = 0

While 1
    If GUIGetMsg() = -3 Then Exit
WEnd

Func Slide()
    $px -= 1
    GUICtrlSetPos($lbl,$px,0)
    If $px < -250 Then
        $px = 400
        $line = $lines[Random(1, $lines[0], 1)]
        GUICtrlSetData($lbl, $line)
    EndIf
EndFunc

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...