Sign in to follow this  
Followers 0
jwurmz

Combobox hates me...

6 posts in this topic

#1 ·  Posted (edited)

I'm working on a script which reads data records from an old flat-file DOS database. It parses all records in the file and populates a combobox using a string made from one or more of the fields from each record. Everything works fine when I'm using a string built using a single field from each record separated by "|". My problem seems to be caused when I try to add a combobox item using a string built out of the second text field, $customername. Everything is fine if I just use the $customerref field; the combobox gets an item added for each record in the dat file. If I try it with just the $customername field (or any combination that includes it) it will only add a single item to the combbox. It does not produce an error or anything, just stops after the first entry.

Here's the code, in it's sloppy entirety:

#include <GuiConstantsEx.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>

;;Variable declarations/definitions
;MsgBox(4096, @ScriptDir, @ScriptDir)
;$dosdirectory = @ScriptDir
$dosdirectory = "C:\Santos\Datapax"
;$dosdirectory = "C:\Users\jwurmz\Desktop\SantosDATAPAX010510\DATAPAX"

Dim $foundinvoicefiles[1000]
Dim $foundcustomerfiles[1000]
Dim $foundinvoices[1000000]
Dim $foundcustomers[10001]
Dim $customerrecord[255]
Dim $invoicerecord[42]

;;Main GUI
$maingui = GuiCreate("Datapax 6.x", 200, 100, (@DesktopWidth / 2) - 100, (@DesktopHeight / 2) - 50)
$mainarbutton = GUICtrlCreateButton("Accounts Receivable", 5, 5, 190, 20)

;;AR GUI
$argui = GUICreate("Datapax 6.x - Accounts Receivable", 640, 480, (@DesktopWidth / 2) - 320, (@DesktopHeight / 2) - 240, $WS_EX_TOOLWINDOW)
GUICtrlCreateLabel("Customer:", 10, 10, 60, 20)
$arcustomercombo = GUICtrlCreateCombo("", 60, 8, 300, 20, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL, $CBS_SORT))
$arreceiptgroup = GUICtrlCreateGroup("Add Receipt", 395, 5, 230, 75)
$ardatepicker = GUICtrlCreateDate("", 410, 25, 200, 20)
GUICtrlCreateLabel("Receipt Total:", 410, 50, 80, 20)
$arreceipttotalinput = GUICtrlCreateInput("", 480, 48, 50, 20)
$araddbutton = GUICtrlCreateButton("Add", 535, 48, 75, 20)
$arlistView = GuiCtrlCreateListView("Date|Customer|BillTo|Description|PartialPay|Prompt|Amount|Status|Source|Route|Tax1|Tax2", 10, 90, 615, 325)
$testaritem = GuiCtrlCreateListViewItem("100107|J420|X1014|57156|$0.00|pd455600|$475.13|*|FP|1|$0.00|$0.00", $arlistView)
$arsavebutton = GUICtrlCreateButton("Save", 10, 425, 80, 20)
$arabortbutton = GUICtrlCreateButton("Abort", 100, 425, 80, 20)
$arabortbutton = GUICtrlCreateButton("Print Statement", 200, 425, 80, 20)
$arexitbutton = GUICtrlCreateButton("Exit AR", 545, 425, 80, 20)

;;Allocation GUI
$allocgui = GUICreate("Allocations", 320, 240, (@DesktopWidth / 2) - 160, (@DesktopHeight / 2) - 120, $WS_EX_TOOLWINDOW)
GUICtrlCreateLabel("Test:", 10, 10, 60, 20)


Func FindAllInvoiceFiles()
    ;;Empty array
    For $i = 1 to 1000
        $foundinvoicefiles[$i - 1] = ""
    Next
    ;;Search DOS directory for INV files
    $search = FileFindFirstFile($dosdirectory & "\INV*.DAT")
    ;;Check if the search was successful
    $numfound = 0
    If $search = -1 Then
        MsgBox(0, "Error", "No invoice files found in directory: " & $dosdirectory)
        ;Exit
    Else
        Do
            $file = FileFindNextFile($search)
            If @error Then ExitLoop
            If $file <> "" Then
                ;MsgBox(4096, "File:", "#" & $numfound & " - " & $file)
                $foundinvoicefiles[$numfound] = $file
                $numfound = $numfound + 1
            EndIf
        Until $file = -1
    EndIf
EndFunc

