#112027 - 2004-01-19 07:27 PM
Random Quote Script
|
Sardis
Fresh Scripter
Registered: 2004-01-16
Posts: 28
Loc: Montgomery, AL
|
I'm attempting to alter my current company logon script to enable a messagebox to pop up with a random message in it. The message would be anything from a quote to a company wide piece of information. The messages would be in a seperate file for easy editing. Does anyone have a good way of going about this?
_________________________
Jason A King
|
|
Top
|
|
|
|
#112028 - 2004-01-19 07:30 PM
Re: Random Quote Script
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Code:
Function DisplayMessage($MessageFile) ; Displays a specific text message contained in a text file via a standard Windows dialog box. dim $RC, $x, $Line $x="" if Exist($MessageFile) if OpenFile(2,$MessageFile, 2) = 0 $Line=Readline(2) WHILE @ERROR = 0 $x=$x+$Line+@CRLF $Line=ReadLine(2) LOOP $RC=Close(2) $x=MESSAGEBOX($x,"Network Message",4160) endif else DebugLog("File Not Found: " + $MessageFile) endif Endfunction
|
|
Top
|
|
|
|
#112029 - 2004-01-19 07:35 PM
Re: Random Quote Script
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
see the Readfile() UDF and the Join() statement
|
|
Top
|
|
|
|
#112030 - 2004-01-19 07:45 PM
Re: Random Quote Script
|
Sardis
Fresh Scripter
Registered: 2004-01-16
Posts: 28
Loc: Montgomery, AL
|
This is fantastic, now could you explain what each part does?
_________________________
Jason A King
|
|
Top
|
|
|
|
#112031 - 2004-01-19 07:53 PM
Re: Random Quote Script
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Could you be more specific?
Are you asking about the UDF? See: How to write a UDF
The UDF checks for the existence of a a file. Then opens that file and reads the contents into a variable. Once the file is read the MessageBox function (see manual) is called. If the file does not exist, write that fact using the debuglog UDF which is not supplied.
|
|
Top
|
|
|
|
#112032 - 2004-01-19 07:59 PM
Re: Random Quote Script
|
Sardis
Fresh Scripter
Registered: 2004-01-16
Posts: 28
Loc: Montgomery, AL
|
Well, I can't seem to get your script to work. So I need to know what each line of code does to find out how I need to alter it to fit what I need it for.
_________________________
Jason A King
|
|
Top
|
|
|
|
#112033 - 2004-01-19 08:11 PM
Re: Random Quote Script
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
It would be very helpful if you posted the error(s) you are receiving and the version of KiXtart you are using. That way I could address specific issues. I would recommend you start with a test script that only contains the UDF and the call to the UDF. Run the test script in a DOS box so that any error remain on the screen after the script closes or teminates.
|
|
Top
|
|
|
|
#112034 - 2004-01-19 08:15 PM
Re: Random Quote Script
|
Sardis
Fresh Scripter
Registered: 2004-01-16
Posts: 28
Loc: Montgomery, AL
|
I don't get any errors, when I copied your script into my file and I run it, nothing happens. No popup, no error message, no nothing. I just don't know what I'm doing is the real problem.
_________________________
Jason A King
|
|
Top
|
|
|
|
#112036 - 2004-01-19 08:30 PM
Re: Random Quote Script
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
Sardis...Try this...
Code:
$null = DisplayMessage("C:\test.txt") ; CHANGE THE C:\test.txt TO WHATEVER FILE YOU WANT TO DISPLAY
Function DisplayMessage($MessageFile) ; Displays a specific text message contained in a text file via a standard Windows dialog box. dim $RC, $x, $Line $x="" if Exist($MessageFile) if Open(2,$MessageFile,2) = 0 $Line=Readline(2) WHILE @ERROR = 0 $x=$x+$Line+@CRLF $Line=ReadLine(2) LOOP $RC=Close(2) $x=MESSAGEBOX($x,"Network Message",4160) endif endif Endfunction
|
|
Top
|
|
|
|
#112037 - 2004-01-19 09:02 PM
Re: Random Quote Script
|
Sardis
Fresh Scripter
Registered: 2004-01-16
Posts: 28
Loc: Montgomery, AL
|
This code gives me the following error:
ERROR: expected expression Script: greeting.kix Line: 6
Any other ideas?
_________________________
Jason A King
|
|
Top
|
|
|
|
#112038 - 2004-01-19 09:05 PM
Re: Random Quote Script
|
Sardis
Fresh Scripter
Registered: 2004-01-16
Posts: 28
Loc: Montgomery, AL
|
Oh wait, nevermind, it worked, I was missing a Quotation mark. But now it isn't doing what I wanted it to. How do I make it pick a random quote from a list of quotes in this txt file?
_________________________
Jason A King
|
|
Top
|
|
|
|
#112040 - 2004-01-19 09:10 PM
Re: Random Quote Script
|
ShaneEP
MM club member
   
Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
|
Try This...
The first function enumerates all the lines of a text file into an array. I then use the random function to get a number between 0 and the highest element of the array. I then display this line number in a messagebox.
Code:
$Lines = ArrayEnumText("C:\test.txt") ; Change This To Your Text File $LineNumber = Random(0,UBound($Lines)) $null = messagebox ($Lines[$LineNumber],"",0)
FUNCTION ArrayEnumText($TextFile) Dim $TextHandle,$Line,$LineArray,$LineValue $TextHandle = FreeFileHandle() $LineValue = 0 If Open ($TextHandle,$TextFile) = 0 $Line = ReadLine ($TextHandle) While @Error = 0 ReDim Preserve $ArrayEnumText[$LineValue] $ArrayEnumText[$LineValue] = $Line $Line = ReadLine ($TextHandle) $LineValue = $LineValue+1 Loop $null = Close ($TextHandle) If UBound ($ArrayEnumText) >= 0 Exit 0 Else Exit 1 Endif Else Exit 1 Endif ENDFUNCTION
FUNCTION random($min, $max, optional $seed) DIM $i, $burn, $nul srnd((-1)*@ticks*(val($seed)+1)) $burn = rnd(50) for $i = 1 to $burn $nul = rnd($max) next $random = rnd($max) while $random < $min or $random > $max $random = rnd($max) loop ENDFUNCTION
|
|
Top
|
|
|
|
#112041 - 2004-01-19 09:18 PM
Re: Random Quote Script
|
Sardis
Fresh Scripter
Registered: 2004-01-16
Posts: 28
Loc: Montgomery, AL
|
Thanks Shane, I'll try that.
Les, if you don't want to help, you don't have to, but I'd appreciate it if you kept your snide comments to yourself.
_________________________
Jason A King
|
|
Top
|
|
|
|
#112042 - 2004-01-19 09:22 PM
Re: Random Quote Script
|
Sardis
Fresh Scripter
Registered: 2004-01-16
Posts: 28
Loc: Montgomery, AL
|
Thanks Shane, that worked perfectly. You're awesome.
Jason
_________________________
Jason A King
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 2175 anonymous users online.
|
|
|