Monday, April 09, 2007

Happy Easter Everyone! Aside from being pummeled with the easter bunny theme, this was a great Easter for me and I learned a lot this year about the significance of the holiday as I sat with my two boys at several masses this weekend. Anyway, I thought I would add a few things I accomplished this week. We were written up in for our meat processing software system. We will see what that brings. I also spent some time making a word wrap function for when I have to print a large ingredient field to an Eltron Label printer but need to split it up into several lines. The following code is in and breaks a string up into lines using a space as the defiining end line character. I can’t say its perfect but here you go anyway

Private Sub splitingredients(ByVal ingredients As String, ByVal port As Object, ByVal lines As Integer, ByVal cpl As Integer)
'this procedure takes the ingredients variable and makes it so many lines by so many characters(cpl)
'it also sends it out the port of choice
Dim length As Integer
Dim pointer As Integer = 1
Dim linepointer As Integer
Dim currentline As String
Dim currentcharacter As String
Dim linelength As Integer = lines
Dim linenumber As Integer
Dim backcount As Integer
Dim header As Integer

ingredients = "INGREDIENTS: " & ingredients
length = Len(ingredients)
While pointer <> length
currentcharacter = Mid(ingredients, pointer, 1)
currentline = currentline & currentcharacter

If linepointer = cpl And linenumber <= lines Then
header = Asc(currentcharacter)
Do While header <> 32

pointer -= 1
currentcharacter = Mid(ingredients, pointer, 1)
header = Asc(currentcharacter)
backcount += 1

currentline = Mid(currentline, 1, (Len(currentline) - backcount))

linenumber += 1
port.Write(currentline & vbCrLf)

linepointer = 0
currentline = ""
backcount = 0

End If
linepointer += 1
pointer += 1

End While
port.Write(currentline & vbCrLf)
linenumber += 1
If linenumber < lines Then
Dim tmpint As Integer
Dim i As Integer
tmpint = lines - linenumber
For i = 1 To tmpint
port.Write(" " & vbCrLf)
End If

End Sub

No comments: