Page 1 of 1 1
Topic Options
#131075 - 2004-12-10 07:51 PM Ascan() and Readfile()
brewdude6 Offline
Hey THIS is FUN

Registered: 2000-10-21
Posts: 280
Loc: Nashville, TN
Can someone take a look at this?
Code:

$PATCHLIST="%temp%\patchlist"
$PNF="Scan"

For Each $array in ReadFile("$patchlist")
? $array
If AScan($array,$PNF) >= 0
Shell "notepad.exe"
EndIf
Next



It returns -1 but the expression is in the text file.
_________________________
I could have made a neat retort but didn't, for I was flurried and didn't think of it till I was downstairs.
-Mark Twain

Top
#131076 - 2004-12-10 07:58 PM Re: Ascan() and Readfile()
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I do not see where you open the file to read it. Chack the manual for "OPEN"

Ascan works on Arrays. I do not see where you have an array. $array in your example would normally be an ELEMENT of an ARRAY.


----------------

Scratch above as I misread ReadFile to be Readline. Still looking...


Edited by Howard Bullock (2004-12-10 07:59 PM)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#131077 - 2004-12-10 08:04 PM Re: Ascan() and Readfile()
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
This should be more correct.
Code:
$PATCHLIST="%temp%\patchlist"

$PNF="Scan"
If AScan(ReadFile($patchlist),$PNF) >= 0
Shell "notepad.exe"
EndIf

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

Top
#131078 - 2004-12-10 08:08 PM Re: Ascan() and Readfile()
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yeah.
_________________________
!

download KiXnet

Top
#131079 - 2004-12-10 08:32 PM Re: Ascan() and Readfile()
brewdude6 Offline
Hey THIS is FUN

Registered: 2000-10-21
Posts: 280
Loc: Nashville, TN
Thanks, but that still returns -1
_________________________
I could have made a neat retort but didn't, for I was flurried and didn't think of it till I was downstairs.
-Mark Twain

Top
#131080 - 2004-12-10 08:41 PM Re: Ascan() and Readfile()
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Time to perform more debugging and providing answers.

Code:
$PATCHLIST="%temp%\patchlist"
$aLines = ReadFile($patchlist)
? "Number of elements = " + (Ubound($aLines) + 1)
? "Ascan = " + AScan($aLines,$PNF)

for each $line in $aLines
? "'" + $line + "'"
next
; Is 'Scan' output?
; Do you have CaseSensitivity turned on?

$PNF="Scan"

If AScan($aLines,$PNF) >= 0
Shell "notepad.exe"
EndIf


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

Top
#131081 - 2004-12-10 09:49 PM Re: Ascan() and Readfile()
brewdude6 Offline
Hey THIS is FUN

Registered: 2000-10-21
Posts: 280
Loc: Nashville, TN
Thanks Howard...that helped me realize that each line is a string and not each word in each line (at least I think that's the case). $PNF is in one of the lines, just not the only word.
_________________________
I could have made a neat retort but didn't, for I was flurried and didn't think of it till I was downstairs.
-Mark Twain

Top
#131082 - 2004-12-10 10:08 PM Re: Ascan() and Readfile()
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Then try this...
Code:
$PATCHLIST="%temp%\patchlist"
$aLines = ReadFile($patchlist)
$TextOfFile = join($aLines, @CRLF)
$PNF="Scan"

If instr($TextOfFile,$PNF) >= 0
Shell "notepad.exe"
EndIf

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

Top
#131083 - 2004-12-10 10:25 PM Re: Ascan() and Readfile()
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
or:
Code:

$PATCHLIST="%temp%\patchlist"
$aLines = ReadFile($patchlist)
$TextOfFile = split(join($aLines))
$PNF="Scan"
If -1<ascan($TextOfFile,$PNF)
Shell "notepad.exe"
EndIf

_________________________
!

download KiXnet

Top
#131084 - 2004-12-10 10:35 PM Re: Ascan() and Readfile()
brewdude6 Offline
Hey THIS is FUN

Registered: 2000-10-21
Posts: 280
Loc: Nashville, TN
I better include the whole script I'm testing with.

test.txt
Code:

test
this
on
a
system




Code:
 
$PATCHLIST="c:\temp\test.txt"
$aLines = ReadFile($patchlist)
$TextOfFile = Join($aLines, @CRLF)
$PNF="test"
If InStr($TextOfFile,$PNF) >= 0
Shell "notepad.exe"
EndIf

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



Even if I use a word not in text.txt, notepad will execute. I'm obviously in over my head, but it's only waist deep.
_________________________
I could have made a neat retort but didn't, for I was flurried and didn't think of it till I was downstairs.
-Mark Twain

Top
#131085 - 2004-12-10 10:36 PM Re: Ascan() and Readfile()
brewdude6 Offline
Hey THIS is FUN

Registered: 2000-10-21
Posts: 280
Loc: Nashville, TN
Yes...that works. Thank you all.
_________________________
I could have made a neat retort but didn't, for I was flurried and didn't think of it till I was downstairs.
-Mark Twain

Top
#131086 - 2004-12-10 10:38 PM Re: Ascan() and Readfile()
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
My mistake.
If InStr($TextOfFile,$PNF) >= 0

should be

If InStr($TextOfFile,$PNF) > 0

Instr returns 0 if not found. That code was a holdover from the ASCAN where you needed zero.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#131087 - 2004-12-10 10:42 PM Re: Ascan() and Readfile()
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
or just plain

If InStr($TextOfFile,$PNF)
_________________________
Eric

Top
#131088 - 2004-12-10 10:45 PM Re: Ascan() and Readfile()
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Simpler is indeed better. Not sure why I wrote it that way.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#131089 - 2004-12-10 10:52 PM Re: Ascan() and Readfile()
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
specially as the joinsplitter is in use now and that is irrelevant.

could do some golfing though:
Code:

$PATCHLIST="%temp%\patchlist"
$PNF="Scan"
If -1<ascan(split(join(ReadFile($patchlist))),$PNF)
Shell "notepad.exe"
EndIf

_________________________
!

download KiXnet

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
1 registered (Allen) and 382 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.065 seconds in which 0.024 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