以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  怎么判断指定的打印机是否存在,请教老师  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=28071)

--  作者:mamuaiqing
--  发布时间:2013/1/17 20:17:00
--  怎么判断指定的打印机是否存在,请教老师

做了张打印机的表,代码如下:

Dim x As String = Tables("打印参数")(0)("打印机")

Doc.PrinterName = "x"

 

想在代码执行前先判断 指定的"X"打印机名是否存在,也就是跟电脑连接上没,代码该怎么写?


--  作者:mamuaiqing
--  发布时间:2013/1/17 20:18:00
--  
上面代码是按专业报表执行,不是窗口
--  作者:lin_hailun
--  发布时间:2013/1/18 12:47:00
--  
 查找,比较。

http://www.foxtable.com/help/topics/1601.htm

--  作者:mamuaiqing
--  发布时间:2013/1/18 19:26:00
--  

代码试半天搞不清楚,求教老师下

Dim ptn As String = Tables("打印参数")(0)("打印机")

Dim s As String = ""
For Each p As String In InstalledPrinters
    s = s & p & "|"
Next
s = s.trimEnd("|","")

If ptn <> s Then
    MessageBox.Show("未找到打印机!","温馨提示!",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If

 

上面的代码不行,执行后打印机是连着的但还是出现提示, If ptn <> s Then 这行判断代码不知道怎么写

 

\\\\Microsof-acfe67\\DPK770E这是网络打印机名,保存到了"打印参数"表



--  作者:lin_hailun
--  发布时间:2013/1/19 10:08:00
--  
呃……应该把参数跟所有的打印机名比较吧?

Dim ptn As String = Tables("打印参数")(0)("打印机")


dim canNotFind as boolean = True

For Each p As String In InstalledPrinters

     If ptn = s Then
         canNotFind = false

     End If

End IfNext


if canNotFind then

    MessageBox.Show("未找到打印机!","温馨提示!",MessageBoxButtons.OK,MessageBoxIcon.Information)

end if


--  作者:mamuaiqing
--  发布时间:2013/1/19 10:29:00
--  
感谢林老师,再请教下dim canNotFind as boolean = True这行代码是代表什么?

--  作者:mamuaiqing
--  发布时间:2013/1/19 10:45:00
--  

没实现.........执行的话都是未找到打印机

Dim ptn As String = Tables("打印参数")(0)("打印机")

Dim s As String = ""
Dim canNotFind As Boolean = True
For Each p As String In InstalledPrinters
    If ptn = s Then
        canNotFind = False
    End If
Next
If canNotFind  Then
    MessageBox.Show("未找到打印机!","温馨提示!",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If


--  作者:lin_hailun
--  发布时间:2013/1/19 12:10:00
--  
 或者试试这样。

Dim ptn As String = Tables("打印参数")(0)("打印机")


dim canNotFind as boolean = True

For Each p As String In InstalledPrinters

     If ptn like "*" & p & "*" Then
         canNotFind = false

     End If

End IfNext


if canNotFind then

    MessageBox.Show("未找到打印机!","温馨提示!",MessageBoxButtons.OK,MessageBoxIcon.Information)

end if

--  作者:程兴刚
--  发布时间:2013/1/19 12:36:00
--  
估计楼主是要从已经安装的打印机中自动找到已经连接的打印机,这个foxtable本身好像没有提供,估计要用到VB.net的其他知识。
--  作者:mamuaiqing
--  发布时间:2013/1/20 0:23:00
--  

林老师的代码执行的时候发现几个问题

 

1.代码执行后实现了判断的打印机名称,但没判断出连接状态,比如以DPK770E打印机为例,打印机电源关着也就是没连接上指定的打印机,并不会出现"未找到打印机"的提示

 

2.当为网络打印机的时候判断的名称不符合,比如网络打印机名为 \\\\Microsof-acfe67\\DPK770E ,如果打印机名就输入DPK770E的话就出现了"未找到打印机"的提示,而在报表代码执行的

 

时候打印机名为DPK770E的话也能按照名称寻找到打印机进行打印