I have created a macro that writes certain data from my worksheet into a text file. This text file will be read by a separate program so I need the lines of the text file to be in a certain format. The format for the line of text is
1st 8 spaces: one or two digit integer right justified
spaces 9-24: number displayed as xxx.yyyyy but right justified so I can have up to 11 decimal places
spaces 25 - 39: Same as spaces 9-24
My code reads as follows:
intFH = FreeFile()
Open "Node.txt" For Output As intFH
Dim DNX As Single
Dim DNY As Single
Dim k As Integer
' Loop to print out node data - Note that Z dimesion is always zero for 2D Axisymmetric Models
For i = 1 To 9
DNX = Cells(i + 4, 10).Value
DNY = Cells(i + 4, 11).Value
Print #intFH, " " & i & " "; DNX & " " & DNY
Next i
For i = 1 To 43
DNX = Cells(i + 13, 10).Value
DNY = Cells(i + 13, 11).Value
k = i + 9
Print #intFH, " " & k & " "; DNX & " " & DNY
Next i
'Close File
Close #intFH
I split up the loop into two separate parts trying to get the output to line up correctly. I am thinking that there is an easier and more elegant way to handle this.
Any help is greatly appreciated.
Thanks so much.
1st 8 spaces: one or two digit integer right justified
spaces 9-24: number displayed as xxx.yyyyy but right justified so I can have up to 11 decimal places
spaces 25 - 39: Same as spaces 9-24
My code reads as follows:
intFH = FreeFile()
Open "Node.txt" For Output As intFH
Dim DNX As Single
Dim DNY As Single
Dim k As Integer
' Loop to print out node data - Note that Z dimesion is always zero for 2D Axisymmetric Models
For i = 1 To 9
DNX = Cells(i + 4, 10).Value
DNY = Cells(i + 4, 11).Value
Print #intFH, " " & i & " "; DNX & " " & DNY
Next i
For i = 1 To 43
DNX = Cells(i + 13, 10).Value
DNY = Cells(i + 13, 11).Value
k = i + 9
Print #intFH, " " & k & " "; DNX & " " & DNY
Next i
'Close File
Close #intFH
I split up the loop into two separate parts trying to get the output to line up correctly. I am thinking that there is an easier and more elegant way to handle this.
Any help is greatly appreciated.
Thanks so much.