Sign in to follow this  
Followers 0
Aurthuric

Editable list based on data in an array

3 posts in this topic

I have used AutoIT for a lot of text manipulation programs, but now I want to move into a more functional program.  Here is the basic concept that I have in mind, perhaps someone could shed some light on it or point me in the right direction.

I want to load a array with part data (Partkey, description, weight, cost, group key, labor)  About 20K lines so I was going to dimension an array as follows

DIM - $product [20000][6]

Then load data from a CSV into that array

I have to then create a quote based on items I select from the list.  First I though of scrolling through the list and check marking the items I want, but that would be cumbersome with so many items.  So I wanted to do like a list view where you enter the partkey and it populates the rest of the fields, you enter quantity and it calculates the total weight, total labor and total cost.  Then go to the next line.  I also want to be able to break the quote into sections so that each section can be subtotaled as well as the entire quote.  This data would be stored in another array and have the ability to save the quote.

I have been looking at listview samples and mouse position/mouse click detection scripts but nothing that seems to fit.

 

So please, I need some help here.  Is there away to do it???  Is there a better way then using an array??  Better way then listview??

Any samples you have would be greatly appreciated. 

 

I am basically looking at a way to quote/invoice items I sell on ebay (That is why the weight is in there).

Thanks in advance

 

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi, Aurthuric, welcome to the forum. With 20k lines, it really sounds like you need a SQLite database to hold your data. It is a bit more difficult, but will be much easier to manage and make edits to in the future. Take a look at this as a quick and dirty example:

#include <MsgBoxConstants.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>


Local $aFinal[1][6]
    $aFinal[0][0] = "PartKey"
    $aFinal[0][1] = "Description"
    $aFinal[0][2] = "Weight"
    $aFinal[0][3] = "Cost"
    $aFinal[0][4] = "GroupKey"
    $aFinal[0][4] = "Labor"


Local $aResult, $iRows, $iColumns, $iRval, $hDB, $myDBase = @ScriptDir & "\Parts.tmp"

Local $sDLL = _SQLite_Startup("sqlite.dll", 1)
    If @error Then
        MsgBox($MB_OK, "", "Failed with error: " & @error)
        Exit(-1)
    EndIf

    $hDB = _dbOpen($myDBase)
    $myTable = _tableCreate($hDB)

        _AddValues("001", "Part Number 1", "5 lbs", "$299.95", "42", "1 hour")
        _AddValues("002", "Part Number 2", "15 lbs", "$399.95", "43", "1 hour")
        _AddValues("003", "Part Number 3", "25 lbs", "$599.95", "44", "1 hour")
        _AddValues("004", "Part Number 4", "50 lbs", "$1199.95", "45", "1 hour")


    $iRval = _SQLite_GetTable2d(-1, "SELECT * FROM Parts;", $aResult, $iRows, $iColumns)
        If $iRval = $SQLITE_OK Then
            For $i = 1 To UBound($aResult) - 1
                _ArrayAdd($aFinal, $aResult[$i][0] & "|" & $aResult[$i][1] & "|" & $aResult[$i][2] & "|" & $aResult[$i][3] & "|" & $aResult[$i][4])
            Next
        EndIf

_ArrayDisplay($aFinal, "Values to be added to database") ;Just to show you what is being written, can comment out.
_SQLite_Close()
_SQLite_Shutdown()

Func _dbOpen($myDBase)
    _SQLite_Open($myDBase)
        If @error Then
            Return -1
        Else
            Return 0
        EndIf
EndFunc

Func _tableCreate($hDB)
    If $SQLITE_OK <> _SQLite_Exec($hDB, "CREATE TABLE Parts ('PartKey', 'Description', 'Weight', 'Cost', 'GroupKey', 'Labor');") Then
        MsgBox($MB_OK, "", "Error from TableCreate Function: " & _SQLite_ErrCode() & ". " & _SQLite_ErrMsg())
        Exit (-1)
    Else
        Return 0
    EndIf
EndFunc

Func _AddValues($sPartKey, $sDesc, $sWeight, $sCost, $sGroupKey, $sLabor)
    If $SQLITE_OK <> _SQLite_Exec($hDB, "INSERT INTO Parts VALUES ('" & $sPartKey & "','" & $sDesc & "', '" & $sWeight & "', '" & $sCost & "', '" & $sGroupKey & "', '" & $sLabor & "');") Then
        MsgBox($MB_OK, "", "Error from AddValues Function: " & _SQLite_ErrCode() & ". " & _SQLite_ErrMsg())
        Exit(-1)
    Else
        Return 0
    EndIf
EndFunc

You can then build your gui around the database info. Please check out the SQLite functions in the help file, and be sure to ask on anything you would like clarification on.

Edited by JLogan3o13

When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

What are "partkey"s and "groupkeys" and how are they related to parts?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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