Jump to content

How To See If Filereadline Routine Failed To Find A Match?


Recommended Posts

  • Moderators

Sorry, try this:

Dim $gsline, $stringfound, $gstxt, $gshtml, $gsinst, $t
$t = "TestFTP"
$gshtml = @TempDir & "\gsver.txt"
$gsinst = @TempDir & "\gsinst.exe"
$FindString1 = "<li><b><a hef=" & Chr(34) & "doc/AFPL/get"
If InetGet("http://www.cs.wisc.edu/~ghost/", $gshtml, 1, 0) Then
    $Version = _GetCurGSVer($gshtml, $FindString1, '.htm')
    If $Version Then
        MsgBox(64, 'Info:', 'Your String Was Found' & @CR & 'And your Version is: ' & $Version)
    Else
        MsgBox(64, "TestFTP", "Ghostscript version could not be determined. Install Ghostscript manually and rerun this program.")
        Exit
    EndIf
EndIf
        

Func _GetCurGSVer($hFileRead, $s_Start, $s_End)
    $hFileRead = FileRead($hFileRead, FileGetSize($hFileRead))
    $aArray = StringRegExp($hFileRead, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3)
    If @extended Then
        FileDelete($gshtml)
        Return $aArray[0]
    EndIf
    FileDelete($gshtml)
    Return 0
EndFunc
You're code you had for the MsgBox() was wrong, and wouldn't let it come up "8298", I haven't tried to figure out why, but I'll tell you I was scratching my head wondering why it wasn't showing up when the string wasn't found.

Edit:

Let me say I left off the href "r" in href on purpose to test it failing.

Edit2:

Showing highlighting of syntax for big daddy :)

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Here. You were mixing up your handle check with your line variable. Error checking was fine except for an extra line the checked error for -1 for no reason at the bottom of the loop.

Global $gsline, $stringfound, $gstxt, $gshtml, $gsinst, $t
$t = "TestFTP"
$gshtml = @TempDir & "\gsver.txt"
$gsinst = @TempDir & "\gsinst.exe"
If Not InetGet("http://www.cs.wisc.edu/~ghost/", $gshtml, 1, 0) Then
    MsgBox(8298, $t, "Error: Unable to test Ghostcript version. qInstall Ghostscript manually and rerun this program.")
    Exit
EndIf

GetCurGSVer()
Exit

Func GetCurGSVer()
    $gstxt = FileOpen($gshtml, 0)
    If $gstxt <> - 1 Then
        $stringfound = 0
        While 1
            $gsline = FileReadLine($gstxt)
            If @error Then ExitLoop
            If StringInStr($gsline, '<li><b><a href="doc/AFPL/get') Then
                $stringfound = 1
                ExitLoop
            EndIf
        WEnd
        MsgBox(0, $t, $stringfound)
        If Not $stringfound Then
            MsgBox(8298, $t, "Ghostscript version could not be determined. Install Ghostscript manually and rerun this program.")
            Exit
        EndIf
        FileClose($gstxt)
    Else
        MsgBox(8298, $t & ' FileOpen Error', "Ghostscript version could not be determined. Install Ghostscript manually and rerun this program.")
        Exit
    EndIf
    FileDelete($gshtml)
    MsgBox(0, $t, $gsline)
EndFunc;==>GetCurGSVer

:)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...