VB下打印不出内容

Green Hander 2018-08-21 08:03:13
为打印单据,将预置的数据保存成ini文件,在主页面选择相关数据打印出表单,有几个内容打印不出来。
贴代码:
Private Sub p_initial()
Dim StrPath$
Dim i As Integer
Dim m_item As String
Dim m_code As String
Dim m_result As String
Dim m_symb As String
Dim num As Integer
Dim i_code As String
Dim i_result As String
Dim n As Integer

StrPath = App.Path & "\configDB.ini"
num = Val(ReadIni(StrPath, "Number", "project_num"))
For n = 0 To 14
For i = 0 To num - 1
m_item = ReadIni(StrPath, "Item" & i, "project")
m_code = ReadIni(StrPath, "Item" & i, "code")
i_code = m_item & "(" & m_code & ")"
If item(n).Text = i_code Then
pname(n) = m_item
Code(n) = m_code
End If
Next i
Next n

num = Val(ReadIni(StrPath, "Number", "result_num"))
For n = 0 To 14
For i = 0 To num - 1
m_result = ReadIni(StrPath, "result" & i, "result")
m_symb = ReadIni(StrPath, "result" & i, "symb")
i_result = m_result & "/" & m_symb
If result(n).Text = i_result Then
symb(n) = m_symb
res(n) = m_result
End If
Next i
Next n

End Sub
Private Sub f_print()
Call p_initial
Printer.PaperSize = 9
Printer.ScaleLeft = -20
Printer.ScaleTop = -25
Printer.ScaleWidth = 210
Printer.ScaleHeight = 297
Printer.CurrentX = 0
Printer.CurrentY = 0
Printer.ScaleMode = 6
X = 67.733
y = 4.233
fnt = 14
Printer.FontName = "黑体"
txt = "同心县马高庄乡卫生院检验报告单"
dy = prnt(X, y, fnt, txt)

X = 8.467
y = 14.817
fnt = 13
Printer.FontName = "宋体"
txt = "姓 名:"
dy = prnt(X, y, fnt, txt)
X = 33.867
y = 14.817
fnt = 13
Printer.FontName = "宋体"
txt = 姓名.Text
dy = prnt(X, y, fnt, txt)

X = 66.675
y = 14.817
fnt = 13
Printer.FontName = "宋体"
txt = "性 别:"
dy = prnt(X, y, fnt, txt)
X = 88.9
y = 14.817
fnt = 13
Printer.FontName = "宋体"
txt = 性别.Text
dy = prnt(X, y, fnt, txt)

X = 131.498
y = 14.817
fnt = 13
Printer.FontName = "宋体"
txt = "年 龄:"
dy = prnt(X, y, fnt, txt)
X = 152.4
y = 14.817
fnt = 13
Printer.FontName = "宋体"
txt = 年龄.Text
dy = prnt(X, y, fnt, txt)

X = 8.467
y = 23.019
fnt = 13
Printer.FontName = "宋体"
txt = "病人类型:"
dy = prnt(X, y, fnt, txt)
X = 33.867
y = 23.019
fnt = 13
Printer.FontName = "宋体"
txt = 病人类型.Text
dy = prnt(X, y, fnt, txt)

X = 66.675
y = 23.019
fnt = 13
Printer.FontName = "宋体"
txt = "科 室:"
dy = prnt(X, y, fnt, txt)
X = 88.9
y = 23.019
fnt = 13
Printer.FontName = "宋体"
txt = 科室.Text
dy = prnt(X, y, fnt, txt)

X = 131.498
y = 23.019
fnt = 13
Printer.FontName = "宋体"
txt = "诊 断:"
dy = prnt(X, y, fnt, txt)
X = 152.4
y = 23.019
fnt = 13
Printer.FontName = "宋体"
txt = diagnose.Text
dy = prnt(X, y, fnt, txt)

Printer.DrawWidth = 2
Printer.Line (8.467, 31.75)-(200.907, 31.75)
Printer.Line (8.467, 40.517)-(200.907, 40.517)
Printer.Line (8.467, 118.533)-(200.907, 118.533)
Printer.DrawWidth = 1
Printer.Line (166.983, 125.889)-(200.907, 125.889)

X = 12.7
y = 33.867
fnt = 13
Printer.FontName = "黑体"
Printer.FontBold = True
txt = "序号"
dy = prnt(X, y, fnt, txt)

X = 42.333
y = 33.867
fnt = 13
Printer.FontName = "黑体"
Printer.FontBold = True
txt = "项目名称"
dy = prnt(X, y, fnt, txt)

