Rhodie72
Well-known Member
- Joined
- Apr 18, 2016
- Messages
- 633
- Office Version
- 365
- 2021
- 2019
- 2016
- 2013
- 2010
- 2007
- 2003 or older
- Platform
- Windows
- Mobile
I need to write data to a text file as a data steam
I have written preliminary code to capute data in a spreadsheet but the ultimate goal is to write the data direct to a text file without using a spreadsheet.
currently the spreadsheet is just to verify that the data is being captured correctly but it needs to be written to an array and then output as a text file with a line that is the command for an AutoCAD script.
The source data
The data ouput format required for "MyFile.scr"
The code so far..
My aim is literally to capture the reordered data of co-ordinates add the command to the first output, add a new line, append rthe file with each pair of cordinates then close the file.
Anybody up for this task to help out? The person who does this will discover what impact they have had on a major construction project, so there's a bragging right attached.
I have written preliminary code to capute data in a spreadsheet but the ultimate goal is to write the data direct to a text file without using a spreadsheet.
currently the spreadsheet is just to verify that the data is being captured correctly but it needs to be written to an array and then output as a text file with a line that is the command for an AutoCAD script.
The source data
So far it produces this tableSOP1
184320.468
398332.116
77,135
SOP2
184324.959
398335.356
77,135
SOP3
184369.416
398248.340
77,135
SOP4
184317.345
398251.648
77,135
SOP1.5
184310.358
398252.072
77,135
SOP1.6
184311.268
398267.045
77,135
SOP1.7
184318.255
398266.620
77,135
SOP2.1
184356.47
398057.478
77,135
SOP2.2
184304.218
398060.209
77,135
SOP2.3
184306.115
398096.166
77,135
SOP2.4
184308.803
398099.982
77,135
SOP2.5
184309.881
398117.917
77,135
SOP2.6
184307.445
398121.375
77,135
SOP3.1
184357.481
398102.259
77,135
SOP3.2
184357.237
398098.266
77,135
SOP3.3
184311.084
398104.783
77,135
SOP3.4
184310.867
398100.789
77,135
SOP1 | 184320.468,398332.116 |
SOP2 | 184324.959,398335.356 |
SOP3 | 184369.416,398248.34 |
SOP4 | 184317.345,398251.648 |
SOP1.5 | 184310.358,398252.072 |
SOP1.6 | 184311.268,398267.045 |
SOP1.7 | 184318.255,398266.62 |
SOP2.1 | 184356.47,398057.478 |
SOP2.2 | 184304.218,398060.209 |
SOP2.3 | 184306.115,398096.166 |
SOP2.4 | 184308.803,398099.982 |
SOP2.5 | 184309.881,398117.917 |
SOP2.6 | 184307.445,398121.375 |
SOP3.1 | 184357.481,398102.259 |
SOP3.2 | 184357.237,398098.266 |
SOP3.3 | 184311.084,398104.783 |
SOP3.4 | 184310.867,398100.789 |
The data ouput format required for "MyFile.scr"
Rich (BB code):
PLINE
184320.468,398332.116 184324.959,398335.356 184369.416,398248.34 184317.345,398251.648 184310.358,398252.072 184311.268,398267.045 184318.255,398266.62 184356.47,398057.478 184304.218,398060.209 184306.115,398096.166 184308.803,398099.982 184309.881,398117.917 184307.445,398121.375 184357.481,398102.259 184357.237,398098.266 184311.084,398104.783 184310.867,398100.789
VBA Code:
Sub Adjust_ColWidth()
'
' Adjust_ColWidth Macro
' Autofit column width
'
'
Columns("A:A").EntireColumn.AutoFit
End Sub
Public Sub Delete_Blanks()
'
' Delete_Blanks Macro
' Deletes blanks in selection
'
'
With Selection
.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End With
'Application.CutCopyMode = False
End Sub
Sub Reorder_Data()
'
' Reorder_Data Macro
' Reorders data secions to correct places
'
Dim N
'
Run "Adjust_ColWidth"
Run "Delete_Blanks"
Range("A1").Select
Run "Arrange_SOP_Data"
With Selection
.Copy
N = .Count - 1
MsgBox "There are " & N & " lines of data to export", vbInformation, "Data Check"
End With
Application.CutCopyMode = False
' Export dataset to script file for AutoCAD
End Sub
Public Sub Delete_cells_up()
'
' Delete_cells_up Macro
' Deletes empty cells
'
'
With Selection
.SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp
.End(xlUp).Select
End With
End Sub
Public Sub Arrange_SOP_Data()
Dim SOP_Data As Variant, X As Variant, Y As Variant
Do Until Left(ActiveCell.Offset(1, 0).Value, 3) = ""
If Left(ActiveCell.Value, 3) = "SOP" Then
X = ActiveCell.Offset(1, 0).Text: Y = ActiveCell.Offset(2, 0).Text
SOP_Data = Array(X, ",", Y)
With ActiveCell
.Offset(0, 1).Value = SOP_Data(0) & SOP_Data(1) & SOP_Data(2)
Range(.Offset(1, 0), .Offset(3, 0)).EntireRow.Delete
.Offset(1, 0).Select
End With
Else
Stop
Do Until Left(ActiveCell.Value, 3) = "SOP"
ActiveCell.Offset(1, 0).Select
Loop
If Left(ActiveCell.Offset(1, 0).Value, 3) <> "SOP" Then
X = ActiveCell.Offset(1, 0).Value: Y = ActiveCell.Offset(2, 0).Value
SOP_Data = Array(X, ",", Y)
End If
End If
Loop
With Range("B1", ActiveCell.Offset(-1, 1))
.Select
Y = .Count
.EntireColumn.AutoFit
MsgBox Y
End With
End Sub
My aim is literally to capture the reordered data of co-ordinates add the command to the first output, add a new line, append rthe file with each pair of cordinates then close the file.
Anybody up for this task to help out? The person who does this will discover what impact they have had on a major construction project, so there's a bragging right attached.