topirol 发表于 2003-11-23 16:40:00

cad 帮助文件中的Example_InitializeUserInput例子,为何不行?

在什么情况下
StrComp(Err.Description, "User input is a keyword", 1) = 0 才成立
???
我把keywordList = "Keyword1 Keyword2"改成keywordList = “Yes Not”
输入y的时候StrComp(Err.Description, "User input is a keyword", 1) = 0
的条件也不成立。何解??

Sub Example_InitializeUserInput()
    ' This example prompts for user input of a point. By using the
    ' InitializeUserInput method to define a keyword list, it can also
    ' return keywords entered by the user.
   
    On Error Resume Next
   
    ' Define the valid keywords
    Dim keywordList As String
    keywordList = "Keyword1 Keyword2"
   
    ' Call InitializeUserInput to setup the keywords

    ThisDrawing.Utility.InitializeUserInput 128, keywordList
   
    ' Get the user input
    Dim returnPnt As Variant
    returnPnt = ThisDrawing.Utility.GetPoint(, "Enter a point(Keyword1, Keyword2): ")
    If Err Then
         If StrComp(Err.Description, "User input is a keyword", 1) = 0 Then
         ' One of the keywords was entered
             Dim inputString As String

             Err.Clear
             inputString = ThisDrawing.Utility.GetInput
             MsgBox "You entered the keyword: " & inputString
         Else
             MsgBox "Error selecting the point: " & Err.Description
             Err.Clear
         End If
    Else
      ' Display point coordinates
      MsgBox "The WCS of the point is: " & returnPnt(0) & ", " & returnPnt(1) & ", " & returnPnt(2), , "GetInput Example"

    End If
   
End Sub

mccad 发表于 2003-11-23 20:02:00

一般情况下不要使用Err.Description来得到出错信息内容,最好使用Err.Number来得到出错编号。
你可以使用debug.print err.number先看看什么样的情况下出什么样的号码,再完善程序。

topirol 发表于 2003-11-23 23:17:00

最主要几种错误的错误代码都是一样。怎么办呢?

mccad 发表于 2003-11-24 07:34:00

Sub Example_InitializeUserInput()
    ' This example prompts for user input of a point. By using the
    ' InitializeUserInput method to define a keyword list, it can also
    ' return keywords entered by the user.
   
    On Error Resume Next
   
    ' Define the valid keywords
    Dim keywordList As String
    keywordList = "Yes No"
   
    ' Call InitializeUserInput to setup the keywords

    ThisDrawing.Utility.InitializeUserInput 128, keywordList
   
    ' Get the user input
    Dim returnPnt As Variant
    returnPnt = ThisDrawing.Utility.GetPoint(, "选择点或输入[是(Y)/否(N)]<是>: ")
    If Err Then
         If Err.Number = -2145320928 Then
         ' One of the keywords was entered
             Dim inputString As String
             Err.Clear
             inputString = ThisDrawing.Utility.GetInput
             If inputString = "" Then
                MsgBox "你选择了默认的选项"
            Else
                MsgBox "你输入的关键字为: " & inputString
            End If
         Else
             MsgBox "选择点时出错: " & Err.Description
             Err.Clear
         End If
    Else
      ' Display point coordinates
      MsgBox "选择的点坐标为: " & returnPnt(0) & ", " & returnPnt(1) & ", " & returnPnt(2), , "明经通道VBA示例"

    End If
   
End Sub

topirol 发表于 2003-11-24 09:37:00

我调试的时候输入Y,出错“选择点时出错:方法getpoint作用于iacadutility时出错”

topirol 发表于 2003-11-24 10:12:00

我把错误代码改为2147467259,就可以了,不过每次用按空格(默认)的时候,总是显示上一次的值

efan2000 发表于 2003-11-24 12:54:00

按空格键返回默认值要这样设置:
If inputString = "" Then
    inputString="Yes"
End If

topirol 发表于 2003-11-24 14:14:00

但不知道怎么回事,我按空格的时候条件 If inputString = "" Then 不成立!!奇怪:(

czbming 发表于 2003-11-25 10:37:00

在初始化时不允许按空格,Bits参数改为127,如下:
ThisDrawing.Utility.InitializeUserInput 127, keywordList

czbming 发表于 2003-11-25 10:41:00

本人觉得这可能是autocad2002中的一个bug.你打上sp1再试试.我没试过.
页: [1]
查看完整版本: cad 帮助文件中的Example_InitializeUserInput例子,为何不行?