Sign in to follow this  
Followers 0
Docfxit

Script not reading file

7 posts in this topic

#1 ·  Posted (edited)

Could I please get some help in figureing out why this code won't read the file.

The text file is called OffSettingEntries.txt

This is the text file:

Vendors,Accounts
CHEVRON,Car/Truck Expense:Gas
BAJA FRESH,Travel & Entertainment:Meals
GRAND PANDA,Travel & Entertainment:Meals
LENOVO,Hardware

#include <file.au3>
#include <array.au3>
AutoItSetOption("TrayIconDebug", 1) ;0-off
; Set so that tray displays current line number
HotKeySet("{ESC}", "Set_Exit")

Dim   $hQBOffSetEntries, $Vendor[10], $Account[10], $sString, $asFields[3]
Global $QBOffSetEntries = "C:\Program Files\QuickBooks Pro 2004\OffSettingEntries.txt"
$sPattern = '([^",]*|"(?:[^"]|"")*")(?:,|\Z)'


    OpenFiles()
    ReadOffSetEntries()
    _ArrayDisplay($Vendor, "Vendor")                                                        
    _ArrayDisplay($Account, "Accounts")     
    Set_Exit()

Func ReadOffSetEntries()
    $x = 0
    While @error = 0
        $x = $x + 1
        Global $sString = FileReadLine($hQBOffSetEntries)
        If @error = -1 Then 
                ;End of file reached
                Set_Exit()
            EndIf
        $asFields = StringRegExp($sString, $sPattern, 3)
;       for $i = 0 to UBound($asFields) - 1
;           msgbox(4096, "Array Number           -------",  $i & " - " & $asFields[$i] & @LF & "InputString - " & $sString & @LF & UBound($asFields))
;       Next
    $Vendor[$x] = $asFields[0]       
    $Account[$x] = $asFields[1]   ; The Debugger gets an error on index[1]  AutoIt ends with no error and doesn't finish displaying the arrays after this function call   
    msgbox(4096, "Contents 2", "$asFields - " & $asFields & @LF & "@error - " & @error)
    WEnd            
    
EndFunc ;==>ReadOffSetEntries

Func OpenFiles()
Global $hQBOffSetEntries = FileOpen($QBOffSetEntries, 0)
    If $hQBOffSetEntries = -1 Then
        MsgBox(0, "Error", "Unable to open - " & $QBOffSetEntries)
        Exit
    EndIf
EndFunc ;==> OpenFiles

Func Set_Exit()
    FileClose($QBOffSetEntries)
   Exit
EndFunc ;==>Set_Exit
Edited by docfxit

Share this post


Link to post
Share on other sites



I'm not 100% sure but I suspect the problem is in using RegExp.

To be sure put a MsgBox after Local $sString = FileReadLine($hQBOffSetEntries) to see if at least you have some content to work on.

If the line is read properly then you will need to focus on StringRegExp and the next part.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

I'm not 100% sure but I suspect the problem is in using RegExp.

To be sure put a MsgBox after Local $sString = FileReadLine($hQBOffSetEntries) to see if at least you have some content to work on.

If the line is read properly then you will need to focus on StringRegExp and the next part.

Thanks for looking at it. I had a MsgBox during my testing. I put it back in for clarity. The records are blank.

Thank you,

Docfxit

Share this post


Link to post
Share on other sites

Thanks for looking at it. I had a MsgBox during my testing. I put it back in for clarity. The records are blank.

Thank you,

Docfxit

your problem appears to be variable scope.

you are only testing for end of file, not a failure to utilize the file handle.

better yet, actually pass a stinking variable around so that you don't have to rely on globals. if you tested what the file handle is , I bet it's a null string....


Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

Defining a variable outside any function as "Local" doesn't sound good to me (it could work OK but you better change "Local" with a simple "Dim" or better "Global") ...

Do this and try again.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

Defining a variable outside any function as "Local" doesn't sound good to me (it could work OK but you better change "Local" with a simple "Dim" or better "Global") ...

Do this and try again.

That is great. I changed all the "Local" 's to "Global" 's and it works great.

Thank you very much.

Docfxit

Share this post


Link to post
Share on other sites

you are only testing for end of file, not a failure to utilize the file handle.

Do you know of any examples of better testing?

Thank you,

Docfxit

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