Page 1 of 1 1
Topic Options
#124153 - 2004-07-30 02:16 AM using MESSAGEBOX() to display contents of a txt file....
cigaweed74 Offline
Fresh Scripter

Registered: 2002-04-08
Posts: 20
Hi to all,

Is it possible to display the contents of a txt file through the use of MESSAGEBOX()?

Top
#124154 - 2004-07-30 02:19 AM Re: using MESSAGEBOX() to display contents of a txt file....
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Yes, indirectly.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#124155 - 2004-07-30 02:47 AM Re: using MESSAGEBOX() to display contents of a txt file....
cigaweed74 Offline
Fresh Scripter

Registered: 2002-04-08
Posts: 20
Les,
What do you mean by indirectly? Can you please give more details....

thanks

Top
#124156 - 2004-07-30 02:58 AM Re: using MESSAGEBOX() to display contents of a txt file....
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Load the contents of the text file into a variable.
Display up to the first 1024 characters (messagebox API limit) of the variable in the messagebox. See the KiXtart Manual on how to read text files or use ready-made UDFs from the UDF Forum.
_________________________
There are two types of vessels, submarines and targets.

Top
#124157 - 2004-07-30 02:59 AM Re: using MESSAGEBOX() to display contents of a txt file....
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Read the file into an array with the ReadFile() UDF. Join() it into a string with @CRLF. Display the string with MessageBox().
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#124158 - 2004-07-30 03:58 AM Re: using MESSAGEBOX() to display contents of a txt file....
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
$Message = Join(ReadFile('c:\file.txt'),@CRLF)
$RC = MessageBox($Message,'Words of Wisdom',,)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#124159 - 2004-07-30 07:35 AM Re: using MESSAGEBOX() to display contents of a txt file....
cigaweed74 Offline
Fresh Scripter

Registered: 2002-04-08
Posts: 20
Hi Les,

I tried your method but it didn't work...
Here is the code:

function Join($Array, OPTIONAL $Delimiter, OPTIONAL $MaxCount)
dim $count
if vartype($Delimiter)=0 ; not passed'
$Delimiter=''
endif
if vartype($MaxCount)=0 ; not passed
; remember, array starts at element 0!
$MaxCount=ubound($Array)
endif
$Join=''
$count=0
for each $element in $Array
if $count<=$MaxCount
$Join=$Join+$element+$Delimiter
endif
$count=$count+1
next
$Join=substr($Join,1,len($Join)-len($Delimiter))
endfunction

Function ReadFile($file)
Dim $lf, $f, $_, $t
$lf=chr(10)
$f=freefilehandle
$_=open($f,$file)
if @error exit @error endif
do $t=$t+$lf+readline($f) until @error
$_=close($f)
$ReadFile=split(substr($t,2),$lf)
EndFunction
$msg = Join(ReadFile('c:\temp\test.txt'),@CRLF)
$ = MessageBox($msg,'Test',,)

Top
#124160 - 2004-07-30 08:59 AM Re: using MESSAGEBOX() to display contents of a txt file....
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
ehm,

no need for custom join functions as this is intrinsic in the mean time.
That's probably also the reason why it fails!
_________________________



Top
#124161 - 2004-07-30 09:04 AM Re: using MESSAGEBOX() to display contents of a txt file....
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Cigaweed,

Not sure what you're attempting to do there but it is as simple as Les already supplied. Unless you're trying to add the code to check for a maximum of 1,000 characters in which case wouldn't the message seem odd anyways if you just arbitrarily cut it off at that level ???


Here is the complete code that should work as Les says.

Code:
Dim $Message,$MB
$Message = Join(ReadFile('C:\TEMP\TEST.TXT'),@CRLF)
$MB = MessageBox($Message,'Words of Wisdom',64,)

Function ReadFile($file)
Dim $lf, $f, $_, $t
$lf=CHR(10)
$f=FreeFileHandle
$_=Open($f,$file)
If @ERROR Exit @ERROR EndIf
Do $t=$t+$lf+ReadLine($f) Until @ERROR
$_=Close($f)
$ReadFile=Split(SubStr($t,2),$lf)
EndFunction



In the FULL script though I would recommend that you get used to using these options

Code:
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')


Top
#124162 - 2004-08-02 03:06 AM Re: using MESSAGEBOX() to display contents of a txt file....
cigaweed74 Offline
Fresh Scripter

Registered: 2002-04-08
Posts: 20
thankyou to all...appreciate the prompt help..
all working now....

Top
#124163 - 2004-08-02 06:07 AM Re: using MESSAGEBOX() to display contents of a txt file....
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Glad to hear it Cig

As an FYI you can simply modify the code to be like this to only get the first 1,000 lines.

Code:
$Message = Left(Join(ReadFile('C:\TEMP\TEST.TXT'),@CRLF),1000)


Top
Page 1 of 1 1


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

Who's Online
0 registered and 764 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.071 seconds in which 0.027 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