Dude Posted November 30, 2015 Share Posted November 30, 2015 Hi. This Function exports an DBF File to an array. But it also exports deleted records. How can i preventthis? The function should only export not as deleted marked records. How can i do this? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 30, 2015 Moderators Share Posted November 30, 2015 Dude,And where do we find this function so we can take a look?M23 Skysnake 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Dude Posted December 1, 2015 Author Share Posted December 1, 2015 expandcollapse popup#include-once ;=============================================================================== ; ; Description: Directly read DBF database file to array ; Parameter(s): $sFileName - name of DBF file ; $nFlags ; 1 - convert from OEM to ANSI ; 2 - strip leading and trailing witespaces ; Requirement(s): Autoit 3.2.9.0 + ; Return Value(s): On Success - 2D array, first row - names of fields ; On Failure - no decent way to check errors ; Author(s): Dmitry Yudin (Lazycat) ; Version: 0.3 ; Date: 14.12.2009 ; Note(s): Many DBF functions and flags are not read - just because ; I wasn't need it ; ;=============================================================================== Func _FileReadDBF($sFileName, $nFlags = 0) Local $hFile = FileOpen($sFileName, 16) Local $pReadBuffer = DllStructCreate("byte[32]") ; Header size DllStructSetData($pReadBuffer, 1, FileRead($hFile, 32)) $pDBFHeader = DllStructCreate("byte;byte;byte;byte;int;short;short;byte[20]" , DllStructGetPtr($pReadBuffer)) ; Header struct $nRecords = DllStructGetData($pDBFHeader, 5) ; Get number of records $nDataPos = DllStructGetData($pDBFHeader, 6) ; Get data start position $nRecordSize = DllStructGetData($pDBFHeader, 7) ; Get record size (included deleted flag) $nFields = Floor($nDataPos / 32) - 1 $nDataGap = $nDataPos - ($nFields + 1) * 32 Local $aData[$nRecords+1][$nFields] Local $sRecordStruct = "byte;" ; Struct string, based on fields size and type, first byte - deleted mark For $i=0 To $nFields - 1 DllStructSetData($pReadBuffer, 1, FileRead($hFile, 32)) $pField = DllStructCreate("char[11];byte;int;byte;byte[15]" , DllStructGetPtr($pReadBuffer)) ; Field structure $aData[0][$i] = DllStructGetData($pField, 1) ; Name of field ; Create struct based on field size and type (now unfinished, treat all types as string) Switch DllStructGetData($pField, 2) Case Asc("C") or Asc("D") ;or Else $sRecordStruct &= "char[" & DllStructGetData($pField, 4) & "];" EndSwitch Next $sRecordStruct = StringTrimRight($sRecordStruct, 1) ; Trim last ";" FileRead($hFile, $nDataGap) ; Skip ending marker, it's size may vary $pReadBuffer = DllStructCreate("byte["&$nRecordSize&"]") ; New buffer, now based on record size For $i = 1 To $nRecords DllStructSetData($pReadBuffer, 1, FileRead($hFile, DllStructGetSize($pReadBuffer))) $pRecord = DllStructCreate($sRecordStruct , DllStructGetPtr($pReadBuffer)) For $j = 0 To $nFields - 1 $aData[$i][$j] = DllStructGetData($pRecord, $j+2) If BitAND($nFlags, 1) Then $aData[$i][$j] = _Ascii2Ansi($aData[$i][$j]) If BitAND($nFlags, 2) Then $aData[$i][$j] = StringStripWS($aData[$i][$j], 3) Next Next FileClose($hFile) Return $aData EndFunc ; Helper function, convert OEM text to ANSI Func _Ascii2Ansi($sText) Local $src = DllStructCreate("char[" & StringLen($sText) + 1 & "]") Local $dst = DllStructCreate("char[" & StringLen($sText) + 1 & "]") DllStructSetData($src, 1, $sText) DllCall("user32.dll", "int", "OemToCharA", "ptr", DllStructGetPtr($src), "ptr", DllStructGetPtr($dst)) Return DllStructGetData($dst, 1) EndFunc Link to comment Share on other sites More sharing options...
Danp2 Posted December 1, 2015 Share Posted December 1, 2015 Here's a revised version that should give you what you are looking for:expandcollapse popupFunc _FileReadDBF($sFileName, $nFlags = 0, $lDeleted = True) Local $hFile = FileOpen($sFileName, 16) Local $pReadBuffer = DllStructCreate("byte[32]") ; Header size DllStructSetData($pReadBuffer, 1, FileRead($hFile, 32)) $pDBFHeader = DllStructCreate("byte;byte;byte;byte;int;short;short;byte[20]" , DllStructGetPtr($pReadBuffer)) ; Header struct $nRecords = DllStructGetData($pDBFHeader, 5) ; Get number of records $nDataPos = DllStructGetData($pDBFHeader, 6) ; Get data start position $nRecordSize = DllStructGetData($pDBFHeader, 7) ; Get record size (included deleted flag) $nFields = Floor($nDataPos / 32) - 1 $nDataGap = $nDataPos - ($nFields + 1) * 32 Local $aData[$nRecords+1][$nFields] Local $sRecordStruct = "byte;" ; Struct string, based on fields size and type, first byte - deleted mark For $i=0 To $nFields - 1 DllStructSetData($pReadBuffer, 1, FileRead($hFile, 32)) $pField = DllStructCreate("char[11];byte;int;byte;byte[15]" , DllStructGetPtr($pReadBuffer)) ; Field structure $aData[0][$i] = DllStructGetData($pField, 1) ; Name of field ; Create struct based on field size and type (now unfinished, treat all types as string) Switch DllStructGetData($pField, 2) Case Asc("C") or Asc("D") ;or Else $sRecordStruct &= "char[" & DllStructGetData($pField, 4) & "];" EndSwitch Next $sRecordStruct = StringTrimRight($sRecordStruct, 1) ; Trim last ";" FileRead($hFile, $nDataGap) ; Skip ending marker, it's size may vary $pReadBuffer = DllStructCreate("byte["&$nRecordSize&"]") ; New buffer, now based on record size Local $nRow = 1, $cDeleted For $i = 1 To $nRecords DllStructSetData($pReadBuffer, 1, FileRead($hFile, DllStructGetSize($pReadBuffer))) $pRecord = DllStructCreate($sRecordStruct , DllStructGetPtr($pReadBuffer)) $cDeleted = Chr(DllStructGetData($pRecord, 1)) If $lDeleted Or $cDeleted <> '*' Then For $j = 0 To $nFields - 1 $aData[$nRow][$j] = DllStructGetData($pRecord, $j+2) If BitAND($nFlags, 1) Then $aData[$nRow][$j] = _Ascii2Ansi($aData[$nRow][$j]) If BitAND($nFlags, 2) Then $aData[$nRow][$j] = StringStripWS($aData[$nRow][$j], 3) Next $nRow += 1 EndIf Next FileClose($hFile) Return $aData EndFuncNote: I didn't reduce the size of the array, so there will be one blank record at the bottom for each deleted record. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Dude Posted December 1, 2015 Author Share Posted December 1, 2015 Hi. Thanks a lot! seems to work Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now