text file into AutoCAD

Discussion in 'AutoCAD' started by Eddy, Jan 12, 2004.

  1. Eddy

    Eddy Guest

    Is there a way to pull a txt (or other ASCII file) into a AutoCAD VBA
    dialogue box? I have seen it done using a data file and pulling it into a
    dialogue box using LISP, but it is SOOOO much code. Can I do it in VBA?
    What objects should I be looking into?

    gracias.
     
    Eddy, Jan 12, 2004
    #1
  2. Eddy

    David Tosh Guest

    You may need to add a reference to the windows scripting DLL. Then use something like:

    Sub text_file2dialog()
    Dim lines As String
    Dim fs As Object
    Dim a As Object

    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.OpenTextFile("c:\MyText.txt")
    lines = a.readall ' read the whole file into the string
    a.Close 'done with the file
    MsgBox lines
    End Sub
     
    David Tosh, Jan 12, 2004
    #2
  3. I use a text box on a form. The text box is named txtLog and the form contains the following code.
    ---------------------------------------------------------------------------
    Private Sub UserForm_Initialize()
    Dim strTextLine As String
    Open "C:\set\CP_ENH_LOG.rtf" For Input As #1
    txtLog = ""
    Do Until EOF(1)
    Line Input #1, strTextLine
    txtLog = txtLog & strTextLine & vbCrLf
    Loop
    Close #1
    End Sub
     
    Nathan Taylor, Jan 12, 2004
    #3
  4. Eddy

    John Coon Guest

    How do you make the text inside the TextBox show vertical?
    All my text appeared in the TextBox but it was all one one line with a pound
    like symbol I don't see on my keyboard between the text values.
    9450,-85& 9500,-85& 9500,85..................
    Also how would you control the length of the textBox if the file is of some
    length? would I change it to a comboBox?

    Thank you as always.
    John Coon
     
    John Coon, Jan 15, 2004
    #4
  5. I don't know about showing the text vertically but there is a multiline property for the textbox which has a default value of false.
    Regards - Nathan
     
    Nathan Taylor, Jan 15, 2004
    #5
  6. If you're getting extra symbols in your text even after you set MultiLine =
    True, try changing vbCrLf to vbCr or vbLf and re-run.

    i.e. from:
    txtLog = txtLog & strTextLine & vbCrLf
    to:
    txtLog = txtLog & strTextLine & vbCr
    or:
    txtLog = txtLog & strTextLine & vbLf

    Regrettably, I don't have time to check this now to see if it helps, but I
    hope it does. Good luck,

    James
     
    James Belshan, Jan 16, 2004
    #6
  7. Eddy

    John Coon Guest

    James,

    That was it! I've never had to use that function, thank you. I'm still very
    new to vba and it's always great when I'm able to try something new and it
    actually works.
    again thank you,

    John Coon

    Those did not change the result.
     
    John Coon, Jan 17, 2004
    #7
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.