How to align dot in currency while printing - vb.net

I have something like this:
Public Function ItemsToBePrinted()
Dim p_dt As DataTable = Model_Query(2)
Dim p_str As String = ""
Dim StringToPrint As String = ""
For Each drow As DataRow In p_dt.Rows
Dim str_itemName As New String(drow.Item("item_name").ToString)
Dim str_itemQty As New String(drow.Item("item_qty").ToString)
Dim str_itemUnitPrice As New String(drow.Item("item_unitprice").ToString)
Dim str_itemDisc As New String(drow.Item("item_disamt").ToString)
Dim str_itemTotalAmt As New String(drow.Item("item_totamt").ToString)
Dim lineLen1 As String = str_itemName.Length
Dim lineLen2 As String = str_itemQty.Length
Dim lineLen3 As String = str_itemUnitPrice.Length
Dim lineLen4 As String = str_itemDisc.Length
Dim spcLen1 As New String(" "c, 20 - lineLen1)
Dim spcLen2 As New String(" "c, 5 - lineLen2)
Dim spcLen3 As New String(" "c, 5 - lineLen3)
Dim spcLen4 As New String(" "c, 8 - lineLen4)
If drow.Item("item_disamt") = 0 Then
StringToPrint = $"{str_itemName}{spcLen1}{str_itemQty}{spcLen2}{str_itemUnitPrice}{spcLen3}{spcLen4}{str_itemTotalAmt}"
Else
StringToPrint = $"{str_itemName}{spcLen1}{str_itemQty}{spcLen2}{str_itemUnitPrice}{spcLen3}{str_itemDisc}{spcLen4}{str_itemTotalAmt}"
End If
p_str &= StringToPrint & Environment.NewLine
Next
Return p_str
End Function
Public Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim p_font As Font = New Font("Consolas", 10)
e.Graphics.DrawString(PrintItemHeader(), p_font, Brushes.Black, 2 * 8, 305)
e.Graphics.DrawLine(p_pen, 16, 340, 350, 340)
e.Graphics.DrawString(ItemsToBePrinted(), p_font, Brushes.Black, 2 * 8, 345)
Currently Im using the spcLen to count the space to make them align to left but I have no idea how to change alignment to right...
Here is the output:
How can I align the dot like this? All the data will align to right except Item Code
Item Code Qty Unit Disc Amount
Price
----------------------------------------------
XXXX 33 4.70 155.10
XXXX 2 3.00 6.00
XXXX 2 9.00 1.80 16.20
XXXX 1 7.50 7.50
XXXX 11 12.00 10.00 122.00

When you have to print the numeric columns you should put the spaces before the number and not after it because you want them aligned on the right
I would write a simple method that aligns your columns data on the right or on the left according to the space and the alignment required.
Function AlignText(text As String, TotalSpace As Integer, AlignRight As Boolean)
Dim alignResult As String
if string.IsNullOrEmpty Then
alignResult = new String(" "c, TotalSpace)
Else
if text.Length > TotalSpace Then
text = text.SubString(0, TotalSpace)
End If
If AlignRight Then
alignResult = New String(" "c, TotalSpace - text.Length) & text
Else
alignResult = text & New String(" "c, TotalSpace - text.Length)
End If
End If
Return alignResult
End Function
Now you can call this method in this way
Dim str_itemName = AlignText(drow.Item("item_name").ToString, 20, False)
Dim str_itemQty = AlignText(drow.Item("item_qty").ToString, 3, True)
Dim str_itemUnitPrice = AlignText(drow.Item("item_unitprice").ToString, 10, True)
Dim str_itemDisc = AlignText(drow.Item("item_disamt").ToString), 10, True)
Dim str_itemTotalAmt = AlignText(drow.Item("item_totamt").ToString), 10, True)
Of course you should remove all your space's calcs inside the loop and this coding will also remove the need of an If to skip the missing discount field

You should format your string using the String.Format function which allows you to create useful string representation when printing. Check out these 2 links:
https://www.dotnetperls.com/format-vbnet
https://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx

Related

How to convert TIFF File to ASCII Hex to send ZPL to a Zebra Printer

