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请高手指教下

解决方案 »

  1.   

    Debug.Print Me.Text1.Text
    看下输出是不是 "非税票打印机"
      

  2.   

    我估计LZ是没有取出INI中的PrintName的值。
      

  3.   

    也可能INI中的值不是 "非税票打印机"
      

  4.   

    默认打印机确实不是 "非税票打印机"我要实现的就是指定打印机打印,因为我这里票据是发票和非税票两种,点打印后同时出票
    这句   
    If LCase(p.DeviceName) = PrintName Then   
    换成
    If LCase(p.DeviceName) = "非税票打印机" 
    就能在 “非税票打印机” 里看见打印进程
      

  5.   


    ini文件如下:[非税票打印]
    PrintName="非税票打印机"
    PrintLeft=10
    PrintTop=0
      

  6.   

    可能是 ini文件取出来有多余的半角字符,你用 文本框过渡后,最后从 文本框取应该就对了
     If LCase(p.DeviceName) =me.text1.text then 
      

  7.   

    INI的值我已经取出来了,Debug.print printname 看得到嘛,并且我还加了个Me.Text1.Text = rintName
      

  8.   

    这样试试:
      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
      

  9.   

    这个也是试了的
    [非税票打印]
    PrintName=非税票打印机
    PrintLeft=10
    PrintTop=10
    -------------------------PrintLeft=10
    PrintTop=10这2个变量都能生效
        'Printer.Orientation = 1 '1纵向,2横向
        Printer.ScaleMode = 6    '单位毫米
        Printer.ScaleLeft = PrintLeft    '设置左边界
        Printer.ScaleTop = PrintTop   '设置上边界
      

  10.   

    我的:sTablePrint = oIni.ReadKey("TableManager", "TablePrint")    For Each objP In Printers
            Debug.Print objP.DeviceName
            If objP.DeviceName = sTablePrint Then
                Exit For
            End If
        Next
      

  11.   

    Debug.Print p.DeviceName 看到的非税票打印机
    发票打印机
    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
      

  12.   

    试下把 非税票打印机 先改成ABC,看看能不能打印。
      

  13.   

    abc也不行
    If LCase(p.DeviceName) = "非税票打印机"  "非税票打印机" 换成变量就不行,我运行后从me.text1.text显示的"非税票打印机" 拷入源代码都可以指定打印,一换变量就成默认打印机打印
      

  14.   

    下面这一句要干嘛?
    PrintName = """" & Trim(Replace(PrintName, Chr(0), "")) & """"
      

  15.   

    去掉NULL值 ,字符串两头加引号
      

  16.   


    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