#124153 - 2004-07-30 02:16 AM
using MESSAGEBOX() to display contents of a txt file....
|
cigaweed74
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
|
|
|
|
#124155 - 2004-07-30 02:47 AM
Re: using MESSAGEBOX() to display contents of a txt file....
|
cigaweed74
Fresh Scripter
Registered: 2002-04-08
Posts: 20
|
Les, What do you mean by indirectly? Can you please give more details....
thanks
|
|
Top
|
|
|
|
#124159 - 2004-07-30 07:35 AM
Re: using MESSAGEBOX() to display contents of a txt file....
|
cigaweed74
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
|
|
|
|
#124161 - 2004-07-30 09:04 AM
Re: using MESSAGEBOX() to display contents of a txt file....
|
NTDOC
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
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
   
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 451 anonymous users online.
|
|
|