|
Post by metro on Jan 2, 2019 19:20:51 GMT -5
I wasn't going to post this code till I had time to complete it. (busy renovating a house), I usually find 15 mins or so a day to look at LB. Dan, this may not be your ideal way of tackling the problem but a listview does keep things tidy.
tonights project was to tackle editing a ListView record and writing the changed back to the DB but I also thought it maybe smarter to write the changes to the DB first then re-load the ListView. So at the moment selecting a row in the listview and clicking "edit" will only print to the mainwin I have played with several variations of ListView Functions and prefer the functions Brandon has supplied with the exception of the AddRow function in my attached code which I prefer. save the following into the MELK folder created by uncompressing the attached zip the code needs some tiding up though
EDIT maybe someone with more experience can tell me why the first row in the listview is blank? I can get rid of it by changing the array but then the record I want to edit is always out 1 place
double click selection of a row is enabled in another version I have and an edit form pops up
'MilkAnotherListView.bas 'list view example 'skeleton listview code generated in lbworkshop 'Basic example of how to populate a listview 'check fo selection 'edit row values, save and update the row 'the array holding the row data is also updated 'ben_jimenez@yahoo.com 'public ' NOTE EDIT FUNCTIONS NOT IMPLEMENTED YET 'set some globals GlOBAL hwndListView1,columnIndex,maxrow Global LVS.REPORT, LVS.NOSORTHEADER, LVS.SINGLESEL,_ LVM.INSERTCOLUMN, LVCF.WIDTH, LVM.INSERTITEM,_ LVCF.TEXT, LVM.SETITEM, LVIF.TEXT ,LVS.SHOWSELALWAYS,LVM.DELETEITEM DIM LineItem$(1000), RecFound$(1000) ,fldlen(100),fldlen$(100),item$(1000) EOL$= chr$(13)+chr$(10) : Dquote$=Chr$(34) gosub [SETupListViewStructs]
'setup window nomainwin WindowWidth = 850 : WindowHeight = 420 UpperLeftX = INT((DisplayWidth-WindowWidth)/2) UpperLeftY = INT((DisplayHeight-WindowHeight)/2)
' Menu #main, "&File" , "E&xit", [quit] button #main.b1,"Edit",[editrow],ul,25,20,30,20 button #main.b2,"Delete",[delete],ul,60,20,40,20 button #main.b3,"Exit",[quit],ul,105,20,40,20 statictext #main.mess1, "Sort By", 165,5,80,15 combobox #main.cb1, FldNames$(),[DisplayDataInListView], 165, 20, 150, 20 button #main.pre, "Prev", [prePage], UL, 320,20,070,020 textbox #main.pge, 390,20,055,020 button #main.nxt, "Next", [nxtPage], UL, 450,20,070,020 statictext #main.rcs, "Records:", 550,18,120,22 statictext #main.pgs, "Pages:", 550,38,100,22 Open "List View Example" for Window as #main #main "trapclose [quit]" ' #main.pge ,1 hWin=hwnd(#main) 'get window handle [CreateListView] 'create listview control calldll #comctl32, "InitCommonControls", re as void calldll #user32, "GetWindowLongA", hWin as uLong, _GWL_HINSTANCE as long, hInstance as uLong
calldll #user32, "CreateWindowExA", _WS_EX_CLIENTEDGE As long,"SysListView32" as ptr,_ "" as ptr, style as long, 25 as Long, 65 as Long, 600 as Long, 300 as Long,_ hWin as uLong, 0 as long, hInstance as uLong,"" as ptr, hwndListView1 As uLong calldll #user32, "SendMessageA" , hwndListView1 as uLong, 4150 as Long,_ 32 As Long, 32 As Long, re as Long 'make listview fullrowselect style call sendMessage hwndListView1,4150,1,1'SET GRID
'WIDTH of LVCOLUMN CAN BE SET WITH COLUMN NAMES using Brandons Functions LVCOLUMN.mask.struct = LVCF.WIDTH OR LVCF.TEXT LVITEM.mask.struct = LVIF.TEXT LVCOLUMN.cx.struct = 70 'desired width of column in pixels
gosub [setStructs] 'for 'DATABASE, CHANGED FROM USUAL STRUCT NAMES TO AVOID CONFLICT with DISK BASED DB gosub [openDll] 'SQlite tblName$ ="melkteller" hDBM=createDB(":memory:") ' gosub [createTABLE] gosub [LOADFROMFILE] gosub [INSERTRECORDS] gosub [PRAGMAINFO] gosub [SetHeaders] 'INSERT Column NAMES into LISTVIEW goto [DisplayDataInListView] 'INSERT DATA INTO LISTVIEW
'set timer for checking selected listview row timer 500, [callsub]
[loop] Wait
[callsub] call listview1Click wait
[SetHeaders] 'NAME THE COLUMNS for setH = 1 to n if FldNames$(setH) <>"" then call addColumn FldNames$(setH) end if next RETURN
'----------------edit row window [editrow] ' NOT CODED YET Rec2Edit$= isSelected$(Rec2Edit$)
for editrecs=1 to numflds Editarray$(editrecs)= FldNames$(editrecs)+chr$(9)+WORD$(Rec2Edit$,editrecs,",") next
WindowWidth = 415 WindowHeight = 250 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2) StyleBits #EditRec.listbox1, _LBS_USETABSTOPS, 0, 0, 0 listbox #EditRec.listbox1, Editarray$(),[listSelect], 10, 10,302,198 button #EditRec.list,"SAVE",[printlist],ul,320,100,80,25 button #EditRec.default,"Hiden", [listSelect],ul,-400,-400, 0, 0
StyleBits #EditRec, _DS_CENTER, 0, 0, 0 open "Arrow to Field to Edit..Press Enter" for dialog as #EditRec print #EditRec, "font Times_New_Roman 10" print #EditRec, "trapclose [quit.editrec]" print #EditRec.listbox1, "selectindex 1" [SETTABSTOP] listHwnd = HWnd( #EditRec.listbox1) Struct lParam, cx1 As Long lParam.cx1.struct = 70 'distance colum 2 TabCount=2 CallDLL #user32, "SendMessageA", _ listHwnd As ULong, _LB_SETTABSTOPS As ULong, _ TabCount As Long, lParam As Struct, _ ret As Long wait
[listSelect] #EditRec.listbox1,"selectionindex? index" ' notice "You selected - ";Editarray$(index) gosub [editfield] wait
[quit.editrec] close #EditRec wait
[editfield] WindowWidth = 320 WindowHeight = 100 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
statictext #fldEdit.st1,"Change the data then press enter",5,5,180,25 textbox #fldEdit.TbEdit , 10, 30,280,25 button #fldEdit.default,"Hiden", [ModFld],ul,-400,-400, 0, 0
open "Mod Data" for dialog as #fldEdit
print #fldEdit,"font Times_New_Roman 8" print #fldEdit, "trapclose [quit.fld.edit]" print #fldEdit.TbEdit, WORD$(Editarray$(index),2,chr$(9)) #fldEdit.TbEdit ,"!setfocus" ret1 = SendMessageLong(hwnd( #fldEdit.TbEdit),_EM_SETSEL,0,-1) wait [ModFld] #fldEdit.TbEdit , "!contents? NewDat$"; NewDat$=FldNames$(index)+chr$(9)+NewDat$ Editarray$(index)=NewDat$ #EditRec.listbox1,"reload"
if editrecs = numfields then editrecs=0 print #EditRec.listbox1, "selectindex "; index+1 [quit.fld.edit] close #fldEdit wait
[printlist] for x=1 to numflds updatearray$= updatearray$ + WORD$(Editarray$(x),1,chr$(9))+" = " +"'"+WORD$(Editarray$(x),2,chr$(9))+"'," next
lenudr=len(updatearray$) updatearray$=left$(updatearray$,lenudr-1)
'SAVE RECORD SQL$="UPDATE "; tblName$ ; " SET "; updatearray$ + " WHERE cowNumber = " + WORD$( Rec2Edit$,1,",") calldll #sqm, "SQ3_4_LB_Execute",SQL$ as ptr, hDBM as long,result as long IF result = 0 THEN calldll #sqm, "SQ3_4_LB_GetLastMessage", result as long print Winstring(result) END IF updatearray$="" close #EditRec goto [chkPage] Wait
[quit2] timer 500, [callsub] close #main2 wait
[CopyData] ' #main.te1,"!contents? Alltext$"; rr = ClipboardSetText(0,Alltext$) NOTICE "Copied to Clip Board" wait
[delete] 'DELETES FROM DB THEN REFRESHES ListView response$="N" Rec2Delete$ = isSelected$(Rec2Delete$) SQL$="DELETE FROM "; tblName$ ; " WHERE " ; "cowNumber" ; " = '" ; WORD$(Rec2Delete$,1,",");"'" Dis$ = "Delete cownumber " + WORD$(Rec2Delete$,1,","); " Y/N"
PROMPT Dis$; response$ response$=upper$(response$) if response$ ="Y" then
calldll #sqm, "SQ3_4_LB_Execute",SQL$ as ptr, hDBM as long,result as long IF result = 0 THEN calldll #sqm, "SQ3_4_LB_GetLastMessage", result as long print Winstring(result) END IF Rec2Delete$="" gosub [getNumRecords] goto [chkPage] ELSE wait
end if gosub [getNumRecords] ' close #EditRec goto [chkPage] Wait [quit] timer 0 close #sqm result = DestroyWindow(hwndListView1) close #main : END
[getNumRecords] SQL$ = "SELECT cowNumber FROM ";tblName$ ;" WHERE cowNumber not null" gosub [sqlExec] numRecords = rows ' print rows ' numPages = int((numRecords + 29) / numRows) ' limit = min(numRows,numRecords) 'pageNum = min(pageNum,numPages) 'if pageNum < 1 then pageNum = 1
' #brs.rcs "Records:";str$(numRecords) ' #brs.pgs "Pages:";str$(numPages) ' #brs.pge str$(pageNum) RETURN
[SETupListViewStructs] 'set global values LVS.REPORT = 1 : LVS.NOSORTHEADER = 32768 LVS.SINGLESEL = 4 : LVM.INSERTCOLUMN = 4123 LVCF.WIDTH = 2 : LVM.INSERTITEM = 4103 LVCF.TEXT = 4 : LVM.SETITEM = 4102 LVIF.TEXT = 1 : LVS.SHOWSELALWAYS = 8 LVM.DELETEITEM = 4104 LVM.DELETEALLITEMS = 4105
'set starting values columnIndex=0
'setup structs for listview call Struct LVITEM,mask As ulong,iItem As long,iSubItem As long,state As ulong,stateMask As ulong,_ pszText$ As ptr,cchTextMax As Long,iImage As Long,lParam As Long,iIndent As Long Struct LVCOLUMN,mask As ulong,fmt As long,cx As long,pszText$ As ptr,cchTextMax As Long,iSubItem As Long,iImage As Long,iOrder As Long 'set style values style = _WS_CHILD OR _WS_VISIBLE OR LVS.NOSORTHEADER Or LVS.REPORT Or LVS.SINGLESEL Or LVS.SHOWSELALWAYS
RETURN [DisplayDataInListView] gosub [getNumRecords] #main.pge , 0
goto [chkPage]
[prePage] pge=pge-1 #main.pge ,pge goto [chkPage]
[nxtPage] pge=pge+1 #main.pge ,pge
[chkPage] if pge >maxpages then print #main.pge ,0 end if
if pge<0 then print #main.pge, 0 end if #main.pge "!contents? pge$" pge = val(pge$) Recs2Display=pge*RecsPerPage gosub [ClearListView]
#main.cb1, "selection? sel$" SQL$ = "SELECT * FROM melkteller ORDER by " + sel$+ " LIMIT ";RecsPerPage ;" OFFSET " ;Recs2Display calldll #sqm, "SQ3_4_LB_GetRecordset", SQL$ as ptr,hDBM as long,RSM as struct, result as long calldll #sqm, "SQ3_4_LB_GetLastMessage", result as long msg$ = Winstring(result)
IF instr(msg$,"Error") THEN notice msg$ END IF
IF RSM.Rows.struct THEN ' no need FOR a loop here but the only use FOR MoveToRow seems TO be a FOR NEXT loop FOR r = 0 TO RSM.Rows.struct CALLDLL #sqm, "SQ3_4_LB_RecordsetMoveToRow",r AS long, result AS void CALLDLL #sqm, "SQ3_4_LB_GetRecordsetValueOfRow", "," AS ptr,result AS long IF result THEN RecFound$(r)= Winstring(RSM.StrAdr.struct) 'print RecFound$(r),r CALLDLL #sqm, "SQ3_4_LB_RecordsetMoveNext", result AS void NEXT
END IF CALLDLL #sqm, "SQ3_4_LB_ReleaseRecordset", result AS void ' numRecords=r-1
for r=r-1 to 1 step -1 call addRow row, RecFound$(r) next
WAIT
[setStructs] ' structure for memory DB Struct RSM,_ BOF as long,_ ' is True when CurrPos = 1 EOF as long,_ ' is True when CurrPos = Rows Handle as long,_ ' address of recordset data returned by sqlite3.dll (dont't use) Rows as long,_ ' number of rows in recordset Cols as long,_ ' number of columns in recordset CurrPos as long,_ ' current row in recordset StrAdr as long ' address of data item (pointer to a string) RETURN
[openDll] ' DLL for #sqm :memory: Open "SQ3_4_LB.dll" for DLL As #sqm ' open SQ3_4_LB.dll'calldll #sqm, "SQ3_4_LB_GetLastMessage", result as long ' was sqlite3.dll loaded by SQ3_4_LB.dll calldll #sqm, "SQ3_4_LB_GetLastMessage", result as long msg$ = Winstring(result) ' LastMessage would be "General Error - Couldn't open 'sqlite3.dll'" if instr(msg$,"Error") then ' If we have an error notice msg$ : close #sqm ' close sqlite and end program end end if
RETURN
[createTABLE] SQL$="CREATE TABLE " SQL$=SQL$+ tblName$ SQL$=SQL$+ " ( cowNumber INT(8),recogn VARCHAR(10), followNum INT(8), also VARCHAR(6), milkDate VARCHAR(10), milkingTime VARCHAR(6), milkAmount REALINT(10), milkmeterNumber VARCHAR(6))"
calldll #sqm, "SQ3_4_LB_Execute",SQL$ as ptr, hDBM as ulong,result as long calldll #sqm, "SQ3_4_LB_GetLastMessage", result as long
IF result = 0 THEN calldll #sqm, "SQ3_4_LB_GetLastMessage", result as long ' print Winstring(result);" "; "Table Does not exist" END IF RETURN
FUNCTION createDB(DBM$) ' DBM$ = ':memory:' calldll #sqm, "SQ3_4_LB_CreateDB",DBM$ as ptr, overwrite as long, hDBM as ulong calldll #sqm, "SQ3_4_LB_GetLastMessage", result as long 'message for testing If hDBM = 0 then 'message on error calldll #sqm, "SQ3_4_LB_GetLastMessage", result as long end if createDB=hDBM END FUNCTION
[LOADFROMFILE] fileName$="newFile.csv" z=1 open fileName$ for input as #inF WHILE eof(#inF)=0 line input #inF, LineItem$(z) ' print LineItem$(z),z z=z+1 WEND close #inF RETURN
[INSERTRECORDS] 'INTO SQLITE DB SQL$ = "BEGIN TRANSACTION" calldll #sqm, "SQ3_4_LB_Execute",SQL$ as ptr, hDBM as long,result as long FOR z = 1 TO z-1 'total records SQL$= "INSERT into melkteller (cowNumber,recogn,followNum,also,milkDate,milkingTime,milkAmount,milkmeterNumber) Values (" + LineItem$(z) +")" calldll #sqm, "SQ3_4_LB_Execute",SQL$ as ptr, hDBM as long,result as long
IF result = 0 THEN calldll #sqm, "SQ3_4_LB_GetLastMessage", result as long print Winstring(result) END IF
NEXT z ' print z SQL$ = "COMMIT" calldll #sqm, "SQ3_4_LB_Execute",SQL$ as ptr, hDBM as long,result as long
IF result = 0 THEN calldll #sqm, "SQ3_4_LB_GetLastMessage", result as long 'print Winstring(result) END IF
RETURN
[getFields] 'NOT IN USE ATM FldNames$="" SQL$ = "Select * From melkteller Limit 1" calldll #sqm , "SQ3_4_LB_GetRecordset", SQL$ as ptr,hDBM as long,RSM as struct, result as long calldll #sqm, "SQ3_4_LB_GetLastMessage", result as long ' print Winstring(result);" " FOR n = 1 TO RSM.Cols.struct -1 calldll #sqm, "SQ3_4_LB_GetFieldNamesByIndex",n as long, result as long FldNames$(n)= Winstring(result) 'print FldNames$(n) NEXT n calldll #sqm, "SQ3_4_LB_ReleaseRecordset", result as void #main.cb1,"reload" #main.cb1,"selectindex 1" RETURN
[PRAGMAINFO] 'OptList$ SQL$ = "PRAGMA table_info(" + tblName$ ;")" calldll #sqm, "SQ3_4_LB_GetRecordset", SQL$ as ptr,hDBM as long,RSM as struct, ret as long calldll #sqm, "SQ3_4_LB_GetLastMessage", result as long
IF RSM.Rows.struct THEN FOR n = 1 TO RSM.Rows.struct calldll #sqm, "SQ3_4_LB_RecordsetMoveToRow",n as long, result as void calldll #sqm, "SQ3_4_LB_GetRecordsetValueOfRow", "_" as ptr,result as long
IF result THEN fldList$(n)= Winstring(RSM.StrAdr.struct)';" records" ' print records ' print fldList$(n);" ";str$(n) END IF
calldll #sqm, "SQ3_4_LB_RecordsetMoveNext", result as void NEXT n END IF calldll #sqm, "SQ3_4_LB_ReleaseRecordset", result as void numflds=n-1 for n = 1 to numflds FldNames$(n)=word$(fldList$(n),2,"_") fldlen$(n)=word$(fldList$(n),3,"_") fldlen$(n)=UPTO$(fldlen$(n),")") fldlen$(n)=AFTER$(fldlen$(n),"(") fldlen(n)=Val(fldlen$(n)) next #main.cb1,"reload" #main.cb1,"selectindex 1"
RETURN
Function ClipboardSetText(hOwner, strText$) 'Puts some text on the Windows clipboard 'In: The text to place on the clipboard 'Out: 0 if fail, > 0 if text placed on clipboard
strText$ = strText$ + chr$(0) lngSize = Len(strText$) hMemory = GlobalAlloc(_GMEM_MOVEABLE, lngSize)
'Lock the object into memory lpMemory = GlobalLock(hMemory)
'Move the string into the memory we locked CallDll #kernel32,"RtlMoveMemory", lpMemory as ulong, strText$ as ptr, lngSize as long, ret as void
'Don't send clipboard locked memory. r = GlobalUnlock(hMemory)
'Open the clipboard CallDll #user32, "OpenClipboard", hOwner as ulong, r as long
'Remove the current contents of the clipboard CallDll #user32, "EmptyClipboard", r as long
'Add our string to the clipboard as text 'If hSuccess > 0 then we have set the clipboard data CallDll #user32, "SetClipboardData", _CF_TEXT as long, hMemory as ulong, hSuccess as long
'Close the clipboard CallDll #user32, "CloseClipboard", r as long
'If we have set the clipboard data, we no longer own 'the memory--Windows does, so don't free it unless we failed. If hSuccess = 0 Then r = GlobalFree(hMemory) End If
ClipboardSetText = hSuccess End Function
'--- Supporting functions ---
Function GlobalAlloc(type, dwBytes) CallDll #kernel32, "GlobalAlloc", type as long, dwBytes as ulong, GlobalAlloc as long End Function
Function GlobalLock(hMem) CallDll #kernel32, "GlobalLock", hMem as ulong, GlobalLock as long End Function
Function GlobalUnlock(hMem) CallDll #kernel32, "GlobalUnlock", hMem as ulong, GlobalUnlock as long End Function
Function GlobalFree(hMem) CallDll #kernel32, "GlobalFree", hMem as ulong, GlobalFree as long End Function
'*************LISTVIEW INFO
SUB sendMessage hwndListView1 , message,wParm ,lParm calldll #user32, "SendMessageA",_ hwndListView1 as ulong,_ message as long,_ wParm as long,_ lParm as long,_ re as long END SUB
[ClearListView] calldll #user32, "SendMessageA" , hwndListView1 as uLong, LVM.DELETEALLITEMS as Long,_ 0 as long, LVCOLUMN as Struct, re as Long LVITEM.stateMask.struct = LVIS.UNSELECTED ' deselect as it created a problem whith next selection calldll #user32, "SendMessageA", hwndListView1 As uLong, LVM.GETITEMA as long,_ index as long, LVITEM as struct , re As Long RETURN
Function DestroyWindow(hWnd) CallDLL #user32, "DestroyWindow", hWnd As ulong, _ DestroyWindow As long End Function
Function SendMessageLVCOLUMNStruct(hWnd, Msg, wParam) CallDLL #user32, "SendMessageA" , hWnd As ulong, _ Msg As long, _ wParam As long, _ LVCOLUMN As struct, _ SendMessageLVCOLUMNStruct As long End Function
function SendMessageLong(hWnd,msg,w,l) calldll #user32, "SendMessageA", hWnd as ulong, _ msg as long, w as long, l as long,_ SendMessageLong as long end function
'subs------------------------------------------------------------------------------------------------
sub deleteRow rn CallDLL #user32, "SendMessageA", _ hwndListView1 As ulong, _ LVM.DELETEITEM As long, _ rn As long, _ LVITEM As struct, _ r As long end sub
sub updaterow rd$ LVITEM.iSubItem.struct = 0 LVITEM.pszText$.struct =word$(rd$,1," ") LVITEM.state.struct=1 calldll #user32, "SendMessageA" , hwndListView1 as uLong, LVM.SETITEM as Long,_ 0 As Long, LVITEM As struct, re as Long
for x=1 to columnIndex-1 LVITEM.iSubItem.struct = x LVITEM.pszText$.struct = word$(rd$,x+1," ") calldll #user32, "SendMessageA" , hwndListView1 as uLong, LVM.SETITEM as Long,_ 0 As Long, LVITEM As struct, re as Long next x
end sub
'------------------------------------ sub addRow row,rd$
LVITEM.iItem.struct = row LVITEM.iSubItem.struct = 0 LVITEM.pszText$.struct =word$(rd$,1,",")
calldll #user32, "SendMessageA" , hwndListView1 as uLong, LVM.INSERTITEM as Long,_ 0 As Long, LVITEM As struct, re as Long
for x=1 to columnIndex-1 LVITEM.iItem.struct = row LVITEM.iSubItem.struct = x LVITEM.pszText$.struct = word$(rd$,x+1,",")
calldll #user32, "SendMessageA" , hwndListView1 as uLong, LVM.SETITEM as Long,_ 0 As Long, LVITEM As struct, re as Long next x end sub '-------------------------------------- sub addColumn name$ LVCOLUMN.pszText$.struct = name$ calldll #user32, "SendMessageA" , hwndListView1 as uLong, LVM.INSERTCOLUMN as Long,_ columnIndex as long, LVCOLUMN as Struct, re as Long columnIndex=columnIndex+1
end sub
Function createNewListColumn(hListView, columnIndex, columnWidth, headerCaption$) LVCOLUMN.cx.struct = columnWidth LVCOLUMN.pszText.struct = headerCaption$ LVCF.WIDTH = 2 : LVCF.TEXT = 4 LVCOLUMN.mask.struct = LVCF.WIDTH OR LVCF.TEXT createNewListColumn = SendMessageLVCOLUMNStruct(hListView, listViewConstants.LVM.INSERTCOLUMN.struct, columnIndex) End Function
Sub listview1Click LVM.GETITEMA = 4101 : LVM.GETITEMCOUNT = 4100 LVIF.TEXT = 1 : LVM.GETITEMSTATE = 4138 LVIS.SELECTED = 2 : LVIF.STATE = 8 'Returns 0-based index of selected item. Call this routine on a timer 'with resolution of 1000 ms to see which item is selected. calldll #user32, "SendMessageA", hwndListView1 As uLong, LVM.GETITEMCOUNT as long,_ 0 as long, 0 as long, total As Long
For index = 0 To total-1 'check each row LVITEM.mask.struct = LVIF.TEXT Or LVIF.STATE LVITEM.iItem.struct = index 'row LVITEM.iSubItem.struct = 0 'first column LVITEM.cchTextMax.struct = 32 LVITEM.pszText$.struct = Space$(32) LVITEM.stateMask.struct = LVIS.SELECTED calldll #user32, "SendMessageA", hwndListView1 As uLong, LVM.GETITEMA as long,_ index as long, LVITEM as struct , re As Long state = LVITEM.state.struct 'selected state of item If state And LVIS.SELECTED Then Exit For End If Next End Sub Function isSelected$(Rec2Edit$) LVM.GETITEMA = 4101 : LVM.GETITEMCOUNT = 4100 LVIF.TEXT = 1 : LVM.GETITEMSTATE = 4138 LVIS.SELECTED = 2 : LVIF.STATE = 8 'Returns 0-based index of selected item. Call this routine on a timer 'with resolution of 1000 ms to see which item is selected. calldll #user32, "SendMessageA", hwndListView1 As uLong, LVM.GETITEMCOUNT as long,_ 0 as long, 0 as long, total As Long
For index = 0 To total-1 'check each row LVITEM.mask.struct = LVIF.TEXT Or LVIF.STATE LVITEM.iItem.struct = index 'row LVITEM.iSubItem.struct = 0 'first column LVITEM.cchTextMax.struct = 32 LVITEM.pszText$.struct = Space$(32) LVITEM.stateMask.struct = LVIS.SELECTED calldll #user32, "SendMessageA", hwndListView1 As uLong, LVM.GETITEMA as long,_ index as long, LVITEM as struct , re As Long state = LVITEM.state.struct 'selected state of item If state And LVIS.SELECTED Then isSelected$ =RecFound$(LVITEM.iItem.struct+1)' watch for saving edited data Exit For End If Next end function
[sqlExec] print "here ";SQL$ calldll #sqm, "SQ3_4_LB_GetRecordset", SQL$ as ptr,hDBM as long,RSM as struct, result as long if result = 0 then calldll #sqm, "SQ3_4_LB_GetLastMessage", result as long sqlExec$ = Winstring(result) cols = 0 rows = 0
else FOR n = 1 TO RSM.Rows.struct calldll #sqm, "SQ3_4_LB_RecordsetMoveToRow",n as long, ret as void calldll #sqm, "SQ3_4_LB_GetRecordsetValueOfRow", "_" as ptr,result as long
cols = RSM.Cols.struct rows = RSM.Rows.struct sqlExec$ = "" ' fldList$(n)= Winstring(RSM.StrAdr.struct)';" records" ' print records ' print fldList$(n);" ";str$(n) next end if RecsPerPage=19 pages=int(rows/19) maxpages=int((rows)/RecsPerPage) #main.pgs, "Pages = " ;pages+1 #main.rcs, "Records = ";rows print rows
print cols sqlExec$ = "" RETURN
Attachments:MELK.zip (392.9 KB)
|
|
|
Post by Chris Iverson on Jan 2, 2019 23:39:43 GMT -5
adding row 0: 144,Krokus,101,250,6-12-20018,18,9.6,13 adding row 0: 143,Krokus,35,250,6-12-20018,18,11.8,3 adding row 0: 141,Krokus,38,250,6-12-20018,18,17.8,6 adding row 0: 140,Krokus,11,250,6-12-20018,18,17.8,3 adding row 0: 138,Krokus,100,250,6-12-20018,18,12.4,12 adding row 0: 137,Krokus,15,250,6-12-20018,17,14.8,7 adding row 0: 133,Krokus,114,250,6-12-20018,19,14,10 adding row 0: 130,Krokus,82,250,6-12-20018,18,5.4,10 adding row 0: 128,Krokus,108,250,6-12-20018,18,6.8,12 adding row 0: 125,Krokus,4,250,6-12-20018,17,14.6,4 adding row 0: 124,Krokus,116,250,6-12-20018,19,11.6,12 adding row 0: 123,Krokus,13,250,6-12-20018,18,11.6,5 adding row 0: 120,Krokus,96,250,6-12-20018,18,11.8,16 adding row 0: 119,Krokus,31,250,6-12-20018,18,11.2,7 adding row 0: 115,Krokus,75,250,6-12-20018,17,12.8,11 adding row 0: 114,Krokus,99,250,6-12-20018,18,7,11 adding row 0: 111,Krokus,113,250,6-12-20018,19,15.8,9 adding row 0: 108,Krokus,118,250,6-12-20018,19,18.2,14 adding row 0: 107,Krokus,97,250,6-12-20018,18,14,9 adding row 0: 106,Krokus,9,250,6-12-20018,18,15.2,1 adding row 0: 103,Krokus,16,250,6-12-20018,18,6.363,8 adding row 0: 102,Krokus,107,250,6-12-20018,18,7,11 adding row 0: 101,Krokus,45,250,6-12-20018,19,8.2,5 adding row 0: 100,Krokus,14,250,6-12-20018,18,18.2,6 adding row 0: 99,Krokus,46,250,6-12-20018,19,14.4,6 adding row 0: 98,Krokus,56,250,6-12-20018,19,6.666,8 adding row 0: 97,Krokus,103,250,6-12-20018,18,10.8,15 adding row 0: 96,Krokus,111,250,6-12-20018,18,10,15 adding row 0: 95,Krokus,84,250,6-12-20018,18,7.2,12 adding row 0: 94,Krokus,91,250,6-12-20018,18,21,11 adding row 0: 92,Krokus,81,250,6-12-20018,18,15.4,9 adding row 0: 91,Krokus,33,250,6-12-20018,18,8.4,1 adding row 0: 90,Krokus,88,250,6-12-20018,18,8,16 adding row 0: 89,Krokus,90,250,6-12-20018,18,13.6,10 adding row 0: 88,Krokus,17,250,6-12-20018,18,6.8,1 adding row 0: 87,Krokus,42,250,6-12-20018,19,8.4,2 adding row 0: 86,Krokus,93,250,6-12-20018,18,15.4,13 adding row 0: 85,Krokus,28,250,6-12-20018,18,14.2,4 adding row 0: 81,Krokus,36,250,6-12-20018,18,18.2,4 adding row 0: 79,Krokus,87,250,6-12-20018,18,10.8,15 adding row 0: 78,Krokus,89,250,6-12-20018,18,20.6,9 adding row 0: 77,Krokus,40,250,6-12-20018,18,8.08,8 adding row 0: 76,Krokus,5,250,6-12-20018,17,4.8,5 adding row 0: 72,Krokus,29,250,6-12-20018,18,13.2,5 adding row 0: 70,Krokus,76,250,6-12-20018,17,14.4,12 adding row 0: 69,Krokus,8,250,6-12-20018,17,6.565,8 adding row 0: 68,Krokus,25,250,6-12-20018,18,8.6,1 adding row 0: 67,Krokus,41,250,6-12-20018,19,17,1 adding row 0: 66,Krokus,30,250,6-12-20018,18,8.6,6 adding row 0: 65,Krokus,32,250,6-12-20018,18,5.05,8 adding row 0: 64,Krokus,79,250,6-12-20018,17,16.4,15 adding row 0: 63,Krokus,94,250,6-12-20018,18,20.2,14 adding row 0: 62,Krokus,49,250,6-12-20018,19,8,1 adding row 0: 61,Krokus,105,250,6-12-20018,19,14,9 adding row 0: 58,Krokus,23,250,6-12-20018,18,12.2,7 adding row 0: 57,Krokus,26,250,6-12-20018,18,13.4,2 adding row 0: 54,Krokus,22,250,6-12-20018,18,10.4,6 adding row 0: 53,Krokus,37,250,6-12-20018,18,10.2,5 adding row 0: 52,Krokus,7,250,6-12-20018,17,11.4,7 adding row 0: 51,Krokus,24,250,6-12-20018,18,9.797,8 adding row 0: 50,Krokus,54,250,6-12-20018,19,15,6 adding row 0: 49,Krokus,21,250,6-12-20018,18,9.2,5 adding row 0: 48,Krokus,10,250,6-12-20018,18,14.6,2 adding row 0: 46,Krokus,83,250,6-12-20018,18,13,11 adding row 0: 45,Krokus,27,250,6-12-20018,18,15.4,3 adding row 0: 44,Krokus,52,250,6-12-20018,19,16.6,4 adding row 0: 43,Krokus,95,250,6-12-20018,18,16.2,15 adding row 0: 42,Krokus,104,250,6-12-20018,18,10.8,16 adding row 0: 41,Krokus,18,250,6-12-20018,18,12.6,2 adding row 0: 39,Krokus,6,250,6-12-20018,17,18.2,6 adding row 0: 38,Krokus,110,250,6-12-20018,18,19.6,14 adding row 0: 36,Krokus,43,250,6-12-20018,19,14.4,3 adding row 0: 35,Krokus,73,250,6-12-20018,17,12.2,9 adding row 0: 34,Krokus,74,250,6-12-20018,17,10,10 adding row 0: 33,Krokus,39,250,6-12-20018,18,11.2,7 adding row 0: 32,Krokus,85,250,6-12-20018,17,15,13 adding row 0: 31,Krokus,115,250,6-12-20018,19,16.2,11 adding row 0: 30,Krokus,92,250,6-12-20018,18,13.8,12 adding row 0: 29,Krokus,117,250,6-12-20018,19,13.4,13 adding row 0: 28,Krokus,34,250,6-12-20018,18,12.8,2 adding row 0: 27,Krokus,109,250,6-12-20018,18,9.6,13 adding row 0: 26,Krokus,51,250,6-12-20018,17,17.6,3 adding row 0: 24,Krokus,80,250,6-12-20018,17,13.8,16 adding row 0: 23,Krokus,78,250,6-12-20018,17,6.8,14 adding row 0: 22,Krokus,47,250,6-12-20018,19,12.2,7 adding row 0: 21,Krokus,48,250,6-12-20018,19,6.464,8 adding row 0: 20,Krokus,50,250,6-12-20018,19,12.2,2 adding row 0: 19,Krokus,44,250,6-12-20018,19,7,4 adding row 0: 18,Krokus,112,250,6-12-20018,18,13,16 adding row 0: 17,Krokus,106,250,6-12-20018,18,12.4,10 adding row 0: 16,Krokus,102,250,6-12-20018,18,23,14 adding row 0: 15,Krokus,86,250,6-12-20018,18,16.6,14 adding row 0: 14,Krokus,98,250,6-12-20018,18,18.8,10 adding row 0: 12,Krokus,19,250,6-12-20018,18,8.4,3 adding row 0: 10,Krokus,119,250,6-12-20018,19,11,15 adding row 0: 9,Krokus,55,250,6-12-20018,19,11.6,7 adding row 0: 8,Krokus,77,250,6-12-20018,17,11.4,13 adding row 0: 7,Krokus,12,250,6-12-20018,18,10.8,4 adding row 0: 5,Krokus,120,250,6-12-20018,19,14.2,16 adding row 0: 3,Krokus,20,250,6-12-20018,18,12,4 adding row 0: 2,Krokus,53,250,6-12-20018,19,10.8,5 adding row 0:
Got this after adding
print "adding row " + str$(row) + ": " + rd$
to the beginning of the addRow subroutine. Based on this, we can see that the final row that gets added is empty. The addRow routine is working properly. The data for the last row just isn't being loaded in.
Not sure yet where, but I'm almost completely certain the issue is an off-by-one indexing error in some part of your code that interacts with the DB.
EDIT: My bad, it's not the data loading. It's the count of objects being added. The last index that gets added is blank because there's no more data. The off-by-one is somewhere outputting to screen.
EDIT2: Oh, duh, that was easy. You're using the wrong count for 'r' when calling addRow.
FOR r = 1 TO RSM.Rows.struct
You start 'r' at 1 when loading from the DB. This creates a one-indexed array.
Then, when adding the data to the screen, you count down to, and include, zero:
for r=r-1 to 0 step -1
Change that '0' to a '1' and it should work fine.
for r=r-1 to 1 step -1
adding row 0: 144,Krokus,101,250,6-12-20018,18,9.6,13 adding row 0: 143,Krokus,35,250,6-12-20018,18,11.8,3 adding row 0: 141,Krokus,38,250,6-12-20018,18,17.8,6 adding row 0: 140,Krokus,11,250,6-12-20018,18,17.8,3 adding row 0: 138,Krokus,100,250,6-12-20018,18,12.4,12 adding row 0: 137,Krokus,15,250,6-12-20018,17,14.8,7 adding row 0: 133,Krokus,114,250,6-12-20018,19,14,10 adding row 0: 130,Krokus,82,250,6-12-20018,18,5.4,10 adding row 0: 128,Krokus,108,250,6-12-20018,18,6.8,12 adding row 0: 125,Krokus,4,250,6-12-20018,17,14.6,4 adding row 0: 124,Krokus,116,250,6-12-20018,19,11.6,12 adding row 0: 123,Krokus,13,250,6-12-20018,18,11.6,5 adding row 0: 120,Krokus,96,250,6-12-20018,18,11.8,16 adding row 0: 119,Krokus,31,250,6-12-20018,18,11.2,7 adding row 0: 115,Krokus,75,250,6-12-20018,17,12.8,11 adding row 0: 114,Krokus,99,250,6-12-20018,18,7,11 adding row 0: 111,Krokus,113,250,6-12-20018,19,15.8,9 adding row 0: 108,Krokus,118,250,6-12-20018,19,18.2,14 adding row 0: 107,Krokus,97,250,6-12-20018,18,14,9 adding row 0: 106,Krokus,9,250,6-12-20018,18,15.2,1 adding row 0: 103,Krokus,16,250,6-12-20018,18,6.363,8 adding row 0: 102,Krokus,107,250,6-12-20018,18,7,11 adding row 0: 101,Krokus,45,250,6-12-20018,19,8.2,5 adding row 0: 100,Krokus,14,250,6-12-20018,18,18.2,6 adding row 0: 99,Krokus,46,250,6-12-20018,19,14.4,6 adding row 0: 98,Krokus,56,250,6-12-20018,19,6.666,8 adding row 0: 97,Krokus,103,250,6-12-20018,18,10.8,15 adding row 0: 96,Krokus,111,250,6-12-20018,18,10,15 adding row 0: 95,Krokus,84,250,6-12-20018,18,7.2,12 adding row 0: 94,Krokus,91,250,6-12-20018,18,21,11 adding row 0: 92,Krokus,81,250,6-12-20018,18,15.4,9 adding row 0: 91,Krokus,33,250,6-12-20018,18,8.4,1 adding row 0: 90,Krokus,88,250,6-12-20018,18,8,16 adding row 0: 89,Krokus,90,250,6-12-20018,18,13.6,10 adding row 0: 88,Krokus,17,250,6-12-20018,18,6.8,1 adding row 0: 87,Krokus,42,250,6-12-20018,19,8.4,2 adding row 0: 86,Krokus,93,250,6-12-20018,18,15.4,13 adding row 0: 85,Krokus,28,250,6-12-20018,18,14.2,4 adding row 0: 81,Krokus,36,250,6-12-20018,18,18.2,4 adding row 0: 79,Krokus,87,250,6-12-20018,18,10.8,15 adding row 0: 78,Krokus,89,250,6-12-20018,18,20.6,9 adding row 0: 77,Krokus,40,250,6-12-20018,18,8.08,8 adding row 0: 76,Krokus,5,250,6-12-20018,17,4.8,5 adding row 0: 72,Krokus,29,250,6-12-20018,18,13.2,5 adding row 0: 70,Krokus,76,250,6-12-20018,17,14.4,12 adding row 0: 69,Krokus,8,250,6-12-20018,17,6.565,8 adding row 0: 68,Krokus,25,250,6-12-20018,18,8.6,1 adding row 0: 67,Krokus,41,250,6-12-20018,19,17,1 adding row 0: 66,Krokus,30,250,6-12-20018,18,8.6,6 adding row 0: 65,Krokus,32,250,6-12-20018,18,5.05,8 adding row 0: 64,Krokus,79,250,6-12-20018,17,16.4,15 adding row 0: 63,Krokus,94,250,6-12-20018,18,20.2,14 adding row 0: 62,Krokus,49,250,6-12-20018,19,8,1 adding row 0: 61,Krokus,105,250,6-12-20018,19,14,9 adding row 0: 58,Krokus,23,250,6-12-20018,18,12.2,7 adding row 0: 57,Krokus,26,250,6-12-20018,18,13.4,2 adding row 0: 54,Krokus,22,250,6-12-20018,18,10.4,6 adding row 0: 53,Krokus,37,250,6-12-20018,18,10.2,5 adding row 0: 52,Krokus,7,250,6-12-20018,17,11.4,7 adding row 0: 51,Krokus,24,250,6-12-20018,18,9.797,8 adding row 0: 50,Krokus,54,250,6-12-20018,19,15,6 adding row 0: 49,Krokus,21,250,6-12-20018,18,9.2,5 adding row 0: 48,Krokus,10,250,6-12-20018,18,14.6,2 adding row 0: 46,Krokus,83,250,6-12-20018,18,13,11 adding row 0: 45,Krokus,27,250,6-12-20018,18,15.4,3 adding row 0: 44,Krokus,52,250,6-12-20018,19,16.6,4 adding row 0: 43,Krokus,95,250,6-12-20018,18,16.2,15 adding row 0: 42,Krokus,104,250,6-12-20018,18,10.8,16 adding row 0: 41,Krokus,18,250,6-12-20018,18,12.6,2 adding row 0: 39,Krokus,6,250,6-12-20018,17,18.2,6 adding row 0: 38,Krokus,110,250,6-12-20018,18,19.6,14 adding row 0: 36,Krokus,43,250,6-12-20018,19,14.4,3 adding row 0: 35,Krokus,73,250,6-12-20018,17,12.2,9 adding row 0: 34,Krokus,74,250,6-12-20018,17,10,10 adding row 0: 33,Krokus,39,250,6-12-20018,18,11.2,7 adding row 0: 32,Krokus,85,250,6-12-20018,17,15,13 adding row 0: 31,Krokus,115,250,6-12-20018,19,16.2,11 adding row 0: 30,Krokus,92,250,6-12-20018,18,13.8,12 adding row 0: 29,Krokus,117,250,6-12-20018,19,13.4,13 adding row 0: 28,Krokus,34,250,6-12-20018,18,12.8,2 adding row 0: 27,Krokus,109,250,6-12-20018,18,9.6,13 adding row 0: 26,Krokus,51,250,6-12-20018,17,17.6,3 adding row 0: 24,Krokus,80,250,6-12-20018,17,13.8,16 adding row 0: 23,Krokus,78,250,6-12-20018,17,6.8,14 adding row 0: 22,Krokus,47,250,6-12-20018,19,12.2,7 adding row 0: 21,Krokus,48,250,6-12-20018,19,6.464,8 adding row 0: 20,Krokus,50,250,6-12-20018,19,12.2,2 adding row 0: 19,Krokus,44,250,6-12-20018,19,7,4 adding row 0: 18,Krokus,112,250,6-12-20018,18,13,16 adding row 0: 17,Krokus,106,250,6-12-20018,18,12.4,10 adding row 0: 16,Krokus,102,250,6-12-20018,18,23,14 adding row 0: 15,Krokus,86,250,6-12-20018,18,16.6,14 adding row 0: 14,Krokus,98,250,6-12-20018,18,18.8,10 adding row 0: 12,Krokus,19,250,6-12-20018,18,8.4,3 adding row 0: 10,Krokus,119,250,6-12-20018,19,11,15 adding row 0: 9,Krokus,55,250,6-12-20018,19,11.6,7 adding row 0: 8,Krokus,77,250,6-12-20018,17,11.4,13 adding row 0: 7,Krokus,12,250,6-12-20018,18,10.8,4 adding row 0: 5,Krokus,120,250,6-12-20018,19,14.2,16 adding row 0: 3,Krokus,20,250,6-12-20018,18,12,4 adding row 0: 2,Krokus,53,250,6-12-20018,19,10.8,5
|
|