Page 1 of 1 1
Topic Options
#112027 - 2004-01-19 07:27 PM Random Quote Script
Sardis Offline
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 Offline
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

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#112029 - 2004-01-19 07:35 PM Re: Random Quote Script
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
see the Readfile() UDF and the Join() statement
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#112030 - 2004-01-19 07:45 PM Re: Random Quote Script
Sardis Offline
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 Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#112032 - 2004-01-19 07:59 PM Re: Random Quote Script
Sardis Offline
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 Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#112034 - 2004-01-19 08:15 PM Re: Random Quote Script
Sardis Offline
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
#112035 - 2004-01-19 08:26 PM Re: Random Quote Script
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Hey Howard...Where is the DebugLog UDF? I cant find it anywhere.
Top
#112036 - 2004-01-19 08:30 PM Re: Random Quote Script
ShaneEP Moderator Offline
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 Offline
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 Offline
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
#112039 - 2004-01-19 09:05 PM Re: Random Quote Script
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Maybe you should have posted to starters. They do more hand holding there.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#112040 - 2004-01-19 09:10 PM Re: Random Quote Script
ShaneEP Moderator Offline
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 Offline
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 Offline
Fresh Scripter

Registered: 2004-01-16
Posts: 28
Loc: Montgomery, AL
Thanks Shane, that worked perfectly. You're awesome.

Jason
_________________________
Jason A King

Top
#112043 - 2004-01-19 10:04 PM Re: Random Quote Script
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Hi Jason,

Since you already have your answer and this is the General Discussion forum I have a general question.

Just wondering why someone at a Director level is writing scripts. Once in a while we having "working" Managers but very rarely do we have a "hands-on" Director.

Top
#112044 - 2004-01-19 11:24 PM Re: Random Quote Script
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
First off, who said I don't want to help? Second, I was not making snide comments, simply trying to direct you to the most appropriate forum. Had you had read the FAQ ABC's of KiXtart board etiquette and message to new forum users you may have noticed that this (general) forum is for:
Quote:

All topics/ideas/suggestions that may or may not relate to KiXtart or may not properly relate to one of the other forums.
Basically, if it doesn't fit in the other forums, then this is the one.


_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#112045 - 2004-01-20 12:03 AM Re: Random Quote Script
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Maybe it's a one-person company? ;-)

BTW, this FAQ might help, too: How to use UDFs
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2360 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.07 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org