Sign in to follow this  
Followers 0
Klexen

Easier way to do this?

4 posts in this topic

#1 ·  Posted (edited)

Ok, I didn't think this all the way through and just ran into a problem...

I'm trying to get the status of % of ink used and pages printed, for black, cyan, yellow and magenta.

Here is the code...

#include <IE.au3>
#include <Date.au3>

HotKeySet("{F1}","Bedford")

Global $CurrentDate = _DateTimeFormat( _NowCalc(),2)
Global $Spacer = " / "
Global $BSpacer = " / "
Global $YSpacer = " / "
Global $CSpacer = " / "
Global $MSpacer = " / "

Func Bedford()
    
    $sURL = "http://10.25.51.162/info_suppliesStatus.html?tab=Status&menu=SupplyStatus"
    $oIE = _IECreate($sURL, 0, 0, 0)
    _IELoadWait($oIE)
    $readtext = _IEBodyReadText($oIE)
    
;Black
    $BlackPercent = StringMid($readtext,470,4)
    $BlackPages = StringMid($readtext,665,4)

;Cyan
    $CyanPercent = StringMid($readtext, 770,4)
    $CyanPages = StringMid($readtext, 963,4)
    
;Magenta
    $MagentaPercent = StringMid($readtext,1070,4)
    $MagentaPages = StringMid($readtext,1263,4)
    
;Yellow 
    $YellowPercent = StringMid($readtext,1370,4)
    $YellowPages = StringMid($readtext,1563,4)
    
    $ChkBPages = StringRegExp(StringLeft($BlackPages, 1), '[0-9]', 1)
If @error == 1 Then
    $BlackPages = 'OUT'
    $BlackPercent = ''
    $BSpacer = ""
EndIf

    $ChkYPages = StringRegExp(StringLeft($YellowPages, 1), '[0-9]', 1)
If @error == 1 Then
    $YellowPages = 'OUT'
    $YellowPercent = ''
    $YSpacer = ""
EndIf

    $ChkCPages = StringRegExp(StringLeft($CyanPages, 1), '[0-9]', 1)
If @error == 1 Then
    $CyanPages = 'OUT'
    $CyanPercent = ''
    $CSpacer = ""
EndIf

    $ChkMPages = StringRegExp(StringLeft($MagentaPages, 1), '[0-9]', 1)
If @error == 1 Then
    $MagentaPages = 'OUT'
    $MagentaPercent = ''
    $MSpacer = ""
EndIf

    Run("notepad.exe")
    WinWaitActive("Untitled")
    ControlSend("Untitled", "", "Edit1","Bedford Printer Stats:" & @CRLF & $CurrentDate & " " &  " " & $BlackPages & $BSpacer & $BlackPercent & " | " & $YellowPages & $YSpacer & $YellowPercent & " | " & $CyanPages & $CSpacer & $CyanPercent & " | " & $MagentaPages & $MSpacer & $MagentaPercent)
    
EndFunc

This works right now, because Black has ink left. So char count works... But if black were out, char count would be different, and give me wrong results. Same as if cyan was out, it would give me wrong results because char count would change. So unless I write something for every possible ink scenario, I'm going to get wrong results for anything besides black ink.

Is there something else I can do to make this work right?

I attached one of the pages I'm working with..

printerpage.zip

Edited by Klexen

Share this post


Link to post
Share on other sites



Well, "33 %" has 4 letters and "9 %" three, so you might want to change values for these numbers using If keyword :P

Right, I know that is going to be an issue too. So is there another way to approach this other than using StringMid and _IEBodyReadText

Share this post


Link to post
Share on other sites

Right, I know that is going to be an issue too. So is there another way to approach this other than using StringMid and _IEBodyReadText

Try with reading two letters and then extracting with Integer() function. See where that leads you.

I can do signature me.

Share this post


Link to post
Share on other sites

Try with reading two letters and then extracting with Integer() function. See where that leads you.

Can you show me an example of what you mean?

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