Visual Basic实现动态报表(2)
2008-04-09 04:44:10来源:互联网 阅读 ()
Dim i As Integer
Const wordwidth As Integer = 201 '五号字的宽度为201缇
For i = 0 To lst.ListCount - 1
Select Case lst.List(i)
Case "序号"
lst.ItemData(i) = wordwidth * 3
Case "股票代号"
lst.ItemData(i) = wordwidth * 5
Case "股票名称"
lst.ItemData(i) = wordwidth * 6
Case "收盘价"
lst.ItemData(i) = wordwidth * 5
Case "涨跌"
lst.ItemData(i) = wordwidth * 4
Case "最高价"
lst.ItemData(i) = wordwidth * 5
Case "最低价"
lst.ItemData(i) = wordwidth * 5
Case "成交量"
lst.ItemData(i) = wordwidth * 4
End Select
Next i
End Sub
'******************************************************************
4.设置Datareport窗体属性,控制输出格式
设置Datareport窗体的属性,控制输出格式也可用一子过程完成,需要说明的是为Datareport和数据控件设置属性时,在设计编码过程中,Visual
Basic多数不出现正常情况下的智能提示,不必大惊小怪,完整代码如下。
'设置报表窗体各种参数,控制输出格式
Private Sub setDatareport(lst As ListBox, dtr As Datareport, scaption As String)
Dim leftpos As Long 'leftpos为存放控件left属性的变量
Dim reportwidth As Long 'reportwidth为存放Datareport总宽度的变量
Dim i As Integer
'求总宽度
For i = 0 To lst.ListCount - 1
reportwidth = reportwidth lst.ItemData(i)
Next
'初始化
With dtr
'设置数据源,页边距,标题,横向分割线,section1、2区第一条竖分割线
.LeftMargin = 1440
.RightMargin = 1440
.TopMargin = 1440
.BottomMargin = 144
.reportwidth = Printer.Width - 2880 - 20
Set .DataSource = rs 'rs为ADODB数据源
.Sections("section4").Controls.Item("label41").Caption = scaption
.Sections("section4").Controls.Item("label41").Width = reportwidth
.Sections("section4").Controls.Item("label42").Width = reportwidth
.Sections("section2").Controls.Item("line_2").Width = reportwidth
.Sections("section2").Controls.Item("line2").Width = reportwidth
.Sections("section1").Controls.Item("line1").Width = reportwidth
.Sections("section2").Controls.Item("line20").Left = 0
.Sections("section1").Controls.Item("line10").Left = 0
End With
'为section1,2区设置数据
leftpos = 0
For i = 0 To lst.ListCount - 1
dtr.Sections("section2").Controls.Item("label1" & (i 1)).Caption = lst.List(i)
dtr.Sections("section2").Controls.Item("label1" & (i 1)).Width = lst.ItemData(i)
dtr.Sections("section2").Controls.Item("label1" & (i 1)).Left = leftpos
dtr.Sections("section1").Controls.Item("text1" & (i 1)).DataField = lst.List(i)
dtr.Sections("section1").Controls.Item("text1" & (i 1)).Width = lst.ItemData(i)
dtr.Sections("section1").Controls.Item("text1" & (i 1)).Left = leftpos
dtr.Sections("section2").Controls.Item("line2" & (i 1)).Left = leftpos lst.ItemData(i)
dtr.Sections("section1").Controls.Item("line1" & (i 1)).Left = leftpos lst.ItemData(i)
leftpos = leftpos lst.ItemData(i)
'特殊字段的格式特殊处理
If lst.List(i) = "收盘价" Or lst.List(i) = "最低价" Or lst.List(i) = "最高价" Then
dtr.Sections("section1").Controls.Item("text1" & (i 1)).DataFormat.Format = "¥#,##0.00"
End If
If lst.List(i) = "涨跌" Then
dtr.Sections("section1").Controls.Item("text1" & (i 1)).DataFormat.Format = "#,##0.00"
End If
If lst.List(i) = "成交量" Then
dtr.Sections("section1").Controls.Item("text1" & (i 1)).DataFormat.Format = "#,##0"
End If
Next i
'对不用的text控件必须设置其datafield属性,如lst.List(0),否则出错,但一定让其不可见
'其他不用的label,line控件同样均不可见
i = lst.ListCount
While i < (dtr.Sections("section1").Controls.Count - 10)
'10 为section1区域的非text控件的控件总数
i = i 1
dtr.Sections("section1").Controls.Item("text1" & i).DataField = lst.List(0)
dtr.Sections("section1").Controls.Item("text1" & i).Visible = False
dtr.Sections("section2").Controls.Item("line2" & i).Visible = False
dtr.Sections("section1").Controls.Item("line1" & i).Visible = False
dtr.Sections("section2").Controls.Item("text1" & i).Visible = False
Wend
End Sub
'******************************************************************************
5.报表输出
报表输出是在单击"输出报表"按钮(cmd_report)完成的,代码如下。
Private Sub cmd_report_Click()
If lst_selected.ListCount <> 0 Then
Call fieldwidth(lst_selected) '设置字段宽度
Call setdatareport(lst_selected, Dtreport, Trim$(txt_caption)) '设置报表属性
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:VB.NET多线程技术及其实现
下一篇:用VB实现数字波形显示程序
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
