[VBA] In Need of Layman's Terms

I have no experience with writing code of any kind.  I have been able to glean a few tips regarding how to make a VBA from reading a number of trouble shooting posts and the MicroStationVBA.chm, but can someone please answer the following questions in the most simple way they know how?  In other words, in layman's terms.

1.  What does the variable type Long do?

2.  What is an element enumerator?

3.  What does adding .Text to a variable type do?  For instance, textEl.text

4.  I know that a dimensioned variable name as a string can store text, but how do I insert that text back into my VBA?  Example:

Someone has helped me get this far with figuring out how to parse text from a selection set

Dim textEl As TextElement
Set textEl = ee.Current.AsTextElement
Dim myText As String
myText = textEl.Text

I assumed that I can now use the variable myText to insert the text that I have parsed out back into my VBA, but after trying this I found out I could not.  Can someone explain to me in layman's terms how to insert a string back into my VBA?

If the language I used is off, please do not take this opportunity to make fun of me as others have, I am very new at this.

P.S.  I know about the Learning MicroStation VBA book, I cannot afford it.

Parents
  • Unknown said:
    Can someone explain to me in layman's terms how to insert a string back into my VBA?

    Welcome to the world of VBA!  There's plenty of jargon to learn  8-)

    VBA for MicroStation shares many characteristics with VBA for Office and other applications.  Some of your questions are generic and apply to all VBA implementations...

    Unknown said:
    What does the variable type Long do?

    VBA supports various data types.  Some are numeric, some are not (e.g. String).  Numeric types include:

    Type NameComment
    Integer Whole number 16 bits
    Long Whole number 32 bits
    Double Floating-point (decimal) number 64 bits
    Float Floating-point (decimal) number 32 bits

    You can find more about numeric and other data types by visiting the MSDN web site, or one of any number of other web sites that deal with VBA.

    Unknown said:
    What is an element enumerator?

    In general, an enumerator is a mechanism for iterating a collection of objects.  MicroStation VBA provides enumerators for several purposes.  An ElementEnumerator is used to iterate the components of a complex object, such as a cell or text node.

    Unknown said:
    What does adding .Text to a variable type do?

    Objects have properties.  Objects that contain text have a Text property.  For example, in a VBA UserForm, a TextBox has a Text property.  You can get and set the value of that property.  In a DGN model, you might have a TextElement object, which also has a Text property.

    When you create a variable of a type that can store text, you refer to its Text property using dot notation:

    Dim oText As TextElement
    '... get text element from somewhere
    Debug.Print "Text element value=" & oText.Text

    Unknown said:
    Can someone explain to me in layman's terms how to insert a string back into my VBA?

    It's not clear what you mean.  Your code snippet declares String variable myText, and you assign myText a value from a TextElement.  What do you want to do?

     
    Regards, Jon Summers
    LA Solutions

  • Jon,
    Thank you for the quick and informative answers to my questions. My goal is to create a VBA that will do the following once I select a text element in a level [the text content are numbers (1, 2, 3, 4, etc.)] and then run my VBA:

    •I want to be able to select one text element, parse its content as a number and attach this number to a defined general URL [as a reference ID (www.webpage.com/1, www.webpage.com/2, www.webpage.com/3, www.webpage.com/4, www.webpage.com/etc.].
    •The result should be attached to the selected element as a URL link.

    I developed the following VBA that does not parse the content from the text element I have selected, instead it only attaches a general URL and then immediately opens "links edit" so I can type in the reference ID myself. I would like to skip the last step, but I do not know how to use the variable type "String" properly:

    Sub Macro1()
    Dim startPoint As Point3d
    Dim point As Point3d, point2 As Point3d
    Dim lngTemp As Long

    ' Start a command
    CadInputQueue.SendKeyin "ELEMENT CREATE LINK URL http://www.google.com"

    ' Send a keyin that can be a command string
    CadInputQueue.SendKeyin "links edit"

    ' Send a data point to the current command
    point.X = startPoint.X
    point.Y = startPoint.Y
    point.Z = startPoint.Z
    CadInputQueue.SendDataPoint point, 1

    CommandState.StartDefaultCommand
    End Sub
  • Sub Init ()
      Dim oText As TextElement
      '... get text element somehow
      Dim content As String
      content = oText.Text
      CreateLink content
    End Sub
    
    Sub CreateLink (ByVal content As String)
      Dim strURL As String
      strURL = "http://www.google.com" & "/" & content
      Debug.Print "My URL=" & strURL
      ' Start a command
      CadInputQueue.SendKeyin "ELEMENT CREATE LINK URL " & strURL
    End Sub    
    

    The above is incomplete and not tested. Hope it helps!

     
    Regards, Jon Summers
    LA Solutions

  • Thanks Jon, I'll play with this and see what I can do. Any chance you could answer two more questions for me though?

    1. Do people use "Dim ee As ElementEnumerator" because it does something, or do people just not want to type ElementEnumerator over and over?

    2. Can you tell me what Debug.Print does? In layman's terms?
Reply Children
  • Unknown said:
    Can you tell me what Debug.Print does?

    It writes your message to the VBA IDE's Immediate window.  It's useful when you want to confirm that your logic is doing what you think it should be doing.  In my example abov, it prints the URL so you can see what the link will get. 

    Only you, the developer, can see Debug.Print output.  A normal user of your macro can't see it.

    Unknown said:
    Do people use "Dim ee As ElementEnumerator" because it does something

    It declares a variable named ee whose type is ElementEnumerator.

    Unknown said:
    Do people just not want to type ElementEnumerator over and over?

    Probably they don't, but there's no need to.  Usually you declare a single variable of that particular type and use it once in your procedure.  You'll find examples in VBA help .

     
    Regards, Jon Summers
    LA Solutions