本人近日,由于业务要求,用ACTIVE REPORT 2 做一个条码打印软件,由于条码数目具有不确定性,所以要动态添加Barcode lable pagebreak控件,查了很多资料,但是由于ACTIVE REPORT 2 是设计器,不是WINFORM ,有用的信息很少,经过自己研究,终于搞定,哈哈,分享一下!
作者:章亚
Sub Print_LOOK()
Dim i As Integer, t As Integer, j As Integer, st As String
Dim left As Integer, top As Integer, height As Integer, width As Integer, bwidth As Integer
Dim x As Long, y As Long
Dim barcode As String '条码内容
t = Len(Trim(txtStart.Text))
x = Val(Trim(txtStart.Text)) '开始码
y = Val(Trim(txtEnd.Text)) '结束码
left = Val(Trim(txtLeft.Text)) '左
top = Val(Trim(txtTop.Text)) '上
height = Val(Trim(txtHeight.Text)) '高
width = Val(Trim(txtWidth.Text)) '宽
bwidth = Val(Trim(txtBwidth.Text)) '密度
barcode = Trim(txtBarcode.Text)
j = 0
With APT
.Restart
For i = 0 To y - x
.Printer.Copies = Val(txtCopies.Text) '打印份数
BarcodeSet '设置
If chkSelt.Value = 0 Or (chkSelt.Value = 1 And OptOpp.Value = True And (i + x) Mod 2 = 0) Or (chkSelt.Value = 1 And OptOdd.Value = True And (i + x) Mod 2 <> 0) Then '判断,可不管它
Dim bar As Object
Dim lbl As Object
With APT.Sections("Detail").Controls
Set bar = .Add("DDActiveReports2.BarCode")
Set lbl = .Add("DDActiveReports2.Label")
End With
'bar.Name = "Bd" & j + 1
'lbl.Name = "lbl" & j + 1
If j Mod 2 = 1 Then
bar.left = left + 5400
Else
bar.left = left
End If
bar.top = top + Int(j / 2) * 2600
bar.height = height
bar.width = width
bar.BarWidth = bwidth '条码密度
lbl.top = bar.top + bar.height 'lbl 跟BD1 属性走
lbl.left = bar.left
lbl.width = bar.width
st = format(i + x, t)
bar.Caption = barcode & st
lbl.Caption = barcode & st
If (j + 1) Mod 10 = 0 Then
Dim pgbk As Object
With APT.Sections("Detail").Controls
Set pgbk = .Add("DDActiveReports2.PageBreak") '添加分页控件
End With
pgbk.top = bar.top + 2600
APT.Detail.height = APT.Detail.height + 13000
End If
j = j + 1
End If
Next i
End With
APT.PrintReport (False) '开始打印
End Sub