从yangming斑竹的窗口打印中抓出来的:
Dim lbr As WinForm.Label
lbr = forms("记帐").Controls("Label4")
lbr.Text = Format(dr("日期"),"yyyy年MM月dd日")
Dim lbdj As WinForm.Label
lbdj = forms("记帐").Controls("Label16")
lbdj.Text = CUMoney(dr("借方金额"))
Dim lblb1 As WinForm.Label
lblb1 = forms("记帐").Controls("Label22")
lblb1.Text = Left(dr("凭证类别"),1)
Dim lblb2 As WinForm.Label
lblb2 = forms("记帐").Controls("Label23")
lblb2.Text = Right(dr("凭证类别"),1)没有必要针对每个控件定义一个变量,其实一个变量就行:
Dim lb As WinForm.Label
lb = forms("记帐").Controls("Label4")
lb.Text = Format(dr("日期"),"yyyy年MM月dd日")
lb = forms("记帐").Controls("Label16")
lb.Text = CUMoney(dr("借方金额"))
lb = forms("记帐").Controls("Label22")
lb.Text = Left(dr("凭证类别"),1)
lb = forms("记帐").Controls("Label23")
lb.Text = Right(dr("凭证类别"),1)
要是我,我会这样:
With forms("记帐").
.Controls("Label4").Text = Format(dr("日期"),"yyyy年MM月dd日")
.Controls("Label16").Text = CUMoney(dr("借方金额"))
.Controls("Label22").Text = Left(dr("凭证类别"),1)
.Controls("Label23").Text = Right(dr("凭证类别"),1)
End With
用不用变量,看个人习惯,但是不要定义太多的变量,变量可以重用的,除非一个控件要反复调用几次,而且调用其它控件之后,还要回头调用,那么可以考虑给这个控件定义一个专用变量,向前面这种用完就丢的变量,完全可以用一个就行。
[此贴子已经被作者于2009-6-10 15:40:12编辑过]
呵.老总应多把自己的经验分享才是!让我等初哥学习学习!