by Willie Hudman (1 Submission)
Category: String Manipulation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Mon 21st August 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)
This code snipet makes a formated string for report generation or log files. You input string values, type of alignment, and postion of
'You input string values, type of alignment, and postion of string.
'It outputs one string according to your input parameters.
'An example follows.
'
'Compound Value Unit
'--------------------------------
' Methane: 130.001 uL
' Ethane: 43.887 uL
'
'
'
'--------------------------------
'Made by: Willie Hudman
'Email: [email protected]
'--------------------------------
'
'You can cut, steal, borrow, or mutilate this code any way you want.
'
'I use this in report generation for labortory reports, but is can be used
'in many other applications.
'
'This makes me money!
'
Private Sub Form_Load()
Debug.Print
Debug.Print "Compound Value Unit"
Debug.Print "--------------------------------"
sString = CreateString("Methane:", "L", 2, "130.001", "D", 20, _
"uL", "R", 32)
Debug.Print sString
sString = CreateString("Ethane:", "L", 2, "43.887", "D", 20, _
"uL", "R", 32)
Debug.Print sString
End Sub
Public Function CreateString(Optional String1 As String, _
Optional String1Align As String, _
Optional String1Pos As Integer, _
Optional String2 As String, _
Optional String2Align As String, _
Optional String2Pos As Integer, _
Optional String3 As String, _
Optional String3Align As String, _
Optional String3Pos As Integer, _
Optional String4 As String, _
Optional String4Align As String, _
Optional String4Pos As Integer, _
Optional String5 As String, _
Optional String5Align As String, _
Optional String5Pos As Integer, _
Optional String6 As String, _
Optional String6Align As String, _
Optional String6Pos As Integer) As String
Dim sString(6) As String 'Array of Strings to build.
Dim sStringAlign(6) As String 'Array of String Alingments.
Dim iStringPos(6) As Integer 'Array of String Positions.
Dim sTempString As String 'Temp string being built.
Dim x, i, iDecimalPos As Integer 'x and i loops, iDecimalPos for _
pos of decimal in "D" align.
sString(1) = String1 'Load arrays with info.
sStringAlign(1) = String1Align
iStringPos(1) = String1Pos
sString(2) = String2
sStringAlign(2) = String2Align
iStringPos(2) = String2Pos
sString(3) = String3
sStringAlign(3) = String3Align
iStringPos(3) = String3Pos
sString(4) = String4
sStringAlign(4) = String4Align
iStringPos(4) = String4Pos
sString(5) = String4
sStringAlign(5) = String4Align
iStringPos(5) = String4Pos
sString(6) = String4
sStringAlign(6) = String4Align
iStringPos(6) = String4Pos
sTempString = "" 'Lets start this baby.
For x = 1 To 6 'Loop for each string
If sString(x) <> "" Then 'If not passed to the procedure it _
will be "" and not process.
'If "L" then make spaces minus _
lenth of sTempString.
If sStringAlign(x) = "L" Or sStringAlign(x) = "l" Then
sTempString = sTempString + Space(iStringPos(x) - _
Len(sTempString) - 1)
sTempString = sTempString + sString(x)
End If
'If "R" then make spaces minus lenth _
of sSting(x) and sTempString
If sStringAlign(x) = "R" Or sStringAlign(x) = "r" Then
sTempString = sTempString + Space(iStringPos(x) - _
Len(sTempString) - Len(sString(x)))
sTempString = sTempString + sString(x)
End If
'If "D" then make spaces minus length _
of sTempString and numbers left of decimal.
If sStringAlign(x) = "D" Or sStringAlign(x) = "d" Then
For i = 1 To Len(sString(x)) 'Find decimal
iDecimalPos = i
If Mid(sString(x), i, 1) = "." Then
Exit For 'Found if, value is in iDecimalPos
End If
Next i
'If no decimal add space for correct align.
If iDecimalPos = Len(sString(x)) Then
iDecimalPos = iDecimalPos + 1
End If
sTempString = sTempString + Space(iStringPos(x) - _
Len(sTempString) - iDecimalPos)
sTempString = sTempString + sString(x)
End If
End If
Next x
CreateString = sTempString ' :)
End Function
No comments have been posted about This code snipet makes a formated string for report generation or log files. You input string value. Why not be the first to post a comment about This code snipet makes a formated string for report generation or log files. You input string value.