如何在Visual Basic 2008 Express Edition中修复此错误 [英] how to fix this error in visual basic 2008 express edition

查看:102
本文介绍了如何在Visual Basic 2008 Express Edition中修复此错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我以vb形式放置打印按钮代码时:

When i put the print button code in my vb form:

Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
        PrintForm1.PrinterSettings.DefaultPageSettings.Landscape = True
        PrintForm1.Print()


它给我错误:对象变量或With块变量未设置
对于行:PrintForm1.PrinterSettings.DefaultPageSettings.Landscape = True


it gives me the error: Object variable or With block variable not set
for line :PrintForm1.PrinterSettings.DefaultPageSettings.Landscape = True

推荐答案

可能的原因:

-PrintForm1可以为空
-PrintForm1.PrinterSettings可以为空
-PrintForm1.PrinterSettings.DefaultPageSettings可以为空.

请先检查是否为空,然后再继续.

更新1:

在VB中空检查:

Possible reason:

- PrintForm1 could be null
- PrintForm1.PrinterSettings could be null
- PrintForm1.PrinterSettings.DefaultPageSettings could be null.

Please check for null before you proceed.

Update 1:

Null Check in VB:

If PrintForm1 IsNot Nothing Then

'YOUR CODE

End If



尼什的猜想:

PrintForm1为null.

试试,



Nish''s Guess:

PrintForm1 is null.

Try,

PrintForm1 = New PrintForm1
PrintForm1.PrinterSettings.DefaultPageSettings.Landscape = True
PrintForm1.Print()



如果有帮助,请将其标记为答案



Mark it as answer if it is helpful


这篇关于如何在Visual Basic 2008 Express Edition中修复此错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