I am creating an application to dynamically print Labels to a networked Zebra printer. I can easily send text values but also need to include a logo at the bottom of the label. The logo(s) are stored on a network location and are tiff files.
I am struggling to find a good example of how to do this. The following code does print, but the returned string I receive from the file is purely FFFFF.... So all I am getting is a black rectangle.
Protected Sub Print()
Dim IP As String = "172.16.132.92"
Dim clientSocket As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
clientSocket.Connect(New IPEndPoint(IPAddress.Parse(IP), 9100))
Dim bitmapFilePath As String = "\\SomeServer\Advertising\Artwork\Trademarks\Packaging Label Trademarks 8919\Betaplug.tif"
Dim bitmapFileData As Byte() = System.IO.File.ReadAllBytes(bitmapFilePath)
Dim fileSize As Integer = bitmapFileData.Length
Dim bitmapDataOffset As Integer = 0
Dim width As Integer = 50 '255
Dim height As Integer = 50 '255
Dim bitsPerPixel As Integer = 1
Dim bitmapDataLength As Integer = 400
Dim widthInBytes As Double = Math.Ceiling(width / 8.0)
Dim bitmap(bitmapDataLength) As Byte
For i As Integer = 0 To bitmapDataLength Step 1
bitmap(i) = bitmap(i) Xor &HFF
Next
Dim ZPLImageDataString As String = BitConverter.ToString(bitmap)
ZPLImageDataString = Replace(ZPLImageDataString, "-", String.Empty)
Dim ZPL As String = "~DGR:SAMPLE.GRF," & bitmapDataLength & ",018," & _
ZPLImageDataString & _
"^XA" & _
"^F100,200^XGR:SAMPLE.GRF,2,2^FS" & _
"^XZ^"
Dim Label As String = ZPL
clientSocket.Send(Encoding.UTF8.GetBytes(Label))
clientSocket.Close()
End Sub
Here's how I tackled this in the past. This code was pulled out of a drag&drop label designer so it has some conversions in it for handling differences in DPI which you'll have to remove if not needed. But the basic process was to get a bitmap, resize it so its width is divisible by 8 for encoding, make it monochrome since this was an on/off pixel thermal printer, convert its bits to a hex string, and then use ZPL's compression map to compress it (less we end up with a ridiculously long string that takes forever to send to the printer).
The 0.8 threshold is just a number I found to work pretty reliably, it is the cut-off value for deciding whether a bit is on/off depending on how dark it is, you may need to adjust that to suit your needs.
Input Image was:
Output using Labelary's online ZPL viewer (http://labelary.com/viewer.html):
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim imgZpl As String = TiffToZpl("C:\Users\sooho\Desktop\so.tif", 0.8)
Debug.Print(imgZpl)
End Sub
Public Function TiffToZpl(tiffFilePath As String, grayscaleThreshold As Single) As String
Dim ms As New System.IO.MemoryStream
System.Drawing.Bitmap.FromFile(tiffFilePath).Save(ms, System.Drawing.Imaging.ImageFormat.Png)
Dim bmp = New System.Drawing.Bitmap(ms)
ResizeBitmapMod8(bmp)
bmp = Monochrome(bmp, grayscaleThreshold)
Return BitmapToZpl(bmp, 0, 0)
End Function
Private Function BitmapToZpl(ByRef bm As Bitmap, top As Integer, left As Integer) As String
Dim ret As New System.Text.StringBuilder
Dim lastHexChar As Nullable(Of Char) = Nothing
Dim hexCharCount As Integer = 0
Dim finalHex As New System.Text.StringBuilder
Dim bitCount As Integer = 0
Dim binaryCount As Integer = 0
For r As Integer = 0 To bm.Height - 1
For c As Integer = 0 To bm.Width - 1
bitCount += 1
If Not bm.GetPixel(c, r).Name.Equals("ffffffff") Then
Select Case bitCount
Case 1 : binaryCount += 8
Case 2 : binaryCount += 4
Case 3 : binaryCount += 2
Case 4 : binaryCount += 1
End Select
End If
If bitCount = 4 Then
If lastHexChar Is Nothing Then
lastHexChar = CChar(hexMap(binaryCount))
hexCharCount = 1
Else
If CChar(hexMap(binaryCount)) = lastHexChar Then
hexCharCount += 1
Else
While hexCharCount > 0
Dim maxKey As Integer = 0
For Each key As Integer In zplHexCompressionMap.Keys
If key <= hexCharCount Then
maxKey = key
Else
Exit For
End If
Next
finalHex.Append(zplHexCompressionMap(maxKey) & lastHexChar)
hexCharCount -= maxKey
End While
lastHexChar = CChar(hexMap(binaryCount))
hexCharCount = 1
End If
End If
bitCount = 0
binaryCount = 0
End If
Next c
Next r
While hexCharCount > 0
Dim maxKey As Integer = 0
For Each key As Integer In zplHexCompressionMap.Keys
If key <= hexCharCount Then
maxKey = key
Else
Exit For
End If
Next
finalHex.Append(zplHexCompressionMap(maxKey) & lastHexChar)
hexCharCount -= maxKey
End While
Dim totalBytes As Integer = CInt((bm.Height * bm.Width) / 8)
Dim byteWidth As Integer = CInt(bm.Width / 8)
Dim adjustedLeft As Integer = CInt(left * dpiMultiplier_ScreenToPrinter)
Dim adjustedTop As Integer = CInt(top * dpiMultiplier_ScreenToPrinter)
ret.Append("^FO" & adjustedLeft.ToString & "," & adjustedTop.ToString)
ret.Append("^GFA," & totalBytes.ToString & "," & totalBytes.ToString & "," & byteWidth.ToString & ",,")
ret.Append(finalHex.ToString)
ret.Append("^FS")
Return ret.ToString
End Function
Private Sub ResizeBitmapMod8(ByRef bm As Bitmap)
'Resizes a bitmap to its nearest width multiple of 8. Images must be hex-encoded
'to be send to the printer, and hex encoding requires pairs of 4 bits, so the
'the image's width must be divisible by 8 or the resulting image will have a black
'strip down the side once it's decoded by the zpl printer
If bm.Width Mod 8 <> 0 Then
Dim width As Integer = bm.Width
Dim height As Integer = bm.Height
Dim aspectRatio As Double = width / height
Dim lowMultiplier As Integer = CInt(Int(width / 8))
Dim highMultiplier As Integer = lowMultiplier + 1
Dim diffBelow As Integer = width - (lowMultiplier * 8)
Dim diffAbove As Integer = (highMultiplier * 8) - width
If diffBelow < diffAbove Then
width = lowMultiplier * 8
Else
width = highMultiplier * 8
End If
height = CInt(width / aspectRatio)
Dim bmResized As New Bitmap(width, height)
Dim gfxResized As Graphics = Graphics.FromImage(bmResized)
gfxResized.DrawImage(bm, 0, 0, bmResized.Width + 1, bmResized.Height + 1)
bm = bmResized
End If
End Sub
Private Function Monochrome(ByVal bmOriginal As Bitmap, grayscaleThreshold As Single) As Bitmap
Dim gsBitmap As New Bitmap(bmOriginal)
Try
'Convert image to grayscale
Dim gfxSource As Graphics = Graphics.FromImage(gsBitmap)
Dim imgAttr As New System.Drawing.Imaging.ImageAttributes
Dim imgRec As Rectangle = New Rectangle(0, 0, gsBitmap.Width, gsBitmap.Height)
imgAttr.SetColorMatrix(New System.Drawing.Imaging.ColorMatrix(grayMatrix))
imgAttr.SetThreshold(grayscaleThreshold)
gfxSource.DrawImage(gsBitmap, imgRec, 0, 0, gsBitmap.Width, gsBitmap.Height, GraphicsUnit.Pixel, imgAttr)
Catch ex As Exception
'image already has an indexed color matrix
End Try
'Convert format to 1-index monochrome
Dim mcBitmap As Bitmap = New Bitmap(gsBitmap.Width, gsBitmap.Height, Imaging.PixelFormat.Format1bppIndexed)
Dim mcBmData As Imaging.BitmapData = mcBitmap.LockBits(
New Rectangle(0, 0, mcBitmap.Width, mcBitmap.Height),
Imaging.ImageLockMode.ReadWrite,
Imaging.PixelFormat.Format1bppIndexed)
For y As Integer = 0 To gsBitmap.Height - 1
For x As Integer = 0 To gsBitmap.Width - 1
Dim pixelColor As Color = gsBitmap.GetPixel(x, y)
If pixelColor.Name = "ffffffff" Then
Dim index As Integer = y * mcBmData.Stride + (x >> 3)
Dim p As Byte = Runtime.InteropServices.Marshal.ReadByte(mcBmData.Scan0, index)
Dim mask As Byte = CByte(&H80 >> (x And &H7))
p = p Or mask
Runtime.InteropServices.Marshal.WriteByte(mcBmData.Scan0, index, p)
End If
Next x
Next y
mcBitmap.UnlockBits(mcBmData)
Return mcBitmap
End Function
Public Const DPI_Screen As Double = 96
Public Const DPI_Printer As Double = 203
Public Const dpiMultiplier_ScreenToPrinter As Double = DPI_Printer / DPI_Screen
Public grayMatrix()() As Single = {
New Single() {0.299F, 0.299F, 0.299F, 0, 0},
New Single() {0.587F, 0.587F, 0.587F, 0, 0},
New Single() {0.114F, 0.114F, 0.114F, 0, 0},
New Single() {0, 0, 0, 1, 0},
New Single() {0, 0, 0, 0, 1}}
Private hexMap() As String = {
"0", "1", "2", "3", "4", "5", "6", "7",
"8", "9", "A", "B", "C", "D", "E", "F"}
Private zplHexCompressionMap As New SortedDictionary(Of Integer, Char) From {
{1, "G"c}, {2, "H"c}, {3, "I"c}, {4, "J"c}, {5, "K"c},
{6, "L"c}, {7, "M"c}, {8, "N"c}, {9, "O"c}, {10, "P"c},
{11, "Q"c}, {12, "R"c}, {13, "S"c}, {14, "T"c}, {15, "U"c},
{16, "V"c}, {17, "W"c}, {18, "X"c}, {19, "Y"c}, {20, "g"c},
{40, "h"c}, {60, "i"c}, {80, "j"c}, {100, "k"c}, {120, "l"c},
{140, "m"c}, {160, "n"c}, {180, "o"c}, {200, "p"c}, {220, "q"c},
{240, "r"c}, {260, "s"c}, {280, "t"c}, {300, "u"c}, {320, "v"c},
{340, "w"c}, {360, "x"c}, {380, "y"c}, {400, "z"c}}
End Class