Func FindAllCustomerFiles()
    ;;Empty array
    For $i = 1 to 1000
        $foundcustomerfiles[$i - 1] = ""
    Next
    ;;Search DOS directory for INV files
    $search = FileFindFirstFile($dosdirectory & "\CUSTOM*.DAT")
    ;;Check if the search was successful
    $numfound = 0
    If $search = -1 Then
        MsgBox(0, "Error", "No customer files found in directory: " & $dosdirectory)
        ;Exit
    Else
        Do
            $file = FileFindNextFile($search)
            If @error Then ExitLoop
            If $file <> "" Then
                ;MsgBox(4096, "File:", "#" & $numfound & " - " & $file)
                $foundcustomerfiles[$numfound] = $file
                $numfound = $numfound + 1
            EndIf
        Until $file = -1
    EndIf

EndFunc

Func FindAllCustomers()
    $customerfile = FileOpen($dosdirectory & "\" & $foundcustomerfiles[1], 0)
    $numcustomerrecords = FileGetSize($dosdirectory & "\" & $foundcustomerfiles[1]) / 255
    If $customerfile <> -1 Then
        For $i = 1 to $numcustomerrecords
            $record = FileRead($customerfile, 255)
            If $customerfile = -1 Then
                MsgBox(0, "Error", "Unable to open file.")
                Exit
            EndIf
            $customername = StringLeft($record, 30);StringStripWS(StringLeft($record, 30), 3)
            $customerref = StringMid($record, 31, 1)
            $pad = ""
            If StringLen(String(Asc(StringMid($record, 32, 1)))) < 3 Then
                $padnum = 3 - StringLen(String(Asc(StringMid($record, 32, 1))))
                For $j = 1 to $padnum
                    $pad = $pad & "0"
                Next
            EndIf
            $customerref = $customerref & $pad & String(Asc(StringMid($record, 32, 1)))
            $foundcustomers[$i] = $customerref ;& StringStripWS($customername, 3)
            ;=================================================this routine doesn't report cust ref for nr and vi properly, or add it to the combo when customer name is included
        Next
    EndIf
    $arcustomercombostring = ""
    For $i = 1 to 10000
        If $foundcustomers[$i] <> "" Then
            $arcustomercombostring = $arcustomercombostring & $foundcustomers[$i] & "|"
        EndIf
    Next
    If StringLen($arcustomercombostring) > 1 Then
        GUICtrlSetData($arcustomercombo, $arcustomercombostring)
    EndIf
EndFunc

GUISwitch($maingui)
GuiSetState()

FindAllInvoiceFiles()
FindAllCustomerFiles()
FindAllCustomers()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $mainarbutton
            GUISetState(@SW_SHOW, $argui)
        ;Case $msg = $testaritem
            ;GUISetState(@SW_SHOW, $allocgui)
        ;Case $msg = $argobutton
            ;FindAllCustomers()
        Case $msg = $arexitbutton
            GUISetState(@SW_HIDE, $argui)
            GUISwitch($maingui)
    EndSelect

WEnd

...and the data files are attached to thi message.

The path to the data files ($dosdirecory) is hard coded at the moment so you'll have to update it to wherever you download the DAT files.

Line 100 is the beginning of where the file is read. I know for certain that the file is being read fine and that there is readable text in the 2 fields I am reading ($customername, $customerref) for all records in the file.

Line 115 is where the two fields are combined into a single string and stored in an array (although in the code above it is partially commented to allow for good results using a single field).

If you can offer any help it would be greatly appreciated!!! Thank you!

DATfiles.7z

Edited by jwurmz

Share this post


Link to post
Share on other sites



jwurmz,

If you could provide the data in another form, I would be happy to look at the problem. I do not use 7-Zip so I cannot read your file. :evil:

PM will do. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

jwurmz,

If you could provide the data in another form, I would be happy to look at the problem. I do not use 7-Zip so I cannot read your file. :evil:

PM will do. ;)

M23

I appreciate the offer, but I don't see a way to PM files. It looks like I still have room in my global quota here...

DATFILES.zip

Share this post


Link to post
Share on other sites

jwurmz,

Ok, initial thoughts.

Are you sure you were even finding all the files correctly? You were starting your array of found files at element[0] but then reading from element[1]. As you only supplied 1 file to test, this was very obvious! You will see where I have changed the lines to start the logging of found files at [1] - look for <<<<<<<<<<<<<<<<<<<<<<<. It is a very common mistake - I have to think very carefully every time about array indices in loops! :)I

You can also empty an array by using Dim - see the +++++++++++++++++ lines.

