【发布时间】:2021-12-29 15:53:50
【问题描述】:
代码的大范围是在 VB6 应用程序中显示 .net 表单。我遇到的小问题是为表单设置两个属性。此逻辑适用于另一种形式,但由于某种原因,我无法在第二种形式上设置 Device(输入参数 1)或 Scanner(输入参数 2)。
'working case statement
Case ScannerEdit
Dim Device As String = String.Empty
Dim Scanner As Integer = 0
If formInputParameters IsNot Nothing AndAlso formInputParameters.Length >= 1 Then
Device = formInputParameters(0)
End If
If formInputParameters IsNot Nothing AndAlso formInputParameters.Length >= 2 Then
Scanner = formInputParameters(1)
End If
Dim f As frmScannerEdit = base
f._Device = Device
f._Scanner = Scanner
'not working case statement
Case ScannerCommandsList
Dim Device As String = String.Empty
Dim Scanner As Integer = 0
If formInputParameters IsNot Nothing AndAlso formInputParameters.Length >= 1 Then
Device = formInputParameters(0)
End If
If formInputParameters IsNot Nothing AndAlso formInputParameters.Length >= 2 Then
Scanner = formInputParameters(1)
End If
Dim f As frmScannerCommandsList = base
f._Device = Device
f._Scanner = Scanner
在调试中运行时,代码会创建 Device 并将其设置为 Nothing,然后当参数集出现而不是将其设置为“TestDevice”时,它将保持为空。与扫描仪相同。
我试过了
If Device = Nothing Then
Device = "TestDevice"
End If
在 set Device if 语句中,但它不认为这是真的;即使 Device = Nothing,该声明的结论也是错误的。为什么我不能设置变量,为什么变量不等于Nothing时变量不等于Nothing?
【问题讨论】:
-
这不是VB6,它是vb.net。这是两种不同但相似的语言。请适当地编辑您的帖子和标签。
-
formInputParameters 是如何定义的。我不确定问题是什么?这两个 case 语句是否在同一个方法中?如果是这样,您是说使用完全相同的 formInputParameters 调用一个有效,一个无效?
-
会不会是
Device在代码中被多次声明,在不同的范围内? -
If Device Is Nothing Then
标签: string vb.net parameters integer