Trasferimento dati numerici in file .txt

di
Anonimizzato13652
il
5 risposte

Trasferimento dati numerici in file .txt

Buongiorno a tutti, premetto che sono nuovo nella programmazione con Visual Basic perciò mi trovo di fronte sempre a nuovi problemi. Vi spiego il problema postando prima il codice:

Sub main()
Dim swApp As SldWorks.SldWorks
Dim doc As SldWorks.ModelDoc2
Dim part As SldWorks.PartDoc
Dim sm As SldWorks.SelectionMgr
Dim feat As SldWorks.Feature
Dim sketch As SldWorks.sketch
Dim v As Variant
Dim i As Long
Dim sseg As SldWorks.SketchSegment
Dim sline As SldWorks.SketchLine
Dim sp As SldWorks.SketchPoint
Dim ep As SldWorks.SketchPoint
Dim s As String

Dim exApp As Excel.Application
Dim sheet As Excel.Worksheet

 Set exApp = New Excel.Application
 If Not exApp Is Nothing Then
  exApp.Visible = True
  If Not exApp Is Nothing Then
   exApp.Workbooks.Add
   Set sheet = exApp.ActiveSheet
   If Not sheet Is Nothing Then
    sheet.Cells(1, 5).Value = "Job Number"
    sheet.Cells(1, 6).Value = "=NOW()"
    sheet.Cells(2, 2).Value = "X"
    sheet.Cells(2, 3).Value = "Y"
    sheet.Cells(2, 4).Value = "Z"
   End If
  End If
 End If
 
 Set swApp = GetObject(, "sldworks.application")
 If Not swApp Is Nothing Then
  Set doc = swApp.ActiveDoc
  If Not doc Is Nothing Then
   If doc.GetType = swDocPART Then
    Set part = doc
    Set sm = doc.SelectionManager
    If Not part Is Nothing And Not sm Is Nothing Then
     If sm.GetSelectedObjectType2(1) = swSelSKETCHES Then
      Set feat = sm.GetSelectedObject4(1)
      Set sketch = feat.GetSpecificFeature
      If Not sketch Is Nothing Then
       v = sketch.GetSketchPoints
       For i = LBound(v) To UBound(v)
        Set sp = v(i)
        If Not sp Is Nothing And Not sheet Is Nothing And Not exApp Is Nothing Then
         sheet.Cells(3 + i, 1).Value = "Pt. " & i + 1
         sheet.Cells(3 + i, 2).Value = Round(sp.X * 1000 / 1, 3)
         sheet.Cells(3 + i, 3).Value = Round(sp.Y * 1000 / 1, 3)
         sheet.Cells(3 + i, 4).Value = Round(sp.Z * 1000 / 1, 3)
         exApp.Columns.AutoFit
        End If
       Next i
      End If
     End If
    End If
   End If
  End If
 End If
End Sub
In pratica questa è una macro che va ad agire sul software CAD 3D SolidWorks: il suo scopo è quello di estrapolare una serie di coordinate da uno schizzo e trasferirle su un file excel.
La mia domanda è questa: se anzichè volerle trasferire in un file excel io volessi semplicemente trasferirle su un file .txt, come si modificherebbe il codice? Ci ho provato in molti modi ma data la mia inesperienza mi trovo in alto mare. Grazie a tutti in anticipo.

Saluti

5 Risposte

  • Re: Trasferimento dati numerici in file .txt

    Ma questa è la sezione per il VB6 non per il VBA

    In ogni caso puoi facilmente usare le istruzioni

    Open
    Print #
    Close

    per aprire, scrivere e chiudere un file di testo.
  • Re: Trasferimento dati numerici in file .txt

    Sorry, allora ho sbagliato sezione!!Provvedo subito a portare questo post sul forum apposito!!...
  • Re: Trasferimento dati numerici in file .txt

    Scusa, sarò rincoglionito io, ma sono andato a vedere e mi dice che è questa la sezione del forum dedicata al VBA, oltre che al VB 6.0

    Sbaglio?
  • Re: Trasferimento dati numerici in file .txt

    goniz88 ha scritto:


    Scusa, sarò rincoglionito io, ma sono andato a vedere e mi dice che è questa la sezione del forum dedicata al VBA, oltre che al VB 6.0

    Sbaglio?
    Ni.
    Nel senso che di VBA ce ne sono diversi tipi: per VB6, per Office, per AutoCAD, ecc...

    Il punto è che tu parli di VBA per Excel, per il quale esiste l'apposita sezione Excel
    http://www.iprogrammatori.it/forum-programmazione/excel/

    nel gruppo OFFICE AUTOMATION
    http://www.iprogrammatori.it/forum-programmazione/office-automation/

    Per cui se posti qui, si suppone che il tuo ambiente di progettazione sia Visual Basic 6.0...
    Ma dato che parli di macro, così non sembra, visto che in VB6.0 non esistono le macro.

    Se invece usi proprio VB6.0 allora non sei stato sufficientemente chiaro.

  • Re: Trasferimento dati numerici in file .txt

    Ok grazie della correzione! Ho appena spostato la discussione nella sezione idonea!
Devi accedere o registrarti per scrivere nel forum
5 risposte