API - Set MyData = New DataObject

Discussion in 'SolidWorks' started by Wayne Tiffany, Aug 19, 2004.

  1. I posted this to the VB group and haven't had any replies yet. Any thoughts
    here?

    I was following the instructions in Help to T, I thought, and pasted this
    code into a new project. However, when I hit the command button, I got an
    error that said "Invalid use of New keyword." Interestingly, I have used
    almost identical code in a SolidWorks macro and it worked fine. But when I
    tried to put it into another project in VB6, it would produce the error.
    So, I went to Help and tried it "by the book." What am I missing?

    WT


    Paste, PutInClipboard, SetText Methods Example

    The following example demonstrates data movement from a TextBox to a
    DataObject, from a DataObject to the Clipboard, and from the Clipboard to
    another TextBox. The PutInClipboard method transfers the data from a
    DataObject to the Clipboard. The SetText and Paste methods are also used.

    To use this example, copy this sample code to the Declarations portion of a
    form. Make sure that the form contains:

    a.. Two TextBox controls named TextBox1 and TextBox2.

    b.. A CommandButton named CommandButton1.

    Dim MyData As DataObject

    Private Sub CommandButton1_Click()
    Set MyData = New DataObject

    MyData.SetText TextBox1.Text
    MyData.PutInClipboard

    TextBox2.Paste
    End Sub

    Private Sub UserForm_Initialize()
    TextBox1.Text = "Move this data to a " _
    & "DataObject, to the Clipboard, then to " _
    & "TextBox2!"
    End Sub
     
    Wayne Tiffany, Aug 19, 2004
    #1
  2. Wayne Tiffany

    rocheey Guest

    I have used

    The difference between Visual Basic, and VBA. (Solidworks Macro=VBA)

    The dataObject is used for 2 different purposes between the two.
    Hightlight ther "DataObject" word and hit F1 in VB. and VBA, repectively.

    BTW, "TextBox2.Copy" would be compatible between both 'flavors'
     
    rocheey, Aug 19, 2004
    #2
  3. Thanks - this is basically what I just figured out. Since I don't have the
    MSDN collection loaded on my machine, I was using the Help from inside SW,
    and that's where I got the example code. Duhhhhh, big mistake, because, as
    you point out, that version is VBA, not VB.

    So, the end result is that in VB, the Clipboard is an object in itself and
    therefore you just reference it directly.

    Clipboard.SetText TextBox1.Text
    TextBox2.Text = Clipboard.GetText

    Sorry to have wasted everyone's time. I have once again learned the hard
    way.....

    WT
     
    Wayne Tiffany, Aug 19, 2004
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.