And so to the combobox. The first 2 elements of the $foundcustomers array are "Non-Regular Customers" and "Voided Invoices", each followed by a load of non-printing characters. When you started to add the names into your string with "|" separators, the process stopped after the "Non-Regular Customers" string - no doubt because of all the garbage behind it. If you start filling the string from element[3], the first proper name, all goes well. You can see where I have changed the count - look for >>>>>>>>>>>>>>>>>>> this time! ;) If you want those names in the combo, then you will have to make sure that they only consist of the normal characters - a StringLen might be the trick.

#include <GuiConstantsEx.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>

#include <Array.au3> ; only here for debugging purposes +++++++++++++++++++++++++++++++++++++

;;Variable declarations/definitions
;MsgBox(4096, @ScriptDir, @ScriptDir)
;$dosdirectory = @ScriptDir
$dosdirectory = @ScriptDir ; changed for my testing only ++++++++++++++++++++++++++++++++++
;$dosdirectory = "C:\Users\jwurmz\Desktop\SantosDATAPAX010510\DATAPAX"

Global $foundinvoicefiles[1000]
Global $foundcustomerfiles[1000]
Dim $foundinvoices[1000000]
Dim $foundcustomers[10001]
Dim $customerrecord[255]
Dim $invoicerecord[42]

;;Main GUI
$maingui = GuiCreate("Datapax 6.x", 200, 100, (@DesktopWidth / 2) - 100, (@DesktopHeight / 2) - 50)
$mainarbutton = GUICtrlCreateButton("Accounts Receivable", 5, 5, 190, 20)

;;AR GUI
$argui = GUICreate("Datapax 6.x - Accounts Receivable", 640, 480, (@DesktopWidth / 2) - 320, (@DesktopHeight / 2) - 240, $WS_EX_TOOLWINDOW)
GUICtrlCreateLabel("Customer:", 10, 10, 60, 20)
Global $arcustomercombo = GUICtrlCreateCombo("", 60, 8, 300, 20, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL, $CBS_SORT))
$arreceiptgroup = GUICtrlCreateGroup("Add Receipt", 395, 5, 230, 75)
$ardatepicker = GUICtrlCreateDate("", 410, 25, 200, 20)
GUICtrlCreateLabel("Receipt Total:", 410, 50, 80, 20)
$arreceipttotalinput = GUICtrlCreateInput("", 480, 48, 50, 20)
$araddbutton = GUICtrlCreateButton("Add", 535, 48, 75, 20)
$arlistView = GuiCtrlCreateListView("Date|Customer|BillTo|Description|PartialPay|Prompt|Amount|Status|Source|Route|Tax1|Tax2", 10, 90, 615, 325)
$testaritem = GuiCtrlCreateListViewItem("100107|J420|X1014|57156|$0.00|pd455600|$475.13|*|FP|1|$0.00|$0.00", $arlistView)
$arsavebutton = GUICtrlCreateButton("Save", 10, 425, 80, 20)
$arabortbutton = GUICtrlCreateButton("Abort", 100, 425, 80, 20)
$arabortbutton = GUICtrlCreateButton("Print Statement", 200, 425, 80, 20)
$arexitbutton = GUICtrlCreateButton("Exit AR", 545, 425, 80, 20)

GUISetState(@SW_HIDE)

;;Allocation GUI
$allocgui = GUICreate("Allocations", 320, 240, (@DesktopWidth / 2) - 160, (@DesktopHeight / 2) - 120, $WS_EX_TOOLWINDOW)
GUICtrlCreateLabel("Test:", 10, 10, 60, 20)
GUISetState(@SW_HIDE)


GUISwitch($maingui)
GuiSetState()

FindAllInvoiceFiles()
FindAllCustomerFiles()
FindAllCustomers()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $mainarbutton
            GUISetState(@SW_SHOW, $argui)
        ;Case $msg = $testaritem
            ;GUISetState(@SW_SHOW, $allocgui)
        ;Case $msg = $argobutton
            ;FindAllCustomers()
        Case $msg = $arexitbutton
            GUISetState(@SW_HIDE, $argui)
            GUISwitch($maingui)
    EndSelect

WEnd

