TheLazyPig
Programmer
Hi, I wanted to know the count of records or data in my Grid View. I'm using Label to view the count. Where will I start?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
PRIVATE m.COUNTER,m.OLDRECNO
m.COUNTER = 0
SELECT MYTABLE
m.OLDRECNO = RECNO()
GO TOP
DO WHILE .NOT. EOF()
m.COUNTER = m.COUNTER +1
SKIP
ENDDO
IF m.OLDRECNO > 0 .AND. m.OLDRECNO <= RECCOUNT()
GOTO m.OLDRECNO
ENDIF
THISFORM.MYLABEL.CAPTION = "There are "+ALLTRIM(STR(m.COUNTER,8,0))+" Records"
LPARAMETERS nColIndex
thisform.MyButton.Click()
SELECT TheTable && this is the table that you used to populate the grid
COUNT TO lnCount
THISFORM.lblCount.Caption = TRANSFORM(lnCount)
THISFORM.lblCount.Visible = .T.
We tested empty loops, just going through a table from top to bottom, and found SCAN to be about twice as fast as the equivalent DO WHILE. Your mileage may vary
PUBLIC go_Form
go_Form = CREATEOBJECT("frmForm")
go_Form.Show
READ Events
CLEAR ALL
DEFINE CLASS frmForm As Form
Width = 420
Height = 360
MinWidth = 420
MinHeight = 360
MaxWidth = 420
MaxHeight = 360
AutoCenter = .T.
*!* Add a grid to the form
Add Object grdNames as Grid with;
Visible = .F., ;
Top = 48, Left = 18, Width = 390, Height = 264, DeleteMark = .F.
*!* Add object Label
ADD OBJECT lblInfo as Label WITH ;
Top = 12, Left = 280, Autosize = .T., FontSize = 8, FontItalic = .T., ;
Caption = "Number of Records: "
*!* Add object Label
ADD OBJECT lblSearch as Label WITH ;
Top = 12, Left = 12, Autosize = .T., FontSize = 8, FontItalic = .T., ;
Caption = "Enter string to search for in Name"
*!* Add object Textbox
ADD OBJECT txtSearch as Textbox WITH ;
Top = 12, Left = 192, Width = 60, Height = 24
*!* ADD a Browse button - allows you to filter the underlying tables
ADD OBJECT cmdBrowse As CommandButton WITH ;
Width=60, Height=30, Left=84, Top=318, Caption="Browse"
PROCEDURE cmdBrowse.Click()
LOCAL lcAlias
lcAlias = ALIAS()
SELECT cName, nMeters, nSquare, nVolume ;
FROM tblNames ;
WHERE IIF(EMPTY(ALLTRIM(ThisForm.txtSearch.Value)), .T., AT(ALLTRIM(ThisForm.txtSearch.Value), cName) != 0) ;
INTO CURSOR csrResults
[highlight #FCE94F] Thisform.lblInfo.Caption = "Number of Records: " + TRANSFORM(_Tally, "999,999")
[/highlight]
WITH ThisForm.grdNames
.ColumnCount = -1
.RecordSource = "csrResults"
.Visible = .T.
.ReadOnly = .T.
.SetAll("Sparse", .F., "Column")
.Column1.Width = 72
.Column1.Header1.Caption = "Name"
.Column1.Text1.FontBold = .T.
.Column1.Text1.FontItalic = .T.
.Column2.Width = 72
.Column2.Header1.Caption = "Me"
.Column2.Text1.InputMask = "9,999.99"
.Column3.Width = 90
.Column3.Header1.Caption = "Sq"
.Column3.Text1.InputMask = "999,999.99"
.Column4.Width = 90
.Column4.Header1.Caption = "Vo"
.Column4.Text1.InputMask = "999,999,999.99"
.Refresh()
ENDWITH
SELECT (lcAlias)
ENDPROC
*!* Add exitbutton to the form
ADD OBJECT cmdExit As CommandButton WITH ;
Width=60, Height=30, Left=18, Top=318, Caption="Exit"
PROCEDURE cmdExit.Click()
CLOSE ALL
CLEAR Events
ThisForm.Release
ENDPROC
*!* ADD code to form's events
PROCEDURE Destroy()
ThisForm.cmdExit.Click()
ENDPROC
PROCEDURE Load()
IF !FILE("tblNames.dbf")
Create Table tblNames (cName C(10), nMeters I, nSquare I, nVolume I )
For li_I = 1 to 180
INSERT INTO tblNames (cName, nMeters, nSquare, nVolume) ;
VALUES ("Name" + PADL(li_I,3,"0"), li_I, li_I ^ 2, li_I ^ 3)
Next li_I
ELSE
USE tblNames
ENDIF
ENDPROC
ENDDEFINE