|
Post by dan1101 on Sept 24, 2021 10:31:02 GMT -5
Greetings all,
I am trying to find a way to display a table of information in Liberty BASIC, similar to a spreadsheet, in a single window. Specifically I am trying to display a table with 8 columns by 15 rows, but I am hoping for a general solution I can use in a variety of situations. My data has mixed numeric and string values in the same table. I have thought of simply creating a window with 120 tiny individual textboxes laid out in a grid pattern, and I can probably accomplish my goal by doing this, but this seems highly inefficient and very cumbersome to manage. If anyone has any suggestions for an approach to display something like a grid, spreadsheet, or table, in Liberty BASIC I would appreciate your input.
Thank you!
-- Dan
|
|
|
Post by tsh73 on Sept 24, 2021 10:40:44 GMT -5
|
|
|
Post by Walt Decker on Sept 24, 2021 11:17:54 GMT -5
If you are not adverse to using API it can be done using an edit control, i. e. LB's TEXTBOX by setting the the appropriate styles for the control and then using the appropriate EM... messages. It can be a bit complicated, however.
On second thought it can be done with the textedit control.
Set the font of the control to a fixed font, e. g. Courier New
Set a string array up with M rows by N columns, e. g. DIM StrAry$(15, 25) fill each row and column with appropriate data
parse each row and column to find the maximum length for each column pad each column with spaces to the maximum for that column + 1 when done, go back and append CRLF$ (CHR$(13) + CHR$(10)) to the end of each column.
Set up a string that will contain all of the array info and set the text of the control with that string.
|
|
|
Post by dan1101 on Sept 24, 2021 14:41:21 GMT -5
Thank you for the quick replies. They are much appreciated.
Walt, I had thought of something roughly along those lines, but was worried it could create a string that exceeded the length limit for a variable so I abandoned the attempt. Later, I learned that in LB, string variables essentially have no length limits. I will give that approach another look if I can't puzzle my way through the code in the examples from tsh73.
tsh73, the code examples in the thread you linked produce exactly the result I was looking for, but the complexity of some of the code is pushing the limits of my skills at the moment. I will spend some time tearing apart the code and hopefully be able to incorporate the essential core into my project.
Thanks again for taking the time to help out a rookie. You folks are awesome.
|
|
|
Post by tsh73 on Sept 24, 2021 15:08:00 GMT -5
If you only want to *show* table, not edit it, it will be simpler
|
|
|
Post by Walt Decker on Sept 24, 2021 15:45:19 GMT -5
' GLOBAL UbndRow, _ UbndCol
UbndRow = -1 UbndCol = -1
DIM DtaAry$(UbndRow, UbndCol)
TxtIn$ = ""
MaxLne = 0
A = FN.GetData() MaxLen = FN.DataPad() TxtIn$ = FN.Concatenate$(MaxLen)
WindowWidth = 280 WindowHeight = 260
TEXTEDITOR #DMO.EDT, 5, 5, 270, 200 OPEN "DMO" FOR WINDOW AS #DMO PRINT #DMO, "TRAPCLOSE DMO.DONE" PRINT #DMO.EDT, "!font courier new 10" PRINT #DMO.EDT, TxtIn$ WAIT
'--------------------------------------------------------------- '---------------------------------------------------------------
SUB DMO.DONE WinHndl$ CLOSE #DMO END END SUB
'--------------------------------------------------------------- '---------------------------------------------------------------
FUNCTION FN.GetData()
DATA "Peter", "Piper", "Picked", "a" DATA "Mary", "had", "a", "little" DATA "Now", "is", "the", "time"
UbndRow = 2 UbndCol = 3 Row = 0 Col = 0
REDIM DtaAry$(UbndRow, UbndCol) TxtDta$ = "" FOR I = 0 TO UbndRow FOR J = 0 TO UbndCol READ TxtDta$ DtaAry$(I, J) = TxtDta$ NEXT J NEXT I
END FUNCTION
'--------------------------------------------------------------- '---------------------------------------------------------------
FUNCTION FN.DataPad()
MaxLen = 0 DtaLen = 0 DtaRow = -1 DtaCol = -1 MaxLen = -1
CRLF$ = CHR$(13) + CHR$(10)
FOR I = 0 TO UbndRow FOR J = 0 TO UbndCol DtaLen = LEN(DtaAry$(I, J)) IF DtaLen > MaxLen THEN DtaRow = I DtaCol = J MaxLen = DtaLen END IF NEXT J
MaxLen = MaxLen + 1
NEXT I
FN.DataPad = MaxLen END FUNCTION
'--------------------------------------------------------------- '---------------------------------------------------------------
FUNCTION FN.Concatenate$(MaxLen)
TxtOut$ = "" TxtIn$ = "" CRLF$ = CHR$(13) + CHR$(10)
TxtLen = 0
FOR I = 0 TO UbndRow FOR J = 0 TO UbndCol TxtIn$ = DtaAry$(I, J) TxtLen = LEN(TxtIn$) TxtIn$ = TxtIn$ + SPACE$(MaxLen - TxtLen) TxtOut$ = TxtOut$ + TxtIn$ NEXT J TxtOut$ = TxtOut$ + CRLF$ NEXT I
FN.Concatenate$ = TxtOut$ END FUNCTION
If you want to edit the data I would recommend using an edit box along with API to give you control of the text and columns, i. e. you can change the caret to indicate over-write or insert mode, and know exactly the line and column being edited.
|
|
|
Post by Brandon Parker on Sept 24, 2021 16:03:40 GMT -5
I, personally, would go with a ListView myself, but I am sure most frequent forum visitors are very well aware of that.
Here is some example code that I have provided previously.
NoMainWin Global False : False = 0 Global True : True = 1 Global currentRow : currentRow = 0
listViewHandle(0) = _NULL
Call initializeListViewConstants
WindowWidth = 530 WindowHeight = 335 Button #Example.btnAddItem, "Add Item", AddItem, UL, 5, (WindowHeight - 67) Button #Example.btnEditItem, "Edit Item", EditItem, UL, 202.5, (WindowHeight - 67) Button #Example.btnDeleteItem, "Delete Item", DeleteItem, UL, 405, (WindowHeight - 67)
Open "ListView Example" For Window As #Example Call InitCommonControls style = _WS_CHILD Or _WS_VISIBLE Or listViewConstants.LVS.NOSORTHEADER.struct _ Or listViewConstants.LVS.REPORT.struct Or listViewConstants.LVS.SHOWSELALWAYS.struct _ Or listViewConstants.LVS.SINGLESEL.struct styleEx = _WS_EX_CLIENTEDGE Or _WS_EX_DLGMODALFRAME 'Or listViewConstants.LVS.EX.DOUBLEBUFFER.struct listViewHandle(0) = CreateListView(style, styleEx, Hwnd(#Example), GetWindowLong(Hwnd(#Example), _GWL_HINSTANCE), 5, 23, 505, 244) result = setListViewFullRowSelect(listViewHandle(0)) result = listViewShowGrid(listViewHandle(0)) result = createNewListColumn(listViewHandle(0), 0, 100, " Item 1") result = createNewListColumn(listViewHandle(0), 1, 100, " Item 2") result = createNewListColumn(listViewHandle(0), 2, 100, " Item 3") #Example "TrapClose Quit"
While Hwnd(#Example) Scan result = Sleep(1) Wend
Sub Quit handle$ result = DestroyWindow(listViewHandle(0)) Close #handle$ End End Sub
Sub AddItem handle$ result = AddListViewData(listViewHandle(0), currentRow, 0, "Data1") result = EditListViewData(listViewHandle(0), currentRow, 1, "Data2") result = EditListViewData(listViewHandle(0), currentRow, 2, "Data3") result = SelectListViewRow(listViewHandle(0), currentRow, True) currentRow = (currentRow + 1) End Sub
Sub EditItem handle$ numListViewEntries = GetListViewItemCount(listViewHandle(0)) If Not(numListViewEntries) Then Exit Sub row = GetSelectedListViewRow(listViewHandle(0)) item1$ = GetListViewText$(listViewHandle(0), row, 0) item2$ = GetListViewText$(listViewHandle(0), row, 1) item3$ = GetListViewText$(listViewHandle(0), row, 2)
result = EditListViewData(listViewHandle(0), row, 0, GetListViewText$(listViewHandle(0), row, 0) + " Edited") result = EditListViewData(listViewHandle(0), row, 1, GetListViewText$(listViewHandle(0), row, 1) + " Edited") result = EditListViewData(listViewHandle(0), row, 2, GetListViewText$(listViewHandle(0), row, 2) + " Edited")
result = SelectListViewRow(listViewHandle(0), row, True) End Sub
Sub DeleteItem handle$ numListViewEntries = GetListViewItemCount(listViewHandle(0)) If Not(numListViewEntries) Then Exit Sub row = GetSelectedListViewRow(listViewHandle(0)) result = SendMessageLVITEMStruct(listViewHandle(0), listViewConstants.LVM.DELETEITEM.struct, row) currentRow = (currentRow - 1) End Sub
Sub InitCommonControls CallDLL #comctl32, "InitCommonControls", ret As void End Sub
Sub initializeListViewConstants 'Create the structs for ListViews
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
Struct LVFINDINFO, flags As ulong, _ psz As ptr, _ lParam As ulong, _ pt As ulong, _ 'point structure vkDirection As ulong
Struct listViewConstants, LVP.DBLCLK As long, _ LVS.REPORT As long, _ LVS.SINGLESEL As long, _ LVS.SHOWSELALWAYS As long, _ LVS.NOSORTHEADER As long, _ LVS.EXDOUBLEBUFFER As long, _ LVS.EX.FULLROWSELECT As long, _ LVS.EX.CHECKBOXES As long, _ LVIS.FOCUSED As long, _ LVIS.UNSELECTED As long, _ LVIS.SELECTED As long, _ LVIS.CHECKED As long, _ LVIS.UNCHECKED As long, _ LVIS.STATEIMAGEMASK As long, _ LVIF.TEXT As long, _ LVIF.STATE As long, _ LVIR.BOUNDS As long, _ LVFI.STRING As long, _ LVFI.PARTIAL As long, _ LVN.ITEMCHANGED As long, _ LVM.ENSUREVISIBLE As long, _ LVM.SETITEMSTATE As long, _ LVM.GETITEMSTATE As long, _ LVM.GETITEMTEXT As long, _ LVM.FINDITEMA As long, _ LVM.SETITEM As long, _ LVM.GETITEMCOUNT As long, _ LVM.GETITEMA As long, _ LVM.GETSUBITEMRECT As long, _ LVM.DELETEITEM As long, _ LVM.INSERTITEM As long, _ LVM.INSERTCOLUMN As long, _ LVM.SETEXTENDEDLISTVIEWSTYLE As long
'LVM_FIRST = &H1000 or 4096 listViewConstants.LVP.DBLCLK.struct = False listViewConstants.LVS.REPORT.struct = 1 listViewConstants.LVS.SINGLESEL.struct = 4 listViewConstants.LVS.SHOWSELALWAYS.struct = 8 listViewConstants.LVS.NOSORTHEADER.struct = 32768 listViewConstants.LVS.EXDOUBLEBUFFER.struct = 10000 listViewConstants.LVS.EX.FULLROWSELECT.struct = 32 listViewConstants.LVS.EX.CHECKBOXES.struct = 4 listViewConstants.LVIS.FOCUSED.struct = 1 listViewConstants.LVIS.UNSELECTED.struct = 0 listViewConstants.LVIS.SELECTED.struct = 2 listViewConstants.LVIS.CHECKED.struct = 8192 listViewConstants.LVIS.UNCHECKED.struct = 4096 listViewConstants.LVIS.STATEIMAGEMASK.struct = 61440 listViewConstants.LVIF.TEXT.struct = 1 listViewConstants.LVIF.STATE.struct = 8 listViewConstants.LVIR.BOUNDS.struct = 0 listViewConstants.LVFI.STRING.struct = 2 listViewConstants.LVFI.PARTIAL.struct = 8 listViewConstants.LVN.ITEMCHANGED.struct = -101 listViewConstants.LVM.ENSUREVISIBLE.struct = 4115 listViewConstants.LVM.SETITEMSTATE.struct = 4139 listViewConstants.LVM.GETITEMSTATE.struct = 4140 listViewConstants.LVM.GETITEMTEXT.struct = 4141 listViewConstants.LVM.FINDITEMA.struct = 4109 listViewConstants.LVM.SETITEM.struct = 4102 listViewConstants.LVM.GETITEMCOUNT.struct = 4100 listViewConstants.LVM.GETITEMA.struct = 4101 listViewConstants.LVM.GETSUBITEMRECT.struct = 4152 listViewConstants.LVM.DELETEITEM.struct = 4104 listViewConstants.LVM.INSERTITEM.struct = 4103 listViewConstants.LVM.INSERTCOLUMN.struct = 4123 listViewConstants.LVM.SETEXTENDEDLISTVIEWSTYLE.struct = 4150 End Sub
Function CreateListView(ByRef style, ByRef styleEx, ByRef hParent, ByRef hInstance, ByRef xloc, ByRef yloc, ByRef width, ByRef height) className$ = "SysListView32" + chr$(0) CallDLL #user32, "CreateWindowExA", styleEx As ulong, _ ' extended style className$ As ptr, _ ' class name "" As ptr, _ style As ulong, _ ' style xloc As long, _ ' left x yloc As long, _ ' top y width As long, _ ' width height As long, _ ' height hParent As ulong, _ ' parent hWnd _NULL As ulong, _ hInstance As ulong, _ ' hInstance _NULL As ulong, _ CreateListView As ulong 'Hwnd to ListView
'LVCF.WIDTH = 2 : LVCF.TEXT = 4 LVCOLUMN.mask.struct = LVCF.WIDTH OR LVCF.TEXT End Function
Function GetWindowLong(hWnd, index) CallDLL #user32, "GetWindowLongA", hWnd As ulong, _ index As long, _ GetWindowLong As long End Function
Function GetListViewItemCount(hWndLV) GetListViewItemCount = SendMessage(hWndLV, listViewConstants.LVM.GETITEMCOUNT.struct, 0, 0) End Function
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
Function AddListViewData(hWndLV, row, column, myData$) LVITEM.mask.struct = listViewConstants.LVIF.TEXT.struct LVITEM.iItem.struct = row LVITEM.iSubItem.struct = column LVITEM.pszText.struct = myData$ result = SendMessageLVITEMStruct(hWndLV, listViewConstants.LVM.INSERTITEM.struct, 0) AddListViewData = SendMessage(hWndLV, listViewConstants.LVM.GETITEMSTATE.struct, 0, 0) End Function
Function EditListViewData(hWndLV, row, column, myData$) LVITEM.mask.struct = listViewConstants.LVIF.TEXT.struct LVITEM.iItem.struct = row LVITEM.iSubItem.struct = column LVITEM.pszText.struct = myData$ EditListViewData = SendMessageLVITEMStruct(hWndLV, listViewConstants.LVM.SETITEM.struct, 0) End Function
Function SelectListViewRow(hWndLV, row, setFocus) LVITEM.iItem.struct = row LVITEM.iSubItem.struct = 0 LVITEM.mask.struct = listViewConstants.LVIF.STATE.struct LVITEM.state.struct = listViewConstants.LVIS.SELECTED.struct If setFocus = True Then LVITEM.state.struct = (LVITEM.state.struct Or listViewConstants.LVIS.FOCUSED.struct) End If 'SelectListViewRow = SetFocus(hWndLV) SelectListViewRow = SendMessage(hWndLV, listViewConstants.LVM.ENSUREVISIBLE.struct, row, False) SelectListViewRow = SendMessageLVITEMStruct(hWndLV, listViewConstants.LVM.SETITEM.struct, 0) End Function
Function setListViewFullRowSelect(hListView) setListViewFullRowSelect = SendMessage(hListView, 4150, 32, 32)'LVS_EX_FULLROWSELECT End Function
Function listViewShowGrid(hListView) listViewShowGrid = SendMessage(hListView, 4150, 1, 1)'LVS_EX_GRIDLINES End Function
Function SendMessage(hWnd, Msg, wParam, lParam) CallDLL #user32, "SendMessageA", hWnd As ulong, _ Msg As long, _ wParam As long, _ lParam As long, _ SendMessage As long End Function
Function SendMessageLVITEMStruct(hWnd, Msg, wParam) CallDLL #user32, "SendMessageA", hWnd As ulong, _ Msg As long, _ wParam As long, _ LVITEM As struct, _ SendMessageLVITEMStruct 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 DestroyWindow(hWnd) CallDLL #user32, "DestroyWindow", hWnd As ulong, _ DestroyWindow As long End Function
Function GetSelectedListViewRow(hWndLV) GetSelectedListViewRow = -1
numListViewEntries = GetListViewItemCount(hWndLV) For row = 0 To (numListViewEntries - 1) LVITEM.mask.struct = listViewConstants.LVIF.STATE.struct LVITEM.iItem.struct = row LVITEM.iSubItem.struct = 0 'first column LVITEM.stateMask.struct = listViewConstants.LVIS.SELECTED.struct result = SendMessageLVITEMStruct(hWndLV, listViewConstants.LVM.GETITEMA.struct, 0) If LVITEM.state.struct And listViewConstants.LVIS.SELECTED.struct Then GetSelectedListViewRow = row Exit Function Else If row = (numListViewEntries - 1) Then GetSelectedListViewRow = -1 Exit Function End If End If Next row End Function
Function GetListViewText$(hWndLV, row, column) LVITEM.mask.struct = listViewConstants.LVIF.TEXT.struct LVITEM.iSubItem.struct = column LVITEM.pszText.struct = Space$(_MAX_PATH) + chr$(0) LVITEM.cchTextMax.struct = Len(Winstring(LVITEM.pszText.struct)) EditListViewData = SendMessageLVITEMStruct(hWndLV, listViewConstants.LVM.GETITEMTEXT.struct, row) GetListViewText$ = Trim$(Winstring(LVITEM.pszText.struct)) End Function
Function Sleep(milliseconds) CallDLL #kernel32, "Sleep", milliseconds As ulong, _ ret As void End Function
{:0)
Brandon Parker
|
|
|
Post by Walt Decker on Sept 24, 2021 16:20:27 GMT -5
Mr. Parker, I agree. However, I think he is not yet prepared for that route.
I think most users on this forum are not prepared to deal with the common controls or enhance their controls with API.
|
|
|
Post by Brandon Parker on Sept 24, 2021 16:42:32 GMT -5
Well, everyone starts somewhere, and if people are never exposed to new things then they may never know they exist.
Also, making super-easy Subroutines/Functions for people to use allows them to achieve things they want to with nice results. They can always go back and learn from any/all code provided by others. I know I have and will continue to do so...
{:0)
Brandon Parker
|
|
|
Post by pablosl on Sept 24, 2021 21:40:16 GMT -5
Mr. Parker, I would like to have a GUI with a listbox at the left with 4 items and a ListView at right. I want to select an item in the listbox and then change the contents/columns in the ListView. Perhaps having 4 different ListViews and hide/show?. Many thanks in advance. -Pablo
|
|
|
Post by Brandon Parker on Sept 24, 2021 23:49:23 GMT -5
Pablo, There is no need to have four different ListViews; we can clear them as we see fit. I will work on a small example tomorrow if I have the time.
Also, in the future, please either start a new thread and request help or send me a PM. It's obvious that you did not have any malintent, but hijacking someone else's thread is frowned upon because it might lead to confusion for people trying to follow the initial conversation. In this case, please start a new thread in case anyone else wants to follow the conversation. I will reply to the thread with an example as soon as I can do so.
{:0)
Brandon Parker
|
|
|
Post by metro on Sept 25, 2021 0:35:46 GMT -5
An API textbox array may be of use. There is also a simple example of a listview in the melk.zip file attached to this post libertybasiccom.proboards.com/post/2448 '=================================================== ' CREATE TEXTBOX GRID CreateTextboxAPI_Grid_5.bas ' USING WINDOWS API '=================================================== ' modified from LB Newsletter API Corner ' with corrections by Cundo LB Conforum 19 July 2016 ' Further modifications by RNBW 21 July 2016 ' Some Mods by metro Jan 2019 '=================================================== dim newdat$(1000),line$(17),Ldat$(16,8),NewLine$(16,8) Fname$="cowNumber , recogn , followNum , also , date , milkingTime , milkAmount , milkmeterNumber" nomainwin
line$(1)="106,Krokus,9,250,6-12-20018,18,15.2,1" line$(2)="88,Krokus,17,250,6-12-20018,18,6.8,1" line$(3)="68,Krokus,25,250,6-12-20018,18,8.6,1" line$(4)="91,Krokus,33,250,6-12-20018,18,8.4,1" line$(5)="67,Krokus,41,250,6-12-20018,19,17.0,1" line$(6)="62,Krokus,49,250,6-12-20018,19,8.0,1" line$(7)="106,Krokus,9,250,6-12-20018,18,15.2,1" line$(8)="88,Krokus,17,250,6-12-20018,18,6.8,1" line$(9)="68,Krokus,25,250,6-12-20018,18,8.6,1" line$(10)="91,Krokus,33,250,6-12-20018,18,8.4,1" line$(11)="67,Krokus,41,250,6-12-20018,19,17.0,1" line$(12)="62,Krokus,49,250,6-12-20018,19,8.0,1" line$(13)="68,Krokus,25,250,6-12-20018,18,8.6,1" line$(14)="93,Krokus,33,250,6-12-20018,18,8.4,1" line$(15)="63,Krokus,41,250,6-12-20018,19,17.0,1" line$(16)="69,Krokus,49,250,6-12-20018,19,8.0,1"
'LOAD INFO for a = 1 to 16 for q= 1 to 8 Ldat$(a,q)=WORD$(line$(a),q,",") next next
numFields=8 numRecs=16
MENU #1, "&File","&Read", [readIt],_ "E&xit", [quit]
[WindowSetup] WindowWidth = 735 : WindowHeight = 700 UpperLeftX = INT((DisplayWidth-WindowWidth)/2) UpperLeftY = INT((DisplayHeight-WindowHeight)/2) ' ------------------------------------------------- ListBox #1.lb1, newdat$(), [selectlist], 40, 430, 645, 150
button #1.btn1 ," Number ",[button1Click],UL, 40, 60, 80, 20 button #1.btn2 ," Name ",[button1Click],UL, 120, 60, 80, 20 button #1.btn3 ," Volume ",[button1Click],UL, 200, 60, 80, 20 button #1.btn4 ," History ",[button1Click],UL, 280, 60, 80, 20 button #1.btn5 ," Date ",[button1Click],UL, 360, 60, 80, 20 button #1.btn6 ," FollowNum ",[button1Click],UL, 440, 60, 80, 20 button #1.btn7 ," Litres ",[button1Click],UL, 520, 60, 80, 20 button #1.btn8 ," Visits ",[button1Click],UL, 600, 60, 80, 20 button #1.btna ," Save Data ",[button1Click],UL, 40, 600, 75, 25 OPEN "API Textbox Grid" FOR dialog AS #1 PRINT #1, "trapclose [quit]" #1.lb1,"Font Courier_New 10 BOLD " #1.lb1,"hide"
Global Style, Style1
startH = 40: startV = 80: hRow = 20 : width = 80 DIM hT(numRecs,numFields) FOR row = 1 to numRecs FOR col = 1 to numFields ' Set up the style for the Textboxes Style = _WS_CHILDWINDOW OR _WS_BORDER OR _WS_VISIBLE OR _WS_TABSTOP'_ES_RIGHT 'OR _ES_NUMBER hPos = startH + (col-1)*width vPos = startV + (row-1) * hRow hT(row,col) = CreateTextbox(hwnd(#1),hPos,vPos,width+1,hRow+1,Style) NEXT col NEXT row
'FILL GRID FOR row = 1 to numRecs FOR col = 1 to numFields Print SetText$(hT(row,col), Ldat$(row,col)) NEXT col NEXT row
call SetFocus hT(1,1)
WAIT
[quit] CLOSE #1: END
[readIt] handle = GetFocus() txt$ = GetWindowText$( handle ) NOTICE txt$ WAIT
[button1Click]
FOR row = 1 to numRecs FOR col = 1 to numFields NewLine$( row,col)=GetWindowText$( hT(row,col)) ' print NewLine$(row,col) newdat$(row)=newdat$(row)+","+NewLine$(row,col) ' newdat$(row)= AFTER$(newdat$(row),",") NEXT col NEXT row for z= 1 to numRecs newdat$(z)= AFTER$(newdat$(z),",") next
#1.lb1,"show" #1.lb1,"reload" z=1 redim newdat$(1000) Wait [selectlist]
WAIT
'-------------------------------------------- ' SUBs and FUNCTIONs '--------------------------------------------
' Get the focus in the Texbox Function GetFocus() CALLDLL #user32, "GetFocus",_ GetFocus AS uLONG END Function
' Set the focus in the Texbox SUB SetFocus hWnd CALLDLL #user32, "SetFocus",_ hWnd AS uLONG,_ result AS LONG END SUB
'Get the text entered into the Textbox FUNCTION GetWindowText$(hWnd) total = GetWindowTextLength(hWnd) Title$ = SPACE$(total) + CHR$(0): l= LEN(Title$)
CALLDLL #user32, "GetWindowTextA",_ hWnd AS uLONG,_ Title$ AS PTR,_ l AS LONG,_ result AS LONG GetWindowText$ = TRIM$(Title$) END FUNCTION
'Get the length of the text entered into Textbox FUNCTION GetWindowTextLength(hW) CALLDLL #user32, "GetWindowTextLengthA",_ hW AS uLONG,_ GetWindowTextLength AS LONG END FUNCTION
' Function to create Textbox FUNCTION CreateTextbox(hW, x, y, w, h, Style) Style = _WS_CHILDWINDOW OR _WS_BORDER _ OR _WS_VISIBLE hInst = GetWindowLong(hW, _GWL_HINSTANCE)
CALLDLL #user32, "CreateWindowExA",_ 0 AS LONG,_ "EDIT" AS PTR,_ "" AS PTR,_ Style AS LONG,_ x AS LONG,_ y AS LONG,_ w AS LONG,_ h AS LONG,_ hW AS uLONG,_ 0 AS LONG,_ hInst AS LONG,_ 0 AS LONG,_ CreateTextbox AS uLONG END FUNCTION
FUNCTION GetWindowLong(hW, type) CALLDLL #user32, "GetWindowLongA", _ hW AS uLONG,_ type AS LONG,_ GetWindowLong AS LONG END FUNCTION
function SetText$(hWnd , caption$) calldll #user32, "SendMessageA",_ hWnd as ulong,_ _WM_SETTEXT as long,_ 0 as long,_ caption$ as PTR,_ result as long end function
Sub SendMessageLong hWnd,msg,wParam,lParam CallDLL #user32, "SendMessageA",_ hWnd As uLong, _ msg As Long,_ wParam As Long,_ lParam As Long,_ re As Long end sub
|
|
|
Post by Rod on Sept 25, 2021 1:57:57 GMT -5
Bit late reading this but the link tsh gave had two sets of code. He intended you look at the much simplified second set of code.
|
|
|
Post by Rod on Sept 25, 2021 3:22:16 GMT -5
pablosl This code moves data from list boxes, it might let you frame your question better because I am not really sure what you want. Do that in another thread. nomainwin dim cock$(100) dim hens$(100) dim pair$(100) pairpointer=1 cock$(1) = "First Cock" cock$(2) = "Second Cock" cock$(3) = "Third Cock" cock$(4) = "Fourth Cock" cock$(5) = "Fifth Cock" hens$(1) = "First Hen" hens$(2) = "Second Hen" hens$(3) = "Third Hen" hens$(4) = "Fourth Hen" hens$(5) = "Fifth Hen"
listbox #bird.cocks, cock$(), [cockSelection], 5, 35, 200, 90 listbox #bird.hens, hens$(), [henSelection], 205, 35, 220, 90 listbox #bird.pair, pair$(),[delete],405,35,220,90 WindowWidth = 800 : WindowHeight = 300 open "Select Pairs" for window as #bird #bird "trapclose [quit]" wait
[cockSelection] #bird.cocks "selection? selection$" pair$(pairpointer)=selection$ #bird.pair "Reload" wait
[henSelection] #bird.hens "selection? selection$" pair$(pairpointer)=pair$(pairpointer)+selection$ #bird.pair "Reload" pairpointer=pairpointer+1 wait
[delete] #bird.pair "" pairpointer=pairpointer-(pairpointer>0) wait
[quit] close #bird end
|
|
|
Post by dan1101 on Sept 25, 2021 15:47:46 GMT -5
Thanks Rod, and to everyone else as well. I am currently working with the shorter/simpler code example in the link and I think I have the gist of it. While API calls are a bit intimidating at this point, I fully intend to devote the time necessary to become proficient with LB, so any and all suggestions are welcome. I have half a dozen projects in various stages of development and as I learn new techniques, I go back and rework sections of my earlier projects to improve their efficiency based upon my new knowledge. Learning LB has already been a very rewarding endeavor and I continue to be amazed by all it can do.
|
|