Func FindAllInvoiceFiles()
    ;;Empty array
    ;For $i = 1 to 1000
    ;    $foundinvoicefiles[$i - 1] = ""
    ;Next
    Dim $foundinvoicefiles[1000] ; ++++++++++++++++++++++++++++++++++++++++
    ;;Search DOS directory for INV files
    $search = FileFindFirstFile($dosdirectory & "\INV*.DAT")
    ;;Check if the search was successful
    $numfound = 1 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    If $search = -1 Then
        MsgBox(0, "Error", "No invoice files found in directory: " & $dosdirectory)
        ;Exit
    Else
        Do
            $file = FileFindNextFile($search)
            If @error Then ExitLoop
            If $file <> "" Then
                ;MsgBox(4096, "File:", "#" & $numfound & " - " & $file)
                $foundinvoicefiles[$numfound] = $file
                $numfound = $numfound + 1
            EndIf
        Until $file = -1
    EndIf

EndFunc

Func FindAllCustomerFiles()
    ;;Empty array
    ;For $i = 1 to 1000
    ;    $foundcustomerfiles[$i - 1] = ""
    ;Next
    Dim $foundcustomerfiles[1000] ; ++++++++++++++++++++++++++++++++++++++++
    ;;Search DOS directory for INV files
    $search = FileFindFirstFile($dosdirectory & "\CUSTOM*.DAT")
    ;;Check if the search was successful
    $numfound = 1  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    If $search = -1 Then
        MsgBox(0, "Error", "No customer files found in directory: " & $dosdirectory)
        ;Exit
    Else
        Do
            $file = FileFindNextFile($search)
            If @error Then ExitLoop
            If $file <> "" Then
                ;MsgBox(4096, "File:", "#" & $numfound & " - " & $file)
                $foundcustomerfiles[$numfound] = $file
                $numfound = $numfound + 1
            EndIf
        Until $file = -1
    EndIf

    _ArrayDisplay($foundcustomerfiles) ; ############################################

EndFunc

Func FindAllCustomers()

    $customerfile = FileOpen($dosdirectory & "\" & $foundcustomerfiles[1], 0)
    $numcustomerrecords = FileGetSize($dosdirectory & "\" & $foundcustomerfiles[1]) / 255
    If $customerfile <> -1 Then
        For $i = 1 to $numcustomerrecords
            $record = FileRead($customerfile, 255)
            If $customerfile = -1 Then
                MsgBox(0, "Error", "Unable to open file.")
                Exit
            EndIf
            $customername = StringLeft($record, 30);StringStripWS(StringLeft($record, 30), 3)
            $customerref = StringMid($record, 31, 1)
            $pad = ""
            If StringLen(String(Asc(StringMid($record, 32, 1)))) < 3 Then
                $padnum = 3 - StringLen(String(Asc(StringMid($record, 32, 1))))
                For $j = 1 to $padnum
                    $pad = $pad & "0"
                Next
            EndIf
            $customerref = $customerref & $pad & String(Asc(StringMid($record, 32, 1)))
            $foundcustomers[$i] = StringStripWS($customername, 3) ; $customerref ;& StringStripWS($customername, 3)
            ;=================================================this routine doesn't report cust ref for nr and vi properly, or add it to the combo when customer name is included
        Next
    EndIf

    _ArrayDisplay($foundcustomers) ; #####################################################

    $arcustomercombostring = ""
    For $i = 3 to 10000 ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        If $foundcustomers[$i] <> "" Then
            $arcustomercombostring &= $foundcustomers[$i] & "|"
            ConsoleWrite($arcustomercombostring & @CRLF) ; ################################
        EndIf
    Next

    ConsoleWrite($arcustomercombostring & @CRLF) ; ########################################

    If StringLen($arcustomercombostring) > 1 Then
        GUICtrlSetData($arcustomercombo, $arcustomercombostring)
    EndIf
EndFunc

Top tip: You will see a number of debugging lines that I have left in - look for ##########. I use these sorts of thing all the time when I do not get what I want/am expecting. :evil:

I hope that helps. Ask again if there are still problems. :evil:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

jwurmz,

Ok, initial thoughts.

Are you sure you were even finding all the files correctly? You were starting your array of found files at element[0] but then reading from element[1]. As you only supplied 1 file to test, this was very obvious! You will see where I have changed the lines to start the logging of found files at [1] - look for <<<<<<<<<<<<<<<<<<<<<<<. It is a very common mistake - I have to think very carefully every time about array indices in loops! :)I

You can also empty an array by using Dim - see the +++++++++++++++++ lines.

And so to the combobox. The first 2 elements of the $foundcustomers array are "Non-Regular Customers" and "Voided Invoices", each followed by a load of non-printing characters. When you started to add the names into your string with "|" separators, the process stopped after the "Non-Regular Customers" string - no doubt because of all the garbage behind it. If you start filling the string from element[3], the first proper name, all goes well. You can see where I have changed the count - look for >>>>>>>>>>>>>>>>>>> this time! ;) If you want those names in the combo, then you will have to make sure that they only consist of the normal characters - a StringLen might be the trick.

