在分析字段中选择案例

时间:2013-06-18 17:11:16

标签: vb.net parsing

我需要在解析器字符串中执行选择案例。我需要选择第二个字段(工作正常)然后根据第二个字段返回字符串的方式,我需要将其切换一点,但由于某种原因它不能正常工作,我想我可能没有绑定它r的权利,不确定。

                Dim r as DataRow
                Dim command = fields(1)
                Select Case command
                    Case 1
                        If fields(1) = "<Left Mouse Down> <Left Mouse Up> <Right Mouse Up>" Then
                            r("Mouse Command") = "Left Click"
                        End If

                    Case 2
                        If fields(1) = "<Right Mouse Down> <Left Mouse Up> <Right Mouse Up" Then
                            r("Mouse Command") = "Right click"
                        End If

                    Case 3
                        If fields(1) = "<Left Mouse Up> <Right Mouse Up>" & Microsoft.VisualBasic.LTrim("Scroll Wheel Roll") Then
                            r("Mouse Command") = "Scroll Wheel"
                        End If

                    Case 4
                        If fields(1) = Microsoft.VisualBasic.LTrim("<Left Mouse Up> <Right Mouse Up> <Press ") Then
                            r("Mouse Command") = "Key Press"
                        End If

                    Case 5
                        If fields(1) = "<Left Mouse Up> <Right Mouse Up>" Then
                            r("Mouse Command") = "Double Click"
                        End If

                End Select

解决

1 个答案:

答案 0 :(得分:0)

我认为您正在某处访问错误的field索引。在Dim command = fields(1)行或If fields(1) = ...语句中。

fields(1)不能同时是1到5之间的数字,也不能是包含Left Mouse Down ...的字符串

以你的第一个案例为例:

Dim command = fields(1) '' You're accessing fields(1) here looking for an int
Select Case command
    Case 1
        If fields(1) = "..." '' and here, but looking for a string
...
相关问题