View Full Version : matrices dialog (8x8)
largo_winch
15-12-2011, 08:46
here I show a little matrix (matrices) dialog example for 8x8 matrix (array) only for displaying. perhaps somebody find this example useful. I like it very much! :)
' Empty ThinBASIC GUI file template by largo_winch, matrix-dialog-8x8 matrices
Uses "UI", "console"
Begin ControlID
%textboxy
%ButtonClose
End ControlID
Function TBMain() As Long
Local hDlg As Long
Dim my_matrix_field(8) As Long
Local v, w As Long
For v = 1 To 8
For w = 1 To 8
my_matrix_field(Format$(v, w)) = v * w
Next
Next
Dialog New 0, "matrix_fields -> 8 x 8 ", -1, -1, 550, 220, %WS_CAPTION Or %WS_SYSMENU To hDlg
For v = 1 To 8
For w = 1 To 8
Control Add Textbox, hDlg,%textboxy+(v-1)*8 + w, Trim$(my_matrix_field(Format$(v, w)) ), _
55 * v, 20 * w, 50, 15
Next
Next
Control Add Button, hDlg, %ButtonClose, "Click to kill", 420, 180, 60, 16
Dialog Show Modal hDlg, Call cbDialog
End Function
CallBack Function cbDialog() As Long
Select Case CBMSG
Case %WM_COMMAND
If CBWPARAM = %ButtonClose Then Dialog End CBHNDL
Case %WM_DESTROY
MsgBox 0, "Window is to be destroyed."
End Select
End Function
bye, largo
ErosOlmi
15-12-2011, 11:07
Thanks largo for testing.
Handling many controls is not that easy. For this reason I remeber the great grid control implemented in thinBasic called ML_Grid
Here an example that implements 1 grid with 4 sheets each with the possibility to have few or many or whatever number of rows/columns
Handling ML_Grid is very easy because there are easy to learn command and all cells can be referenced using row/column numeric coordinates like in a matrix.
Check inside \thinBasic\SampleScripts\UI\MLGrid\ few few examples.
Here a basic one.
'------------------------------------------------------------------------------
' MLGrid Example: basic example
'------------------------------------------------------------------------------
#MINVERSION 1.8.9.0
Uses "UI"
Randomize
Begin ControlID
%IDC_MLGRID
End ControlID
'----------------------------------------------------------------------------
FUNCTION TBMain() as long
'----------------------------------------------------------------------------
Local hDlg As Long '---Used to store window handle
Local Count As Long
'---Create a new dialog
Dialog New Pixels, 0, "thinBasic - MLGrid Control test", -1, -1, 640, 480, _
%WS_DLGFRAME | _
%DS_CENTER | _
%WS_CAPTION | _
%WS_SYSMENU | _
%WS_OVERLAPPEDWINDOW | _
%WS_CLIPCHILDREN, _
0 TO hDlg
'---Set window minimum size
Dialog Set Minsize hDlg, 408, 206
'---Show dialog
Dialog Show Modeless hDlg, Call cbDialog_Proc
Do
Dialog DoEvents 0 To Count
Loop While Count
End Function
'------------------------------------------------------------------------------
' Callback procedure for main window
'------------------------------------------------------------------------------
CallBack Function cbDialog_Proc() As Long
'------------------------------------------------------------------------------
Static hGrid As Long '---Defined as statis so at every callback run it will be available
local Counter as long
local w1, w2, h1, h2 as long
local lRow, lCol as long
select case cbmsg
case %WM_INITDIALOG
'---Add controls
hGrid = Control Add MLGrid, CBHNDL, %IDC_MLGRID, "", _
0, 0, 0, 0, %WS_VISIBLE Or %WS_CHILD Or %WS_BORDER', Call cbGrid
MLGrid_Redim hGrid, 8, 8, 8, 8
MLGRID_SetColumnWidth hGrid, 1, 80, 40, 40, 40, 50, 40, 80
MLGrid_SetHeaderColor hGrid, %RGB_LAVENDER
MLGrid_SetGridColors hGrid, %WHITE, Rgb(240,240,250), %RGB_LAVENDER
MLGRID_Sheet_SetName hGrid, 1, "Base"
'---Add other 3 sheets
MLGrid_Sheet_Add hGrid, "Matrix 1" '---Number of rows and columns will be the same as BASE
MLGrid_Sheet_Add hGrid, "Matrix 2", 2000, 32 '--- 2000 rows, 32 columns
MLGrid_Sheet_Add hGrid, "Matrix 3", 5000, 100 '--- 5000 rows, 100 columns
MLGrid_Sheet_Select hGrid, 1
'---Fill cell 1:1
MLGRID_Put(hgrid, 1, 1, "Cell data in 1:1", %TRUE)
'---Change column/row header
MLGRID_Put(hgrid, 0, 1, "Col A", %TRUE)
MLGRID_Put(hgrid, 1, 0, "Row 1", %TRUE)
MLGRID_Sheet_Tabs_Visible hgrid, %TRUE, 350
MLGrid_Refresh hGrid
case %WM_COMMAND
case %WM_SIZE
dialog get client cbhndl to w1, h1
Control Set Size CBHNDL, %IDC_MLGRID, w1, h1
CASE %WM_NOTIFY
case %WM_DESTROY
'---Do whatever needed just before dialog is destroyed.
end select
END FUNCTION
Ciao
Eros
largo_winch
16-12-2011, 11:50
thank you for this very interesting grid example, I didn't know!
I found this example from planetsquire, they want to have money for their grid app, I am wondering why? It's so hard to achieve such grid example? I have no big experience with that kind of grid and cell programming, but I can imagine it's a lot of work to do though.
http://www.planetsquires.com/mylittlegrid.html
the price of 35 dollar isn't high I think but I never would buy such a little tool. it must be free to make it share to other people. better idea can be to give a donation?
my son is ill therefore a lot of things I cannot manage. I have to care for him at home this day. at my work my prof is ill, the two assistance too, my wife, but not me. I am fit as usual. don't know why ;)
bye, largo
largo_winch
16-12-2011, 13:15
just for fun and testing purpose: my grid test. it's really great to see such a little tool for free !
' Empty GUI script created on 12-16-2011 11:51:36 by largo_winch (ThinAIR)
'------------------------------------------------------------------------------
' MLGrid Example: basic example
'------------------------------------------------------------------------------
#MINVERSION 1.8.9.0
Uses "UI"
Randomize
Begin ControlID
%IDC_MLGRID
End ControlID
'----------------------------------------------------------------------------
Function TBMain() As Long
'----------------------------------------------------------------------------
Local hDlg As Long '---Used to store window handle
Local Count As Long
'---Create a new dialog
Dialog New Pixels, 0, "largos_thinBasic - MLGrid Control test", -1, -1, 640, 480, _
%WS_DLGFRAME | _
%DS_CENTER | _
%WS_CAPTION | _
%WS_SYSMENU | _
%WS_OVERLAPPEDWINDOW | _
%WS_CLIPCHILDREN, _
0 To hDlg
'---Set window minimum size
Dialog Set Minsize hDlg, 408, 206
'---Show dialog
Dialog Show Modeless hDlg, Call cbDialog_Proc
Do
Dialog DoEvents 0 To Count
Loop While Count
End Function
'------------------------------------------------------------------------------
' Callback procedure for main window
'------------------------------------------------------------------------------
CallBack Function cbDialog_Proc() As Long
'------------------------------------------------------------------------------
Static hGrid As Long '---Defined as statis so at every callback run it will be available
Local Counter As Long
Local w1, w2, h1, h2 As Long
Local lRow, lCol As Long
Select Case CBMSG
Case %WM_INITDIALOG
'---Add controls
hGrid = Control Add MLGrid, CBHNDL, %IDC_MLGRID, "", _
0, 0, 0, 0, %WS_VISIBLE Or %WS_CHILD Or %WS_BORDER', Call cbGrid
MLGrid_Redim hGrid, 16, 16, 16, 16
MLGrid_SetColumnWidth hGrid, 1, 80, 70, 70, 70, 70, 70, 80
MLGrid_SetHeaderColor hGrid, %RGB_LAVENDER
MLGrid_SetGridColors hGrid, Rgb(140,140,255), Rgb(140,240,250), %RGB_LAVENDER
MLGrid_Sheet_SetName hGrid, 1, "Base"
'---Add other 5 sheets
MLGrid_Sheet_Add hGrid, "Matrix 1", 200,100 '---Number of rows and columns will be the same as BASE
MLGrid_Sheet_Add hGrid, "Matrix 2", 200, 32 '--- 200 rows, 32 columns
MLGrid_Sheet_Add hGrid, "Matrix 3", 500, 100 '--- 500 rows, 100 columns
MLGrid_Sheet_Add hGrid, "Matrix 4", 500, 100 '--- 500 rows, 100 columns
MLGrid_Sheet_Add hGrid, "Matrix 5", 500, 100 '--- 500 rows, 100 columns
MLGrid_Sheet_Select hGrid, 1
'---Fill cell 1:1
MLGrid_Put(hgrid, 1, 1, "Cell data in 1:1", %TRUE)
MLGrid_Put(hgrid, 1, 2, "wheather data ", %TRUE)
MLGrid_Put(hgrid, 1, 3, "movies top ten", %TRUE)
MLGrid_Put(hgrid, 2, 1, "thinbasic", %TRUE)
MLGrid_Put(hgrid, 2, 2, "freebasic", %TRUE)
MLGrid_Put(hgrid, 2, 3, "powerbasic", %TRUE)
MLGrid_Put(hgrid, 2, 4, "cosmicbasic", %TRUE)
'---Change column/row header
MLGrid_Put(hgrid, 0, 1, "Col A", %TRUE)
MLGrid_Put(hgrid, 1, 0, "Row 1", %TRUE)
MLGrid_Sheet_Tabs_Visible hgrid, %TRUE, 350
MLGrid_Refresh hGrid
Case %WM_COMMAND
Case %WM_SIZE
Dialog Get Client CBHNDL To w1, h1
Control Set Size CBHNDL, %IDC_MLGRID, w1, h1
Case %WM_NOTIFY
Case %WM_DESTROY
'---Do whatever needed just before dialog is destroyed.
End Select
End Function
bye, largo
ErosOlmi
16-12-2011, 15:31
I found this example from planetsquire, they want to have money for their grid app, I am wondering why? It's so hard to achieve such grid example? I have no big experience with that kind of grid and cell programming, but I can imagine it's a lot of work to do though.
http://www.planetsquires.com/mylittlegrid.html
the price of 35 dollar isn't high I think but I never would buy such a little tool. it must be free to make it share to other people. better idea can be to give a donation?
thinBasic MLGrid is exactly MyLittleGrid :D
James Klutho (MLGrid author) donated to thinBasic project PowerBasic sources of MLGrid. It was a great act of generosity.
It is documented in thinBasic help: http://www.thinbasic.com/public/products/thinBasic/help/html/mlgrid_control.htm