#include <GuiConstantsEx.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>

#include <Array.au3> ; only here for debugging purposes +++++++++++++++++++++++++++++++++++++

;;Variable declarations/definitions
;MsgBox(4096, @ScriptDir, @ScriptDir)
;$dosdirectory = @ScriptDir
$dosdirectory = @ScriptDir ; changed for my testing only ++++++++++++++++++++++++++++++++++
;$dosdirectory = "C:\Users\jwurmz\Desktop\SantosDATAPAX010510\DATAPAX"

Global $foundinvoicefiles[1000]
Global $foundcustomerfiles[1000]
Dim $foundinvoices[1000000]
Dim $foundcustomers[10001]
Dim $customerrecord[255]
Dim $invoicerecord[42]

;;Main GUI
$maingui = GuiCreate("Datapax 6.x", 200, 100, (@DesktopWidth / 2) - 100, (@DesktopHeight / 2) - 50)
$mainarbutton = GUICtrlCreateButton("Accounts Receivable", 5, 5, 190, 20)

;;AR GUI
$argui = GUICreate("Datapax 6.x - Accounts Receivable", 640, 480, (@DesktopWidth / 2) - 320, (@DesktopHeight / 2) - 240, $WS_EX_TOOLWINDOW)
GUICtrlCreateLabel("Customer:", 10, 10, 60, 20)
Global $arcustomercombo = GUICtrlCreateCombo("", 60, 8, 300, 20, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL, $CBS_SORT))
$arreceiptgroup = GUICtrlCreateGroup("Add Receipt", 395, 5, 230, 75)
$ardatepicker = GUICtrlCreateDate("", 410, 25, 200, 20)
GUICtrlCreateLabel("Receipt Total:", 410, 50, 80, 20)
$arreceipttotalinput = GUICtrlCreateInput("", 480, 48, 50, 20)
$araddbutton = GUICtrlCreateButton("Add", 535, 48, 75, 20)
$arlistView = GuiCtrlCreateListView("Date|Customer|BillTo|Description|PartialPay|Prompt|Amount|Status|Source|Route|Tax1|Tax2", 10, 90, 615, 325)
$testaritem = GuiCtrlCreateListViewItem("100107|J420|X1014|57156|$0.00|pd455600|$475.13|*|FP|1|$0.00|$0.00", $arlistView)
$arsavebutton = GUICtrlCreateButton("Save", 10, 425, 80, 20)
$arabortbutton = GUICtrlCreateButton("Abort", 100, 425, 80, 20)
$arabortbutton = GUICtrlCreateButton("Print Statement", 200, 425, 80, 20)
$arexitbutton = GUICtrlCreateButton("Exit AR", 545, 425, 80, 20)

GUISetState(@SW_HIDE)

;;Allocation GUI
$allocgui = GUICreate("Allocations", 320, 240, (@DesktopWidth / 2) - 160, (@DesktopHeight / 2) - 120, $WS_EX_TOOLWINDOW)
GUICtrlCreateLabel("Test:", 10, 10, 60, 20)
GUISetState(@SW_HIDE)


GUISwitch($maingui)
GuiSetState()

FindAllInvoiceFiles()
FindAllCustomerFiles()
FindAllCustomers()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $mainarbutton
            GUISetState(@SW_SHOW, $argui)
        ;Case $msg = $testaritem
            ;GUISetState(@SW_SHOW, $allocgui)
        ;Case $msg = $argobutton
            ;FindAllCustomers()
        Case $msg = $arexitbutton
            GUISetState(@SW_HIDE, $argui)
            GUISwitch($maingui)
    EndSelect

WEnd

Func FindAllInvoiceFiles()
    ;;Empty array
    ;For $i = 1 to 1000
    ;    $foundinvoicefiles[$i - 1] = ""
    ;Next
    Dim $foundinvoicefiles[1000] ; ++++++++++++++++++++++++++++++++++++++++
    ;;Search DOS directory for INV files
    $search = FileFindFirstFile($dosdirectory & "\INV*.DAT")
    ;;Check if the search was successful
    $numfound = 1 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    If $search = -1 Then
        MsgBox(0, "Error", "No invoice files found in directory: " & $dosdirectory)
        ;Exit
    Else
        Do
            $file = FileFindNextFile($search)
            If @error Then ExitLoop
            If $file <> "" Then
                ;MsgBox(4096, "File:", "#" & $numfound & " - " & $file)
                $foundinvoicefiles[$numfound] = $file
                $numfound = $numfound + 1
            EndIf
        Until $file = -1
    EndIf