X = 85.461
y = 33.867
fnt = 13
Printer.FontName = "黑体"
Printer.FontBold = True
txt = "项目代号"
dy = prnt(X, y, fnt, txt)

X = 131.233
y = 33.867
fnt = 13
Printer.FontName = "黑体"
Printer.FontBold = True
txt = "结果"
dy = prnt(X, y, fnt, txt)

X = 168.804
y = 33.867
fnt = 13
Printer.FontName = "黑体"
Printer.FontBold = True
txt = "标志"
dy = prnt(X, y, fnt, txt)

X = 10.583
y = 122.255
fnt = 12
Printer.FontName = "宋体"
txt = "检验日期:"
dy = prnt(X, y, fnt, txt)
X = 29.633
y = 122.255
fnt = 12
Printer.FontName = "宋体"
txt = Format(Now, "yyyy-mm-dd hh:mm:ss")
dy = prnt(X, y, fnt, txt)

X = 70
y = 122.255
fnt = 12
Printer.FontName = "宋体"
txt = "检验医生:"
dy = prnt(X, y, fnt, txt)
X = 94
y = 122.255
fnt = 12
Printer.FontName = "宋体"
txt = 送检医生.Text
dy = prnt(X, y, fnt, txt)

X = 117
y = 122.255
fnt = 12
Printer.FontName = "宋体"
txt = "检验员:"
dy = prnt(X, y, fnt, txt)
X = 133.117
y = 122.255
fnt = 12
Printer.FontName = "宋体"
txt = 检验员.Text
dy = prnt(X, y, fnt, txt)

X = 150.117
y = 122.255
fnt = 12
Printer.FontName = "宋体"
txt = "签字:"
dy = prnt(X, y, fnt, txt)

Dim i As Integer
Dim num As Integer
num = 0
For i = 0 To 14
X = 16.122
y = 41.54 + num
fnt = 13
Printer.FontName = "宋体"
txt = Val(i + 1)
dy = prnt(X, y, fnt, txt)

X = 40.34
y = 41.046 + num
fnt = 13
Printer.FontName = "宋体"
txt = pname(i)
dy = prnt(X, y, fnt, txt)

X = 87.754
y = 41.046 + num
fnt = 13
Printer.FontName = "宋体"
txt = Code(i)
dy = prnt(X, y, fnt, txt)

X = 132.239
y = 41.046 + num
fnt = 13
Printer.FontName = "宋体"
txt = symb(i)
dy = prnt(X, y, fnt, txt)

X = 169.81
y = 41.046 + num
fnt = 13
Printer.FontName = "宋体"
txt = res(i)
dy = prnt(X, y, fnt, txt)

num = num + 4.233 + 0.794

Next i

Printer.EndDoc
End Sub

Private Sub Command1_Click()
Call f_print
End Sub



pname、Code、symb、res打印不出来,鄙人初学,望各位大神赐教,不胜感激!
...全文
401 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
ccbbcc 2018-10-11
prnt这个函数可能有问题
回复
脆皮大雪糕 2018-08-23
首先确认一下,pname、Code、symb、res 到底有没有值

确认一下这句:num = Val(ReadIni(StrPath, "Number", "project_num"))
如果num没取到值也会导致你的 For i = 0 To num - 1 变成空循环而导致没有赋值
回复
Green Hander 2018-08-21
引用 1 楼 Chen8013 的回复:
如果“pname、Code、symb、res打印不出来”,那岂不是相当于什么都没打出来了?


我看你的代码, 几乎都是执行调用 “dy = prnt(X, y, fnt, txt) ”进行打印操作的,
 自己看看这个“打印函数”有没有问题啊。

另外,可以多加个测试代码,检查一下那些“被打印内容”,是否都正确获取到内容了啊。


最奇怪的事,调试的时候如果我是输出成PDF文件,是没有什么问题的,但是用打印机打印的时候就会出问题。
回复
舉杯邀明月 2018-08-21
如果“pname、Code、symb、res打印不出来”,那岂不是相当于什么都没打出来了?


我看你的代码, 几乎都是执行调用 “dy = prnt(X, y, fnt, txt) ”进行打印操作的,
 自己看看这个“打印函数”有没有问题啊。

另外,可以多加个测试代码,检查一下那些“被打印内容”,是否都正确获取到内容了啊。
回复
相关推荐
发帖

1187

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
帖子事件
创建了帖子
2018-08-21 08:03
社区公告
暂无公告