Change font style to Richtextbox vb.net

I need to change font style and add it to Richtextbox, this is my code but i get some errors. please help
Dim sb = New StringBuilder()
sb.AppendFormat(New Font("IDAutomationHC39M", 12,FontStyle.Regular).AppendLine("SCAN BARCODE: " & txtBarcode.Text)
RichTextBoxPrintCtrl1.Text = sb.ToString()
To change the font for only a part of the text in your RichTextBox you need to search for the text required, then calculate its length and select it. At this point you can apply the font you want to the SelectionFont property.
Sub SetBarCodeText(searchText as String)
Dim len As Integer = searchText.Length
Dim pos As Integer = RichTextBoxPrintCtrl1.Find(searchText, 0, RichTextBoxFinds.NoHighlight)
if pos >= 0 Then
Dim start As Integer = pos
Dim endpos As Integer = start + len
RichTextBoxPrintCtrl1.Select(start, endpos - start)
RichTextBoxPrintCtrl1.SelectionFont = new Font("IDAutomationHC39M", 12, FontStyle.Regular)
End If
End Sub
and you call the method above with
RichTextBoxPrintCtrl1.Text = "SCAN BARCODE: " & txtBarcode.Text
SetBarCodeText("SCAN BARCODE: " & txtBarcode.Text)

Reading and writing from a csv file

Structure TownType
Dim Name As String
Dim County As String
Dim Population As Integer
Dim Area As Integer
End Structure
Sub Main()
Dim TownList As TownType
Dim FileName As String
Dim NumberOfRecords As Integer
FileName = "N:\2_7_towns(2).csv"
FileOpen(1, FileName, OpenMode.Random, , , Len(TownList))
NumberOfRecords = LOF(1) / Len(TownList)
Console.WriteLine(NumberOfRecords)
Console.ReadLine()
There are only 12 records in the file but this returns a value of 24 for number of records. How do I fix this?
Contents of csv file:
Town, County,Pop, Area
Berwick-upon-tweed, Nothumberland,12870,468
Bideford, devon,16262,430
Bognor Regis, West Sussex,62141,1635
Bridlington, East Yorkshire,33589,791
Bridport, Dorset,12977,425
Cleethorpes, Lincolnshire,31853,558
Colwyn bay, Conway,30269,953
Dover, Kent,34087,861
Falmouth, Cornwall,21635,543
Great Yarmouth, Norfolk,58032,1467
Hastings, East Sussex,85828,1998
This will read the contents into a collection and you can get the number of records from the collection.
Sub Main()
Dim FileName As String
Dim NumberOfRecords As Integer
FileName = "N:\2_7_towns(2).csv"
'read the lines into an array
Dim lines As String() = System.IO.File.ReadAllLines(FileName)
'read the array into a collection of town types
'this could also be done i a loop if you need better
'parsing or error handling
Dim TownList = From line In lines _
Let data = line.Split(",") _
Select New With {.Name = data(0), _
.County = data(1), _
.Population = data(2), _
.Area = data(3)}
NumberOfRecords = TownList.Count
Console.WriteLine(NumberOfRecords)
Console.ReadLine()
End Sub
Writing to the console would be accomplished with something like:
For Each town In TownList
Console.WriteLine(town.Name + "," + town.County)
Next
Many ways to do that
Test this:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
dim FileName as string = "N:\2_7_towns(2).csv"
Dim Str() As String = System.IO.File.ReadAllLines(filename)
'Str(0) contains : "Town, County,Pop, Area"
'Str(1) contains : "Berwick-upon-tweed, Nothumberland,12870,468"
'Str(2) contains : "Bideford, devon,16262,430"
' etc...
'Sample code for string searching :
Dim Lst As New List(Of String)
Lst.Add(Str(0))
Dim LookingFor As String = "th"
For Each Line As String In Str
If Line.Contains(LookingFor) Then Lst.Add(Line)
Next
Dim Result As String = ""
For Each St As String In Lst
Result &= St & Environment.NewLine
Next
MessageBox.Show(Result)
'Sample code creating a grid :
Dim Grid = New DataGridView
Me.Controls.Add(Grid)
Grid.ColumnCount = Str(0).Split(","c).GetUpperBound(0) + 1
Grid.RowCount = Lst.Count - 1
Grid.RowHeadersVisible = False
For r As Integer = 0 To Lst.Count - 1
If r = 0 Then
For i As Integer = 0 To Lst(r).Split(","c).GetUpperBound(0)
Grid.Columns(i).HeaderCell.Value = Lst(0).Split(","c)(i)
Next
Else
For i As Integer = 0 To Lst(r).Split(","c).GetUpperBound(0)
Grid(i, r - 1).Value = Lst(r).Split(","c)(i)
Next
End If
Next
Grid.AutoResizeColumns()
Grid.AutoSize = True
End Sub

How can I get String values rather than integer

How To get StartString And EndString
Dim startNumber As Integer
Dim endNumber As Integer
Dim i As Integer
startNumber = 1
endNumber = 4
For i = startNumber To endNumber
MsgBox(i)
Next i
Output: 1,2,3,4
I want mo make this like sample: startString AAA endString AAD
and the output is AAA, AAB, AAC, AAD
This is a simple function that should be easy to understand and use. Every time you call it, it just increments the string by one value. Just be careful to check the values in the text boxes or you can have an endless loop on your hands.
Function AddOneChar(Str As String) As String
AddOneChar = ""
Str = StrReverse(Str)
Dim CharSet As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
Dim Done As Boolean = False
For Each Ltr In Str
If Not Done Then
If InStr(CharSet, Ltr) = CharSet.Length Then
Ltr = CharSet(0)
Else
Ltr = CharSet(InStr(CharSet, Ltr))
Done = True
End If
End If
AddOneChar = Ltr & AddOneChar
Next
If Not Done Then
AddOneChar = CharSet(0) & AddOneChar
End If
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim S = TextBox1.Text
Do Until S = TextBox2.Text
S = AddOneChar(S)
MsgBox(S)
Loop
End Sub
This works as a way to all the codes given an arbitrary alphabet:
Public Function Generate(starting As String, ending As String, alphabet As String) As IEnumerable(Of String)
Dim increment As Func(Of String, String) = _
Function(x)
Dim f As Func(Of IEnumerable(Of Char), IEnumerable(Of Char)) = Nothing
f = _
Function(cs)
If cs.Any() Then
Dim first = cs.First()
Dim rest = cs.Skip(1)
If first = alphabet.Last() Then
rest = f(rest)
first = alphabet(0)
Else
first = alphabet(alphabet.IndexOf(first) + 1)
End If
Return Enumerable.Repeat(first, 1).Concat(rest)
Else
Return Enumerable.Empty(Of Char)()
End If
End Function
Return New String(f(x.ToCharArray().Reverse()).Reverse().ToArray())
End Function
Dim results = New List(Of String)
Dim text = starting
While True
results.Add(text)
If text = ending Then
Exit While
End If
text = increment(text)
End While
Return results
End Function
I used it like this to produce the required result:
Dim alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
Dim results = Generate("S30AB", "S30B1", alphabet)
This gave me 63 values:
S30AB
S30AC
...
S30BY
S30BZ
S30B0
S30B1
It should now be very easy to modify the alphabet as needed and to use the results.
One option would be to put those String values into an array and then use i as an index into that array to get one element each iteration. If you do that though, keep in mind that array indexes start at 0.
You can also use a For Each loop to access each element of the array without the need for an index.
if the default first two string value of your output is AA.
You can have a case or if-else conditioning statement :
and then set 1 == A 2 == B...
the just add or concatenate your default two string and result string of your case.
I have tried to understand that you are looking for a series using range between 2 textboxes. Here is the code which will take the series and will give the output as required.
Dim startingStr As String = Mid(TextBox1.Text, TextBox1.Text.Length, 1)
Dim endStr As String = Mid(TextBox2.Text, TextBox2.Text.Length, 1)
Dim outputstr As String = String.Empty
Dim startNumber As Integer
Dim endNumber As Integer
startNumber = Asc(startingStr)
endNumber = Asc(endStr)
Dim TempStr As String = Mid(TextBox1.Text, 1, TextBox1.Text.Length - 1)
Dim i As Integer
For i = startNumber To endNumber
outputstr = outputstr + ", " + TempStr + Chr(i)
Next i
MsgBox(outputstr)
The First two lines will take out the Last Character of the String in the text box.
So in your case it will get A and D respectively
Then outputstr to create the series which we will use in the loop
StartNumber and EndNumber will be give the Ascii values for the character we fetched.
TempStr to Store the string which is left off of the series string like in our case AAA - AAD Tempstr will have AA
then the simple loop to get all the items fixed and show
in your case to achive goal you may do something like this
Dim S() As String = {"AAA", "AAB", "AAC", "AAD"}
For Each el In S
MsgBox(el.ToString)
Next
FIX FOR PREVIOUS ISSUE
Dim s1 As String = "AAA"
Dim s2 As String = "AAZ"
Dim Last As String = s1.Last
Dim LastS2 As String = s2.Last
Dim StartBase As String = s1.Substring(0, 2)
Dim result As String = String.Empty
For I As Integer = Asc(s1.Last) To Asc(s2.Last)
Dim zz As String = StartBase & Chr(I)
result += zz & vbCrLf
zz = Nothing
MsgBox(result)
Next
**UPDATE CODE VERSION**
Dim BARCODEBASE As String = "SBA0021"
Dim BarCode1 As String = "SBA0021AA1"
Dim BarCode2 As String = "SBA0021CD9"
'return AA1
Dim FirstBarCodeSuffix As String = Replace(BarCode1, BARCODEBASE, "")
'return CD9
Dim SecondBarCodeSuffix As String = Replace(BarCode2, BARCODEBASE, "")
Dim InternalSecondBarCodeSuffix = SecondBarCodeSuffix.Substring(1, 1)
Dim IsTaskCompleted As Boolean = False
For First As Integer = Asc(FirstBarCodeSuffix.First) To Asc(SecondBarCodeSuffix)
If IsTaskCompleted = True Then Exit For
For Second As Integer = Asc(FirstBarCodeSuffix.First) To Asc(InternalSecondBarCodeSuffix)
For Third As Integer = 1 To 9
Dim tmp = Chr(First) & Chr(Second) & Third
Console.WriteLine(BARCODEBASE & tmp)
If tmp = SecondBarCodeSuffix Then
IsTaskCompleted = True
End If
Next
Next
Next
Console.WriteLine("Completed")
Console.Read()
Take a look into this check it and let me know if it can help

How to Display a Bmp in a RTF control in VB.net

I Started with this C# Question
I'm trying to Display a bmp image inside a rtf Box for a Bot program I'm making.
This function is supposed to convert a bitmap to rtf code whis is inserted to another rtf formatter srtring with additional text. Kind of like Smilies being used in a chat program.
For some reason the output of this function gets rejected by the RTF Box and Vanishes completly. I'm not sure if it the way I'm converting the bmp to a Binary string or if its tied in with the header tags
lb.SelectedRtf = FormatText(build.ToString, newColor)
'returns the RTF string representation of our picture
Public Shared Function PictureToRTF(ByVal Bmp As Bitmap) As String
'Create a new bitmap
Dim BmpNew As New Bitmap(Bmp.Width, Bmp.Height, Imaging.PixelFormat.Format24bppRgb)
Dim gr = Graphics.FromImage(BmpNew)
gr.DrawimageUnscaled(Bmp, 0, 0)
gr.dispose()
Dim stream As New MemoryStream()
BmpNew.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp)
Dim bytes As Byte() = stream.ToArray()
Dim str As String = BitConverter.ToString(bytes, 0).Replace("-", String.Empty)
'header to string we want to insert
Using g As Graphics = Main.CreateGraphics()
xDpi = g.DpiX
yDpi = g.DpiY
End Using
Dim _rtf As New StringBuilder()
' Calculate the current width of the image in (0.01)mm
Dim picw As Integer = CInt(Math.Round((Bmp.Width / xDpi) * HMM_PER_INCH))
' Calculate the current height of the image in (0.01)mm
Dim pich As Integer = CInt(Math.Round((Bmp.Height / yDpi) * HMM_PER_INCH))
' Calculate the target width of the image in twips
Dim picwgoal As Integer = CInt(Math.Round((Bmp.Width / xDpi) * TWIPS_PER_INCH))
' Calculate the target height of the image in twips
Dim pichgoal As Integer = CInt(Math.Round((Bmp.Height / yDpi) * TWIPS_PER_INCH))
' Append values to RTF string
_rtf.Append("{\pict\wbitmap0")
_rtf.Append("\picw")
_rtf.Append(Bmp.Width.ToString)
' _rtf.Append(picw.ToString)
_rtf.Append("\pich")
_rtf.Append(Bmp.Height.ToString)
' _rtf.Append(pich.ToString)
_rtf.Append("\wbmbitspixel24\wbmplanes1")
_rtf.Append("\wbmwidthbytes40")
_rtf.Append("\picwgoal")
_rtf.Append(picwgoal.ToString)
_rtf.Append("\pichgoal")
_rtf.Append(pichgoal.ToString)
_rtf.Append("\bin ")
_rtf.Append(str.ToLower & "}")
Return _rtf.ToString
End Function
Public Function FormatText(ByVal data As String, ByVal newColor As fColorEnum) As String
data = System.Net.WebUtility.HtmlDecode(data)
data = data.Replace("|", " ")
Dim reg As New Regex("\$(.[0-9]+)\$")
If reg.IsMatch(data) Then
Dim meep As String = Regex.Match(data, "\$(.[0-9]+)\$").Groups(1).ToString
Dim idx As Integer = Convert.ToInt32(meep)
Dim img As String = Fox2RTF(idx)
If img IsNot Nothing Then data = Regex.Replace(data, "\$(.[0-9]+)\$", img)
End If
Dim myColor As System.Drawing.Color = fColor(newColor)
Dim ColorString = "{\colortbl ;"
ColorString += "\red" & myColor.R & "\green" & myColor.G & "\blue" & myColor.B & ";}"
Dim FontSize As Integer = cMain.ApFont.Size
Dim FontFace As String = cMain.ApFont.Name
FontSize *= 2
Dim test As String = "{\rtf1\ansi\ansicpg1252\deff0\deflang1033" & ColorString & "{\fonttbl{\f0\fcharset0 " & FontFace & ";}}\viewkind4\uc1\fs" & FontSize.ToString & data & "\par}"
Return "{\rtf1\ansi\ansicpg1252\deff0\deflang1033" & ColorString & "{\fonttbl{\f0\fcharset0 " & FontFace & ";}}\viewkind4\uc1\fs" & FontSize.ToString & data & "\cf0 \par}"
End Function
Private Function Fox2RTF(ByRef Img As Integer) As String
Dim shape As New FurcadiaShapes(Paths.GetDefaultPatchPath() & "system.fsh")
Dim anims As Bitmap() = Helper.ToBitmapArray(shape)
' pic.Image = anims(Img)
Return PictureToRTF.PictureToRTF(anims(Img))
End Function
Never found the Soultion I was hoping for with this.. But I did find a work around http://www.codeproject.com/Articles/30902/RichText-Builder-StringBuilder-for-RTF