#2
hp_20002016-07-09 17:14
|
各位大神,在下面的窗口事件中,因为代码重复量大,想把重复的代码编写成函数,可因为函数中牵涉到父类窗口创建的控件,不知如何引用,所以怎么也写不出来,请大神帮帮忙啊!
主窗口中代码:
long i,ll_row,ll_columns,i_return
oleobject xlapp,xlsub,xlsub1
xlapp = CREATE OLEObject
i_return = xlapp.ConnectToNewObject( "Excel.Application")
if i_return <> 0 then
MessageBox( "提示! ", "Excel连接失败! ")
return
end if
string dept_name,item_head,item_detail,result,unit,reference_value,cue,summary
xlapp.application.workbooks.open(path_name)
xlsub = xlapp.application.activeworkbook.worksheets[1]
ll_row=xlsub.UsedRange.Rows.Count
ll_columns=xlsub.UsedRange.Columns.Count
dw_report.reset() //数据窗口清空
if tab_1.tabpage_2.cbx_xcg.checked then
w_getItemDetail("血常规")
end if
if tab_1.tabpage_2.cbx_shqt.checked then
w_getItemDetail("生化全套")
end if
dw_report.GroupCalc()
//窗口函数代码:w_getItemDetail
int i=6
item_head=string(xlsub.cells(i,4).value)
do while (item_head <> "血常规")
i=i+1
item_head=string(xlsub.cells(i,4).value)
if isnull(item_head) then
item_head=""
end if
loop
do while string(xlsub.cells(i,4).value) = "血常规"
ll_row=dw_report.insertrow(0)
dept_name=string(xlsub.cells(i,2).value)
item_head=string(xlsub.cells(i,4).value)
item_detail=string(xlsub.cells(i,5).value)
result=string(xlsub.cells(i,6).value)
unit=string(xlsub.cells(i,7).value)
reference_value=string(xlsub.cells(i,8).value)
cue=string(xlsub.cells(i,9).value)
dw_report.setitem(ll_row,'dept_name',dept_name)
dw_report.setitem(ll_row,'item_head',item_head)
dw_report.setitem(ll_row,'item_detail',item_detail)
dw_report.setitem(ll_row,'result',result)
dw_report.setitem(ll_row,'unit',unit)
dw_report.setitem(ll_row,'reference_value',reference_value)
dw_report.setitem(ll_row,'cue',cue)
i = i + 1
loop
summary=string(xlsub.cells(i,2).value)+string(xlsub.cells(i,3).value)
dw_report.setitem(ll_row,'summary',summary)