Sign in to follow this  
Followers 0
theguy0000

Script not running...

5 posts in this topic

#include <File.au3>

MsgBox(0, "whats", _FileFindString("C:\test.txt", "whats"))

MsgBox(0, "are", _FileFindString("C:\test.txt", "are", 2))

MsgBox(0, "dude", _FileFindString("C:\test.txt", "dude", 3))

When I run this, it does absolutely nothing at all, and ends immediately. No message boxes, no errors, nothing. It just exists.

Here is _FileFindString:

;$iMode - 
;  1 - Beginning of line (default)
;  2 - Anywhere in line
;  3 - Whole line
Func _FileFindString($zFile, $sSearch, $iMode=1)
    If $iMode <> 1 Or $iMode <> 2 Or $iMode <> 3 Then
        SetError(-3)
        Return -3
    EndIf
    
    If Not FileExists($sPath) Then
        SetError(-1)
        Return -1
    EndIf
    
    If IsString($zFile) Then $handle = FileOpen($sPath, 0)
    
    Else $handle = $zFile
    
    If $handle = -1 Then
        SetError(-2)
        Return -2
    EndIf
    
    For $i=1 To _FileCountLines($sPath)
        If $iMode = 1 Then
            If StringInStr(FileReadLine($handle, $i), $sSearch) = 1 Then Return $i
        ElseIf $iMode = 2 Then
            If StringInStr(FileReadLine($handle, $i), $sSearch) Then Return $i
        ElseIf $iMode = 3 Then
            If FileReadLine($handle, $i) = $sSearch Then Return $i
        EndIf
    Next
    Return 0
EndFunc

What is wrong here?


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$sPath?? didn't make sense so changed to $zFile

Commented out the else because that didn't make sense either.

I'm not really sure what your expecting to get back from this, you will only ever get a number back based on the For count.

#include <File.au3>

MsgBox(0, "whats", _FileFindString("C:\test.txt", "whats"))

MsgBox(0, "are", _FileFindString("C:\test.txt", "are", 2))

MsgBox(0, "dude", _FileFindString("C:\test.txt", "dude", 3))

;$iMode - 
;  1 - Beginning of line (default)
;  2 - Anywhere in line
;  3 - Whole line
Func _FileFindString($zFile, $sSearch, $iMode=1)
   If not $iMode > 0 or $iMode > 3  Then
        SetError(-3)
        Return -3
    EndIf
    
    If Not FileExists($zFile) Then
        SetError(-1)
        Return -1
    EndIf
    
    If IsString($zFile) Then $handle = FileOpen($zFile, 0)
    
 ;;;;Else $handle = $zFile
    
    If $handle = -1 Then
        SetError(-2)
        Return -2
    EndIf
    
    For $i=1 To _FileCountLines($zFile)
        If $iMode = 1 Then
            If StringInStr(FileReadLine($handle, $i), $sSearch) = 1 Then Return $i
        ElseIf $iMode = 2 Then
            If StringInStr(FileReadLine($handle, $i), $sSearch) Then Return $i
        ElseIf $iMode = 3 Then
            If FileReadLine($handle, $i) = $sSearch Then Return $i
        EndIf
    Next
    Return 0
EndFunc
Edited by ChrisL

Share this post


Link to post
Share on other sites

oh, right. Thanks. :o


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

what do you mean?

edit: oh I see. thanks.

Edited by theguy0000

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0