Utility Object in VBA

I though I would not bother Support with this before I check here in the forum. I am seriously confused. I try to implement user interaction with the Utility Object in VBA and I apply .GetInput() for my code to react to Keywords.My first surprise was that I found I had to place the command GetInput() after the initialize and getstring commands. The variable strInput would remain empty if I used the sequence that my VBA handbook suggested:

With thisDrawing.Utility strInput = .GetInput() .InitializeUserInput 1, "Clipboard Transformation Projection Options" fName = .GetString(True, "Enter name of export file or " _ & "[Clipboard/Transformation/Projection/Options]: ")

I found this to work:

With thisDrawing.Utility .InitializeUserInput 1, "Clipboard Transformation Projection Options" fName = .GetString(True, "Enter name of export file or " _ & "[Clipboard/Transformation/Projection/Options]: ") strInput = .GetInput()

But I have more problems (like my failure to reset the strInput variable to "", so I can reuse it: for some reason it triggers back to the last userinput string... ). And? .InitializeUserInput 1 should prevent 'Enter' as an response, according to my book..., but it does not do so.Does my workaround cause that? Should I get rid of my book? Or should I send in a support request?Any idea's?

Comments

  • This might be of use of anyone interested in my problem:

    Sub Test_This()Dim strInput As String, fName As String On Error Resume Next strInput = "" Set thisDrawing = ActiveDocument thisDrawing.Utility.InitializeUserInput 1, "Clipboard Transformation Projection Options" fName = thisDrawing.Utility.GetString(True, "Enter name of export file or " _ & "[Clipboard/Transformation/Projection/Options]: ") strInput = thisDrawing.Utility.GetInput() MsgBox "Error # " & str(Err.Number) & " was generated by " _ & Err.Source & Chr(13) & Err.Description, , "Error" MsgBox "strInput = " & strInput MsgBox "fName = " & fNameEnd Sub
  • One could ofcourse solve it with a custom function:

    Sub Test_This() Dim strInput As String, fName As String, Keywoord Dim arKeyWords As Variant arKeyWords = Array("Clipboard", "Transformation", "Projection", "Options") On Error Resume Next Set thisDrawing = ActiveDocument thisDrawing.Utility.InitializeUserInput 1, "Clipboard Transformation Projection Options" fName = thisDrawing.Utility.GetString(True, "Enter name of export file or " _ & "[Clipboard/Transformation/Projection/Options]: ") strInput = GetKeyWord(fName, arKeyWords) MsgBox "Error # " & str(Err.Number) & " was generated by " _ & Err.Source & Chr(13) & Err.Description, , "Error" MsgBox "strInput = " & strInput MsgBox "fName = " & fNameEnd SubFunction GetKeyWord(inString As String, inKeyWords As Variant) As String 'inStr As String, inArray() As String 'Only works on "keyWord" if 'W' is seperately inserted in the array Dim i As Integer GetKeyWord = False For i = LBound(inKeyWords) To UBound(inKeyWords) If VBA.LCase(inString) = VBA.LCase(VBA.Left(inKeyWords(i), VBA.Len(inString))) Then GetKeyWord = inKeyWords(i) Exit For End If Next iEnd Function
  • This surely became a one-man thread, but I obviously needed it to sort these things out. Conclusions: 1. I will probably be writing and using custom functions to replace the GetInput() method, which means I don't have to rely on interpreting a triggered error (a far better coding practice if you'd ask me).2. I believe the InitializeUserInput method to malfunctioning, and seriously so, since it is my understanding it should not trigger errors like "User input is a keyword" when only pressing an Enter, leaving the input to be "" (assuming it is declared as a String value). I'll make a support request, but lacking Bricscad documentation on how it should behave I'll be puzzled how to formulate it properly.

  • Hi Gerrit... I cannot contribute to this thread but I am interested in it.Off topic a little... Do you work in both LISP and VBA? If yes how does the VBA generally compare to LISP in Bricscad? I tried to create a routing to create LWPolylines from 3dPolylines but found it runs rather slow when dealing with larger counts of entities. I think it must the way I did it (as I really do not know much about VBA)...

  • Yep, I think you found a bug.. this code works in AutoCAD, but not in Bricscad

    (DEFUN C:doit (/ ACAD ANS DOC KEYWORD? KEYWORDLIST UTIL) (VL-LOAD-COM) (SETQ ACAD (VLAX-GET-ACAD-OBJECT) DOC (VLA-GET-ACTIVEDOCUMENT ACAD) UTIL (VLA-GET-UTILITY DOC) ) (SETQ KEYWORDLIST "A B" KEYWORD? (VLA-INITIALIZEUSERINPUT UTIL 128 KEYWORDLIST) ANS (VLA-GETKEYWORD UTIL "A/B: ") ))
  • Hi Greg. I started using VBA in Excel years ago and never felt the need to learn LISP, so unfortunately I cannot compare the two. I leave it to others to comment on speed differences.I profited very much from some good handbooks (preferable a Programmer's reference or something like that) and (responding spontaniously) I believe that if you want to write routines like converting 3dPolylines to LWPolylines you should especially study the use of Arrays. Speed is very much affected by the amount of interaction your code has with your drawing. You can limit this interaction by reading your properties (in your example: coordinates) into an array, then manipulate the array and finally write it back to your drawing as an altered or new Entity. This should be very fast. P.S. Is there any way that I can give to Greg my email address and a note he can email me without the whole community knowing about this?

  • Daniel, thanks for confirming. As I stated above the use of error handling to retrieve user input, which seems to be common practice for ACAD as well, is bad coding practice and in this instance it simply obscured the bug in InitializeUserInput (reported yesterday evening).So I'll handle all GetInput() with a custom function from now on. That causes some limitations as at the moment I cannot differentiate between the response of an Enter or a 0 at my instance of GetInteger, meaning that I'll might be forced to create another custom function replacing the GetInteger with a GetString method and interpreting the user response and convert it into an Integer.But you would not believe what I just read in my (ACAD) VBA reference book: “A bug causes GetInput to return the keyword from earlier calls to InitializeUserInput when the user enters null input at a later input method that takes keywords. The following code demonstrates the problem.” and later on “Because null and keyword input throw the same exceptions, GetInput’s return value is the only way to determine which the user entered. But because of this odd persistence of the previous keyword entry, no sure way exists to determine whether the user entered a keyword or nothing at all. The following code demonstrates a partial workaround for this problem.”Surely Bricscad is not meant to be that compatible with ACAD as to incorporate the bugs that Autodesk fails to repair? I think we all expect Bricsys to do better than that.“This is all extremely vexing”My initial go at a custom function for GetInput:

    Function GetKeyWord(inString As String, inKeyWords As Variant) As String 'Only works on "keyWord" if 'W' is seperately inserted in the array Dim i As Integer For i = LBound(inKeyWords) To UBound(inKeyWords) If VBA.LCase(inString) = VBA.LCase(VBA.Left(inKeyWords(i), VBA.Len(inString))) Then GetKeyWord = inKeyWords(i) Exit For End If Next iEnd Function
  • That was a silly quote of course and it might cause some confusion"This is all extremely vexing" is not from my VBA handbook, but from Jane Austen’s 1813 novel Pride and Prejudice

This discussion has been closed.