EndFunc

Func FindAllCustomerFiles()
    ;;Empty array
    ;For $i = 1 to 1000
    ;    $foundcustomerfiles[$i - 1] = ""
    ;Next
    Dim $foundcustomerfiles[1000] ; ++++++++++++++++++++++++++++++++++++++++
    ;;Search DOS directory for INV files
    $search = FileFindFirstFile($dosdirectory & "\CUSTOM*.DAT")
    ;;Check if the search was successful
    $numfound = 1  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    If $search = -1 Then
        MsgBox(0, "Error", "No customer files found in directory: " & $dosdirectory)
        ;Exit
    Else
        Do
            $file = FileFindNextFile($search)
            If @error Then ExitLoop
            If $file <> "" Then
                ;MsgBox(4096, "File:", "#" & $numfound & " - " & $file)
                $foundcustomerfiles[$numfound] = $file
                $numfound = $numfound + 1
            EndIf
        Until $file = -1
    EndIf

    _ArrayDisplay($foundcustomerfiles) ; ############################################

EndFunc

Func FindAllCustomers()

    $customerfile = FileOpen($dosdirectory & "\" & $foundcustomerfiles[1], 0)
    $numcustomerrecords = FileGetSize($dosdirectory & "\" & $foundcustomerfiles[1]) / 255
    If $customerfile <> -1 Then
        For $i = 1 to $numcustomerrecords
            $record = FileRead($customerfile, 255)
            If $customerfile = -1 Then
                MsgBox(0, "Error", "Unable to open file.")
                Exit
            EndIf
            $customername = StringLeft($record, 30);StringStripWS(StringLeft($record, 30), 3)
            $customerref = StringMid($record, 31, 1)
            $pad = ""
            If StringLen(String(Asc(StringMid($record, 32, 1)))) < 3 Then
                $padnum = 3 - StringLen(String(Asc(StringMid($record, 32, 1))))
                For $j = 1 to $padnum
                    $pad = $pad & "0"
                Next
            EndIf
            $customerref = $customerref & $pad & String(Asc(StringMid($record, 32, 1)))
            $foundcustomers[$i] = StringStripWS($customername, 3) ; $customerref ;& StringStripWS($customername, 3)
            ;=================================================this routine doesn't report cust ref for nr and vi properly, or add it to the combo when customer name is included
        Next
    EndIf

    _ArrayDisplay($foundcustomers) ; #####################################################

    $arcustomercombostring = ""
    For $i = 3 to 10000 ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        If $foundcustomers[$i] <> "" Then
            $arcustomercombostring &= $foundcustomers[$i] & "|"
            ConsoleWrite($arcustomercombostring & @CRLF) ; ################################
        EndIf
    Next

    ConsoleWrite($arcustomercombostring & @CRLF) ; ########################################

    If StringLen($arcustomercombostring) > 1 Then
        GUICtrlSetData($arcustomercombo, $arcustomercombostring)
    EndIf
EndFunc

Top tip: You will see a number of debugging lines that I have left in - look for ##########. I use these sorts of thing all the time when I do not get what I want/am expecting. :evil:

I hope that helps. Ask again if there are still problems. :evil:

M23

Yeah, I am sure that I'm finding the file correctly. I only posted one of the invoices files that are in my specified directory -- there are actually hundreds of them, all with data that works fine in another app.

I just used "1" as the index because it was quicker to see the results than if I was parsing all files. I know exactly what you mean about array indices, they've gotten me a million times before. What leads me to believe it's not an index issue is because the $customerreference by itself worked fine. I'm not ruling anything out at this point, though.

I was thinking it may have been due to non-readable characters so I told it to strip the whitespace using flag 3 (all whitespace before AND after string); this seemed to yield the same results.

I can't test any of your suggestions for a couple of hours. I will certainly let you know how it goes.

Thank you very much for your help!!!

Share this post


Link to post
Share on other sites

As it turns out, there was one extra byte (0x00) in the NR record. I just changed the reading of this field to 29 bytes instead of 30 and it works great. Thanks again!

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