Hi Mark,
Here is the code -
Sub BtnPrepareBankEntries()
Dim sEntryDate AS String
Dim sBkStat AS String
Dim sBkStatBak AS String
Dim aFields(150,7) AS String
Dim sKey AS String
Dim aWhoRef(150,7) AS String
Dim iCount AS Integer
Dim iFileNo AS Integer
Dim iRec AS Integer
Dim iFld AS Integer
Dim iPtr AS Integer
Dim iBSB_AcNo AS Integer
Dim iEntryDate AS Integer
Dim iTypeCode AS Integer
Dim iAmount AS Integer
Dim iEntryType AS Integer
Dim iWho AS Integer
Dim iWhoRef AS Integer
Dim iKey AS Integer
iBSB_AcNo = 1
iEntryDate = 2
iTypeCode = 3
iAmount = 4
iEntryType = 5
iWho = 6
iWhoRef = 7
iKey = 0
sBkStat = "D:\Downloads\BBL.csv"
sBkStatBak = "D:\Downloads\BBL.bak"
if not FileExists(sBkStat) then
msgBox("File " + sBkStat + " not found. Check that you have
downloaded the month's entries from the Bank", MB_OK, "PRIOR ACTION NEEDED"
)
else
iCount = 0
iRec = 0
iFileNo = FreeFile()
' Read records from "D:\Downloads\BBL.csv into the array -
(aFields(150,7))
Open sBkStat for Input as #iFileNo
Do while NOT EOF(iFileNo)
iRec = iRec + 1
For iFld = 1 to 7
Input #iFileNo, aFields(iRec,iFld)
Next iFld
Loop
REM1 - The following lines transform the data to suit the Accounting System.
This is where you could delete duplicates or make data
adjustments.
For iPtr = iRec To 1 Step -1
aFields(iPtr,iEntryType) =
fCamelCase(fRemoveNumbers(aFields(iPtr,iEntryType),0))
aFields(iPtr,iWho) =
fCamelCase(fRemoveNumbers(aFields(iPtr,iWho),0))
aWhoRef(iPtr,iWhoRef) =
fCamelCase(fRemoveNumbers(aFields(iPtr,iWhoRef),2))
Select case aFields(iPtr,iEntryType)
Case "Debit Card Fee" :
aFields(iPtr,iKey) = aFields(iPtr,iEntryType)
Case "Deposit - Cheque(s)" :
aFields(iPtr,iKey) = aFields(iPtr,iEntryType)
Case "Direct Credit" :
aFields(iPtr,iKey) = aFields(iPtr,iWho)
if aFields(iPtr,iWho) = "Challenger Life" then
aFields(iPtr,iKey) = aFields(iPtr,iWho) + ": " +
aWhoRef(iPtr,iWhoRef)
End if
if aFields(iPtr,iWho) = "Ing Direct" then
aFields(iPtr,iKey) = aFields(iPtr,iWho) + " Credit"
End if
Case "Direct Debit" :
if aFields(iPtr,iWho) = "Ing Direct" then
aFields(iPtr,iKey) = aFields(iPtr,iWho) + " Debit"
else
aFields(iPtr,iKey) = aFields(iPtr,iWho) + ": " +
aWhoRef(iPtr,iWhoRef)
End if
Case "Interest" :
aFields(iPtr,iKey) = aFields(iPtr,iEntryType)
case "Pay Anyone" :
if aFields(iPtr,iAmount) > 0 then
aFields(iPtr,iKey) = aFields(iPtr,iWho)
else
aFields(iPtr,iKey) =
fCamelCase(fRemoveNumbers(aWhoRef(iPtr,iWhoRef),0))' Remove 2 digits
remaining on left of string
End if
case "Pension" :
aFields(iPtr,iKey) = aFields(iPtr,iWho) + ": " +
aWhoRef(iPtr,iWhoRef)
case "Retail Purchase" :
aFields(iPtr,iKey) = aFields(iPtr,iWho)
Case "Transaction Fees Charged" :
aFields(iPtr,iKey) = aFields(iPtr,iEntryType)
Case "Withdrawal - Atm" :
aFields(iPtr,iKey) = Left("WDraw-ATM: " +
aFields(iPtr,iWho), 30)
Case "Withdrawal - Eftpos" :
aFields(iPtr,iKey) = Left("WDraw-EFTPOS: " +
aFields(iPtr,iWho), 30)
case Else :
aFields(iPtr,iKey) = aFields(iPtr,iWho)
end Select
Next iPtr
REM2 - End of transformation section
' Add records to the BankStatments table in date order
For iPtr = iRec To 1 Step -1
sEntryDate = fReverseDate(aFields(iPtr,iEntryDate))
gsSQL = "INSERT INTO BankStatements
(EntryDate,Who,Amount,EntryType,WhoRef,""BSB-A/cNo"",TypeCode,Key) " _
+ "VALUES ('" + sEntryDate + "','" +
fProcessSingleQuotes(aFields(iPtr,iWho)) + "','" + aFields(iPtr,iAmount) +
"','" _
+ aFields(iPtr,iEntryType) + "','" +
aFields(iPtr,iWhoRef) + "','" + aFields(iPtr,iBSB_AcNo) + "','" _
+ aFields(iPtr,iTypeCode) + "','" +
fProcessSingleQuotes(aFields(iPtr,iKey)) + "')"
if goStmt9.executeUpdate(gsSQL) = 0 then '= row NOT
inserted
MsgBox("INSERT failed. Command was - '" + gsSQL + ";", 0,
"BtnPrepareBankEntries()")
Exit Sub
End if
iCount = iCount + 1
Next iPtr
Close #iFileNo
' Delete backup file
If FileExists(sBkStatBak) then
Kill(sBkStatBak)
else
msgBox("File " + sBkStatBak + " not found.")
End if
' Rename BBL.csv to BBL.bak
if FileExists(sBkStat) then
Name sBkStat As sBkStatBak
else
MsgBox("There was no '" + sBkStat + "' to make a new '" +
sBkStatBak + "' from.")
End if
MsgBox("Download Completed - " + CStr(iCount) + " entries
processed")
End if
End Sub
Hope you can read this - on a wide screen, the formatting is much better!
Perhaps you could copy and paste the code into a Writer document set to
landscape, to make it more readable.
You can probably ignore all the code between REM1 and REM2. This is just
formatting to suit my requirements.
I use several functions, all starting with "f", e.g. -
fReverseDate - Puts a date into yyyy-mm-dd format.
fProcessSingleQuotes - Single quotes need to be doubled up to avoid
problems.
etc.
If you would like the code for any of these, let me know.
Hopefully this may give you ideas you can experiment with.
Noel
--
Noel Lodge
lodgemn@gmail.com
On 10 July 2013 11:56, Mark LaPierre <marklapier@aol.com> wrote:
On 9 July 2013 17:46, Alexander Thurgood <alex.thurgood@gmail.com> wrote:
Le 07/07/13 21:37, Mark LaPierre a écrit :
Any suggestions on how to proceed from here? Do I just copy and paste
the data from the spreadsheet directly into the mySQL table?
On further reflection, it might be possible to do this by using a macro,
in which you connect to the Calc sheet, load the data array into a basic
array stored in memory, and then connect to your mysqldb and do the
updates from the stored data array. However :
- I have no idea whether this would actually work ;
- the performance might suck big time, as LO Basic does not exactly have
the greatest of memory management models.
It might possibly work better in python. If you can avoid using the UI
where possible, you will speed things up no end. Redrawing UI components
is pretty costly in terms of performance.
Alex
--
To unsubscribe e-mail to:
users+unsubscribe@global.**libreoffice.org<users%2Bunsubscribe@global.libreoffice.org>
Problems?
http://www.libreoffice.org/**get-help/mailing-lists/how-to-**
unsubscribe/<http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/>
Posting guidelines + more: http://wiki.**documentfoundation.org/**
Netiquette <http://wiki.documentfoundation.org/Netiquette>
List archive:
http://listarchives.**libreoffice.org/global/users/<http://listarchives.libreoffice.org/global/users/>
All messages sent to this list will be publicly archived and cannot be
deleted
> On 07/09/2013 09:20 PM, Marion & Noel Lodge wrote:
Hi Mark,
I have written a Macro in Basic that imports Bank Statement details from
a
.csv file into my Accounting system. It uses an SQL INSERT INTO
statement
to write to the database Table. I run an H2 database, but because the
Insert is done using SQL, it should translate fairly readily to your
mysqldb.
I could post the code if you think it could be adapted for your
situation.
Noel
Hey Noel,
I would be interested in seeing your code. Post it to the list so others
may gain from it as well.
--
_
°v°
/(_)\
^ ^ Mark LaPierre
Registered Linux user No #267004
https://linuxcounter.net/
****
--
To unsubscribe e-mail to:
users+unsubscribe@global.**libreoffice.org<users%2Bunsubscribe@global.libreoffice.org>
Problems? http://www.libreoffice.org/**get-help/mailing-lists/how-to-**
unsubscribe/<http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/>
Posting guidelines + more: http://wiki.**documentfoundation.org/**
Netiquette <http://wiki.documentfoundation.org/Netiquette>
List archive:
http://listarchives.**libreoffice.org/global/users/<http://listarchives.libreoffice.org/global/users/>
All messages sent to this list will be publicly archived and cannot be
deleted
--
To unsubscribe e-mail to: users+unsubscribe@global.libreoffice.org
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted
Context
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.