Using the padRight-method
Hi,
I would like to use the padRight-method in a visual basic file (Excel VBA).
The program I wrote manipulates curve data and then exports that data (including comments, etc.)
to a text file.
The comments (5 comment lines in total) are being typed into an input-box and the values are
being stored as a string in an array called comments(5) .
Since the text file is supposed to be used as an input file of a simulation software, the text can only be
written within the first eighty columns. Therefore, I need the text of the comments to be left-alligned
and the space occupied by the text in the text file should not exceed 70 characters.
The padright-method seem to be the perfect solution for that task, but I can´t get it to work.
The fragments of the code look like this:
----------------------------------------------------------------
Dim Comments(5) As String
Comments(1) = Comments_TB_Name
Comments(2) = Comments_TB_Comment1
Comments(3) = Comments_TB_Comment2
Comments(4) = Comments_TB_Comment3
Comments(5) = Comments_TB_Comment4
' Comments_TB_Comment1,...Comments_TB_Comment4 are the comments that were
read from the input-box!
...
totalWidth
For i = 1 To 5
Comments(i) = Comments(i).PadRight(totalWidth)
Print #1, "$--- - "; Comments(i); " ---"
Next i
----------------------------------------------------------------
The function I used is:
Dim totalWidth As Integer
Dim paddingChar As String
Public Function PadLeft(ByVal totalWidth As Integer, _
ByVal paddingChar As Char) As String
End function
----------------------------------------------------------------
It would be great, if someone could help me and tell me how to apply the padright-method in an appropriate manner.
Thank you very much in advance.
Dirk
|