VB指定打印机,用字符串"非税票打印机"能实现,但是用变量就不行,我变量是从INI读取的
代码如下: Dim PrintName As String
inipath = App.Path & IIf(Len(App.Path) > 3, "\" & "PrintSet.ini", "PrintSet.ini")
PrintName = GetMyINI("非税票打印", "PrintName", inipath)
PrintName = """" & Trim(Replace(PrintName, Chr(0), "")) & """"
'Debug.Print PrintName
Me.Text1.Text = CStr(PrintName) Dim p As Printer '指定打印机
For Each p In Printers
If LCase(p.DeviceName) = PrintName Then
Set Printer = p
Exit For
End If
Next这句
If LCase(p.DeviceName) = PrintName Then
换成
If LCase(p.DeviceName) = "非税票打印机"
就能实现指定打印机打印,换成 PrintName 变量就不行
用 Debug.Print 输出PrintName,字符串确实是 "非税票打印机",空格我已经处理掉ini文件如下:[非税票打印]
PrintName="非税票打印机"
PrintLeft=10
PrintTop=0请高手指教下
代码如下: Dim PrintName As String
inipath = App.Path & IIf(Len(App.Path) > 3, "\" & "PrintSet.ini", "PrintSet.ini")
PrintName = GetMyINI("非税票打印", "PrintName", inipath)
PrintName = """" & Trim(Replace(PrintName, Chr(0), "")) & """"
'Debug.Print PrintName
Me.Text1.Text = CStr(PrintName) Dim p As Printer '指定打印机
For Each p In Printers
If LCase(p.DeviceName) = PrintName Then
Set Printer = p
Exit For
End If
Next这句
If LCase(p.DeviceName) = PrintName Then
换成
If LCase(p.DeviceName) = "非税票打印机"
就能实现指定打印机打印,换成 PrintName 变量就不行
用 Debug.Print 输出PrintName,字符串确实是 "非税票打印机",空格我已经处理掉ini文件如下:[非税票打印]
PrintName="非税票打印机"
PrintLeft=10
PrintTop=0请高手指教下
看下输出是不是 "非税票打印机"
这句
If LCase(p.DeviceName) = PrintName Then
换成
If LCase(p.DeviceName) = "非税票打印机"
就能在 “非税票打印机” 里看见打印进程
ini文件如下:[非税票打印]
PrintName="非税票打印机"
PrintLeft=10
PrintTop=0
If LCase(p.DeviceName) =me.text1.text then
Me.Text1.Text = CStr(PrintName) Dim p As Printer '指定打印机
For Each p In Printers
Debug.Print p.DeviceName
If LCase(p.DeviceName) = PrintName Then
Set Printer = p
Exit For
End If
Next
[非税票打印]
PrintName=非税票打印机
PrintLeft=10
PrintTop=10
-------------------------PrintLeft=10
PrintTop=10这2个变量都能生效
'Printer.Orientation = 1 '1纵向,2横向
Printer.ScaleMode = 6 '单位毫米
Printer.ScaleLeft = PrintLeft '设置左边界
Printer.ScaleTop = PrintTop '设置上边界
Debug.Print objP.DeviceName
If objP.DeviceName = sTablePrint Then
Exit For
End If
Next
发票打印机
Ps File
Microsoft XPS Document Writer
Microsoft Office Document Image Writer
EPSON Stylus Photo 1390 Series
EPSON LQ-670K
EPSON LQ-630K ESC/P2 (副本 1)
EPSON LQ-630K ESC/P2
\\生技科刘倡\HP LaserJet P1007
If LCase(p.DeviceName) = "非税票打印机" "非税票打印机" 换成变量就不行,我运行后从me.text1.text显示的"非税票打印机" 拷入源代码都可以指定打印,一换变量就成默认打印机打印
PrintName = """" & Trim(Replace(PrintName, Chr(0), "")) & """"
Dim sPrintName as string
Dim objP As Printerinipath = App.Path & IIf(Len(App.Path) > 3, "\" & "PrintSet.ini", "PrintSet.ini")
sPrintName = GetMyINI("非税票打印", "PrintName", inipath)
Debug.Print sPrintName For Each objP In Printers
If objP.DeviceName = sPrintName Then
Exit For
End If
Next