不要过度迷信进度条,因为 VFP 不是多进度多进程的软件,而且中间的运行过程不好俘获,大部分的语句是同步方式的,所以进程条的刻度很难采集。
下面是三种创建索引方式的速度比较:
Set Talk Off
Clear
Set Excl On
Clear
Create Cursor Test (cfield C(1))
For I = 1 To 100000
&& 10W 条记录
Append Blank
Endfor
*!*
方法一:无进度条:0.5秒
a1=Seconds( )
Index On cfield Tag slowindex
? '自然索引 : ' + Str(Seconds( )-a1,6,4) + ' 秒'
*!*
方法二:进度条类:22秒
oProgress=Createobject("myThermo")
oProgress.nMaxValue=Reccount()
oProgress.nValue=1
oProgress.Show()
a1=Seconds( )
Index On IndexProgress(cfield , Recno(), Reccount()) Tag SlowIndex
oProgress.Release()
? '进度条类索引 : ' + Str(Seconds( )-a1,6,4) + ' 秒'
*!*
方法三:Wait 命令方法:75秒
a1=Seconds( )
Index On IndexProgress2(cfield , Recno(), Reccount()) Tag slowindex
? 'Wait Window 索引 : ' + Str(Seconds( )-a1,6,4) + ' 秒'
Wait Clear
Use
Function IndexProgress2(tcValue, tnRecno, tnReccount)
Wait Window "正在索引,记录号:" + Transform(tnRecno) + " of " + Transform(tnReccount) NoWait
Return tcValue
Endfunc
Function IndexProgress(tcValue, tnRecno, tnReccount)
oProgress.nValue=tnRecno
oProgress.Refresh()
Return tcValue
Endfunc
**************************************************
Define Class mythermo As Form
ShowWindow=2
Height = 100
Width = 420
Desktop = .T.
ScrollBars = 0
DoCreate = .T.
AutoCenter = .T.
BorderStyle = 2
Caption = " Percent of perfoming"
HalfHeightCaption = .F.
TitleBar = 0
BackColor = Rgb(128,128,128)
ncurrentvalue = 1
nincrementvalue = 1
nMaxValue = 100
Name = "mythermo"
nValue = .F.
Add Object TEXT1 As TextBox With ;
Height = 25, ;
Left = 6, ;
Top = 42, ;
Width = 400, ;
BackColor = Rgb(214,214,171), ;
Name = "Text1"
Add Object shp_progress_bar As Shape With ;
Top = 44, ;
Left = 6, ;
Height = 23, ;
Width = 20, ;
BackStyle = 1, ;
BackColor = Rgb(255,255,0), ;
BorderColor = Rgb(255,255,0), ;
Name = "Shp_progress_bar"
Add Object lbl1 As Label With ;
AutoSize = .T., ;
FontBold = .T., ;
FontSize = 10, ;
Alignment = 0, ;
BackStyle = 0, ;
Caption = "0%", ;
Height = 18, ;
Left = 162, ;
Top = 47, ;
Width = 19, ;
ForeColor = Rgb(64,0,128), ;
Name = "Lbl1"
Add Object Lbl_High As Label With ;
AutoSize = .T., ;
FontBold = .T., ;
FontSize = 10, ;
Alignment = 0, ;
BackStyle = 0, ;
Caption = "正在创建索引", ;
Height = 18, ;
Left = 71, ;
Top = 12, ;
Width = 71, ;
ForeColor = Rgb(255,255,128), ;
Name = "lbl_high"
Protected Procedure incrementvalue
*-- Increment the current value
This.ncurrentvalue = This.ncurrentvalue + This.nincrementvalue
*-- Increase the size of the progress bar
This.shp_progress_bar.Width = 400 * (This.ncurrentvalue / This.nMaxValue)
Thisform.lbl1.Caption=Str(This.ncurrentvalue / This.nMaxValue)+' %'
Thisform.Refresh
Endproc
Procedure nvalue_access
*To do: Modify this routine for the Access method
*/ ACTION.PRG
Lparameters vNewVal
If Type ("vNewVal") = "N"
This.nValue = m.vNewVal
This.shp_progress_bar.Width = 400 * (This.nValue / This.nMaxValue)
Else
=Messagebox ("wrong data type")
Endif
*****RETURN THIS.nValue
Endproc
Procedure nvalue_assign
Lparameters vNewVal
*-- Test the data type
If Type("vNewVal") = "N"
*-- Set the value of the property
This.nValue = m.vNewVal
*-- Increase the size of the progress bar
This.shp_progress_bar.Width = 400 * (This.nValue / This.nMaxValue)
Thisform.lbl1.Caption=Str(This.nValue*100 / This.nMaxValue)+' %'
*Thisform.refresh
Else
=Messagebox("Invalid data type.")
Endif
Endproc
Enddefine
*
*-- EndDefine: mythermo
**************************************************