Loop for PDF Cells always Off by One - vb.net

I am trying to make a barcode label printer through cells. I have a pdfTable that has 3 columns. But everytime I tried to export the pdfTable with a cell count that is not equal or divisible by 3 (which is the number of columns), the cell count are always increasing or off by 1.
For example :
Tried to export 30 cells which is divisible to the pdfTable columns which is 3 (works fine)
Tried to export 1 or 10 cells which is not divisible to the pdfTable columns which is 3 (cell count are always off by 1). Results are like 1 cell become 2 cells and 10 cells become 11 cells.
I always check if there is something wrong with my loop that causes the cells to increase by 1 but I can't find anything.
Here is my code for exporting a PDF :
Public Function print_itembarcodes(lbl169 As Label)
Dim pdfTable As New PdfPTable(3) 'pdfTable Column Count'
pdfTable.DefaultCell.Padding = 3
pdfTable.WidthPercentage = 100
pdfTable.HorizontalAlignment = Element.ALIGN_CENTER
pdfTable.DefaultCell.Border = Rectangle.NO_BORDER
Dim emptyCell As New PdfPCell
emptyCell.Border = 0
Dim count As Integer
count = 0
For i As Integer = 0 To Admin_Menu.BarcodePrintListGrid.Rows.Count - 1 'Read item one by one'
Admin_Menu.Label169.Text = Admin_Menu.BarcodePrintListGrid.Rows(i).Cells(1).Value
Admin_Menu.Label170.Text = Admin_Menu.BarcodePrintListGrid.Rows(i).Cells(0).Value
Admin_Menu.Label171.Text = Admin_Menu.BarcodePrintListGrid.Rows(i).Cells(4).Value
Barcode.process_printbarcode(Admin_Menu.Label169)
save_printbarcode()
For j As Integer = 0 To Admin_Menu.BarcodePrintListGrid.Rows(i).Cells(5).Value 'Cell quantity to be exported for one item'
pdfTable.AddCell(create_barcodecell) 'Create a cell with barcode'
count = count + 1
Next
Next
For k As Integer = 0 To count Mod 3
pdfTable.AddCell(emptyCell)
Next
count = 0
Try
'Exporting to PDF'
Dim folderPath As String = "C:\Temp\"
If Not Directory.Exists(folderPath) Then
Directory.CreateDirectory(folderPath)
End If
Using stream As New FileStream(folderPath & "temp2.pdf", FileMode.Create)
Dim pdfdoc As New Document(PageSize.A4, 15.0F, 15.0F, 10.0F, 20.0F)
PdfWriter.GetInstance(pdfdoc, stream)
pdfdoc.Open()
pdfdoc.Add(pdfTable)
pdfdoc.Close()
stream.Close()
System.Diagnostics.Process.Start("C:\\Temp\\temp2.pdf")
End Using
Catch ex As MySqlException
MsgBox(ex.Message)
Finally
MysqlConn.Dispose()
End Try
Return True
End Function
Here is my code for the function of creating a cell with barcode :
Public Function create_barcodecell()
Dim SaveFileDialog1 = "D:\School\Capstone\Sta. Lucia East Bowling and Billiard Hall Management System\Item Barcodes\"
Dim Barcode2 As Image = Image.GetInstance(SaveFileDialog1 + Admin_Menu.Label169.Text + ".png")
Barcode2.ScaleAbsolute(170.0F, 50.0F)
img.ScalePercent(20.0F)
img.Alignment = iTextSharp.text.Image.ALIGN_CENTER
Dim itemname, itemprice, itemcode As New Paragraph
itemname.Alignment = Element.ALIGN_CENTER
itemprice.Alignment = Element.ALIGN_CENTER
itemcode.Alignment = Element.ALIGN_CENTER
Dim codeFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 10)
Dim tagFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)
Dim priceFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 11)
codeFont.Color = BaseColor.WHITE
tagFont.Color = BaseColor.WHITE
priceFont.Color = BaseColor.WHITE
itemname.Add(New Chunk(Admin_Menu.Label170.Text, tagFont))
itemprice.Add(New Chunk("P " + Admin_Menu.Label171.Text + ".00", priceFont))
itemcode.Add(New Chunk(Admin_Menu.Label169.Text, codeFont))
Dim pdfCell As New PdfPCell
pdfCell.UseVariableBorders = True
pdfCell.BackgroundColor = BaseColor.RED
pdfCell.BorderColorLeft = BaseColor.BLACK
pdfCell.BorderColorRight = BaseColor.BLACK
pdfCell.BorderColorTop = BaseColor.BLACK
pdfCell.BorderColorBottom = BaseColor.BLACK
pdfCell.PaddingTop = 10
pdfCell.PaddingBottom = 10
pdfCell.PaddingLeft = 8
pdfCell.PaddingRight = 10
pdfCell.AddElement(img)
pdfCell.AddElement(itemname)
pdfCell.AddElement(Barcode2)
pdfCell.AddElement(itemcode)
pdfCell.AddElement(itemprice)
Return pdfCell
End Function

The loop started by
For j As Integer = 0 To Admin_Menu.BarcodePrintListGrid.Rows(i).Cells(5).Value 'Cell quantity to be exported for one item'
executes Admin_Menu.BarcodePrintListGrid.Rows(i).Cells(5).Value + 1 times. You might want to start with the value 1 instead of 0 to get rid of the off-by-one.
The loop started by
For k As Integer = 0 To count Mod 3
executes (count Mod 3) + 1 times.
My first idea was that you might also want to start with the value 1 instead of 0, after all if Count already is a multiple of 3, you don't want it to run at all.
When I set up a simplified version of your program, though, in which I started that loop at 1, I got an exception, too. Thus, I reconsidered the actual purpose of that extra loop (which I myself recommended in my answer to your previous question) and figured out that the number of iterations was completely wrong to start with:
For Count = 1 one needs 2 extra iterations, for Count = 2 one needs 1 extra iteration, for Count = 3 none is needed, for Count = 4 one needs 2 extra iterations, ...
So, one does not need Count Mod 3 iterations of the second loop at all but instead (3 - (Count Mod 3)) Mod 3 iterations, or more simple
While count Mod 3 <> 0
pdfTable.AddCell(emptyCell)
count = count + 1
End While
which also is what intuition should dictate: Continue adding empty cells until the cell count is a multiple of 3...
The test code
I simplified your code to be able to run it at all, after all I don't have those many variables you use. The final version (including the fixes mentioned above, the first loop starting at 1, the second one using the While now) was this:
Public Sub CreateTableLuciferRodstark(filledCells As Integer, fileName As String)
Dim pdfTable As New PdfPTable(3) 'pdfTable Column Count'
pdfTable.DefaultCell.Padding = 3
pdfTable.WidthPercentage = 100
pdfTable.HorizontalAlignment = Element.ALIGN_CENTER
pdfTable.DefaultCell.Border = Rectangle.NO_BORDER
Dim emptyCell As New PdfPCell
emptyCell.Border = 0
Dim count As Integer = 0
For j As Integer = 1 To filledCells
pdfTable.AddCell(create_barcodecell) 'Create a cell with barcode'
count = count + 1
Next
While count Mod 3 <> 0
pdfTable.AddCell(emptyCell)
count = count + 1
End While
Using stream As New FileStream(fileName, FileMode.Create)
Dim pdfdoc As New Document(PageSize.A4, 15.0F, 15.0F, 10.0F, 20.0F)
PdfWriter.GetInstance(pdfdoc, stream)
pdfdoc.Open()
pdfdoc.Add(pdfTable)
pdfdoc.Close()
End Using
End Sub
Public Function create_barcodecell()
Dim pdfCell As New PdfPCell
pdfCell.UseVariableBorders = True
pdfCell.BackgroundColor = BaseColor.RED
pdfCell.BorderColorLeft = BaseColor.BLACK
pdfCell.BorderColorRight = BaseColor.BLACK
pdfCell.BorderColorTop = BaseColor.BLACK
pdfCell.BorderColorBottom = BaseColor.BLACK
pdfCell.PaddingTop = 10
pdfCell.PaddingBottom = 10
pdfCell.PaddingLeft = 8
pdfCell.PaddingRight = 10
pdfCell.AddElement(New Paragraph("an item"))
pdfCell.AddElement(New Paragraph("a code"))
pdfCell.AddElement(New Paragraph("a price"))
Return pdfCell
End Function
I ran the code for 1 to 6 filled cells:
CreateTableLuciferRodstark(1, "Table1of3.pdf")
CreateTableLuciferRodstark(2, "Table2of3.pdf")
CreateTableLuciferRodstark(3, "Table3of3.pdf")
CreateTableLuciferRodstark(4, "Table4of3.pdf")
CreateTableLuciferRodstark(5, "Table5of3.pdf")
CreateTableLuciferRodstark(6, "Table6of3.pdf")
and the results are:
Table1of3.pdf:
Table2of3.pdf:
Table3of3.pdf:
Table4of3.pdf:
Table5of3.pdf:
Table6of3.pdf:

Related

trying to add a graph through txt file on visual basic

as of now I have been able to get the data to come in and the graph portion set up. The issue is trying to use 2 separate array variables. I am using stream reader. I can not get my command in the loop where it will put all my plots in together. The values in my text file are comma separated and are as follows:
220,92,83,74,65,56,47,38,29,102
dim line (9) as string
for I as Integer = 0 To 9
using reader as StreamReader = New StreamReader("c:\New Folders\graph\small Graph.txt")
line = reader.ReadLine.Split(",")
end using
console.WriteLine(line)
console.Read()
Chart1.Titles.Add("Spectrum")
Chart1.chartAreas.Add("Default")
with chart1.chartareas("Default")
.AxisX.Title = "Channel"
.AxisY.Title = "Counts"
.AxisX. MajorGrid.LineColor = Color.AliceBlue
.AxisY. MajorGrid.LineColor = Color.AliceBlue
end with
chart1.Series.Clear()
chart1.Series.Add("file")
chart1.Series("file").color = Color.Red
chart1.Series("file").ChartType = DataVisualization.Charting.SeriesChartType.Line
Dim n As Integer
n = 10
Dim y as single
Continue For x = 0 To n Step 1
y = line(i)
Chart1.Series("file").Points.AddXY(x, y)
next
`

I want to align Dynamic pictureboxs with Dynamic Labels

Here is my function that allows me to get from a webpage the image link for my PictureBoxs and the title for my labels
Public Shared Function getPics(website As String, pattern As String)
Dim tempTitles As New List(Of String)()
Dim tempTitles2 As New List(Of String)()
Dim lestitres As New List(Of titlesclass)
Dim webClient As New WebClient()
webClient.Headers.Add("user-agent", "null")
Dim counter As Integer = 0
Dim counter2 As Integer = 0
Dim counter3 As Integer = 0
Dim counter4 As Integer = 1
Dim counter5 As Integer = 0
Dim counter6 As Integer = 0
'If the website happens to go offline, at least your application wont crash.
Dim content As String = webClient.DownloadString(website)
Dim query = From title In Regex.Matches(content, pattern).Cast(Of Match)
Select New With {Key .Link = String.Concat("http://www.gamestop.com", title.Groups("Data").Value),
Key .Title = title.Groups("Dataa").Value}
For Each letitre In query.Distinct
'MsgBox(letitre.Link & " ======= " & letitre.Title)
Next
'For Each title As Match In (New Regex(pattern).Matches(content)) 'Since you are only pulling a few strings, I thought a regex would be better.
' Dim letitre As New titlesclass
' letitre.Link = title.Groups("Data").Value
' letitre.Title = title.Groups("Dataa").Value
' lestitres.Add(letitre)
' 'tempTitles2.Add(title.Groups("Dataa").Value)
'Next
Dim titles = tempTitles.Distinct().ToArray() 'remove duplicate titles
'Dim titles2 = tempTitles2.Distinct().ToArray()
Dim titles2 = lestitres.Distinct().ToArray()
lestitres.Clear()
'For Each title As titlesclass In titles2
For Each letitre In query.Distinct
'ListBox.Items.Add(title) 'what you do with the values from here is up to you.
Dim ImageInBytes() As Byte = webClient.DownloadData(letitre.Link)
Dim ImageStream As New IO.MemoryStream(ImageInBytes)
Dim MyPic As New PictureBox
Dim MyLab As New Label
If (counter2 > 0 AndAlso ((counter2 Mod 4 = 0) OrElse counter3 = 1)) Then
counter3 = 1
counter4 += 1
If (counter2 Mod 4 = 0) Then
counter5 = 0
counter6 += 170
End If
MyPic.Location = New Point(counter5, MyPic.Location.Y + counter6)
MyLab.Location = New Point(counter5, MyPic.Location.Y + counter6)
If counter4 = 4 Then
counter3 = 0
End If
counter5 += 200
Else
MyPic.Location = New Point(counter, MyPic.Location.Y)
MyLab.Location = New Point(counter, MyPic.Location.Y)
End If
counter += 200
counter2 += 1
MyPic.SizeMode = PictureBoxSizeMode.AutoSize
MyLab.Text = letitre.Title
MyPic.Image = New System.Drawing.Bitmap(ImageStream)
Form2.Controls.Add(MyPic)
Form2.Controls.Add(MyLab)
Next
End Function
The class named titlesclass contain two elements which i will store my Link and Title in :
Public Class titlesclass
Public Property Link As String
Public Property Title As String
End Class
And My little button does all the work
Dim websiteURL1 As String = "http://www.gamestop.com/collection/upcoming-video-games"
Class1.getPics(websiteURL1, "<img src=""(?<Data>[^>]*)""><p>(?<Dataa>[^>]*)<br>")
What i'm trying to do is to show 4 pictureboxs per row with the lables right bellow each picture , for now some labels doesn't show , some shows just in the right place and some shows very far bellow ! I tested the values i'm getting with a Message Box and it shows me the informations in the order i need , i'm not sure if i screw up in the x,y values or if it's something else ...
Edit : I can already show the 4 pictureboxes per row , the labels also , but the Y of some labels isn't well adjusted it can go far far bellow !
Here is some pictures that will help you to understand my situation Don't mind the buttons and listboxs , it's just for the test :
My list containt a lot of pictures , so i just showed you some when the thing work kind of well , when it shows couple of rows far from the designed picture
http://img110.xooimage.com/files/f/a/d/picture1-5239f7c.png
http://img110.xooimage.com/files/8/f/8/picture-2-5239f7e.png
http://img110.xooimage.com/files/4/7/b/picture-3-5239f80.png
http://img110.xooimage.com/files/f/0/f/picture4-5239f82.png
So I cleaned the way you where generating the position of the PictureBox by using a row principle and increment:
Note:
If you need space at the top to add information start the row count at 1 instead of 0
Note 2:
Here the image dimensions are harcoded but you could use dynamic ones which would be more fluid. I just cleaned the positioning code not the rest.
Replace your function by this one:
Public Shared Sub getPics(website As String, pattern As String)
Dim tempTitles As New List(Of String)()
Dim tempTitles2 As New List(Of String)()
Dim lestitres As New List(Of titlesclass)
Dim webClient As New WebClient()
webClient.Headers.Add("user-agent", "null")
Dim counter As Integer = 0
Dim counter2 As Integer = 0
Dim counter3 As Integer = 0
Dim counter4 As Integer = 1
Dim counter5 As Integer = 0
Dim counter6 As Integer = 0
'If the website happens to go offline, at least your application wont crash.
'Handle default proxy
Dim proxy As IWebProxy = WebRequest.GetSystemWebProxy()
proxy.Credentials = CredentialCache.DefaultCredentials
webClient.Proxy = proxy
Dim content As String = webClient.DownloadString(website)
Dim query = From title In Regex.Matches(content, pattern).Cast(Of Match)
Select New With {Key .Link = String.Concat("http://www.gamestop.com", title.Groups("Data").Value),
Key .Title = title.Groups("Dataa").Value}
Dim titles = tempTitles.Distinct().ToArray() 'remove duplicate titles
Dim titles2 = lestitres.Distinct().ToArray()
lestitres.Clear()
'Count Items
Dim item As Integer = 0
'Count Row
Dim row As Integer = 0
'image: 222*122
For Each letitre In query.Distinct
Dim ImageInBytes() As Byte = webClient.DownloadData(letitre.Link)
Dim ImageStream As New IO.MemoryStream(ImageInBytes)
Dim MyPic As New PictureBox
Dim MyLab As New Label
'x = numéro item fois largeur image
'y = numéro de ligne fois hauteur image
MyPic.Location = New Point(item * 222, row * 122)
MyLab.Location = New Point(item * 222, row * 122)
MyPic.SizeMode = PictureBoxSizeMode.AutoSize
MyLab.Text = letitre.Title
MyPic.Image = New System.Drawing.Bitmap(ImageStream)
Form1.Controls.Add(MyPic)
Form1.Controls.Add(MyLab)
'Bring Labels to front
For Each ctrl As Control In Form1.Controls
'If the control is of type label
If TypeOf ctrl Is Label Then
'Then bring to front
ctrl.BringToFront()
End If
Next
'Increment the item count
item = item + 1
'If item is multiple of 4 or could check 4 then
If item Mod 4 = 0 Then
'Reset counter
item = 0
'Increment Row
row = row + 1
End If
Next
End Sub
Example return:

How to stop an 'Object reference not set to an instance of an object' when creating textboxes at run time in VB

For a project I require the creation of textboxes at run time, to this end I have used this code;
Dim AOP As Integer = GlobalVariables.AOP
Dim tb(11, 11) As TextBox
Dim LocationX As Integer
Dim LocationY As Integer
Dim count As Integer = 2
LocationX = 10
LocationY = 10
tb(1, 0).Name = "txtRoot"
tb(1, 0).Size = New Size(170, 20)
tb(1, 0).Location = New Point(LocationX, LocationY)
tb(1, 0).Visible = False
I am then able to loop it using this For loop;
For i = 1 To AOP
If count > AOP Then
Else
If i = AOP Then
LocationY = LocationY + 10
LocationX = 10
tb(count, 0).Name = "txtXValue" & 0 & "YValue" & count
tb(count, 0).Size = New Size(170, 20)
tb(count, 0).Location = New Point(LocationX, LocationY)
Controls.Add(tb(count, 0))
count = count + 1
i = 1
Else
LocationX = LocationX + 10
tb(count, i).Name = "txtXValue" & i & "YValue" & count
tb(count, i).Size = New Size(170, 20)
tb(count, i).Location = New Point(LocationX, LocationY)
Controls.Add(tb(count, i))
End If
End If
Next
This works in theory, however, when the code reaches the line;
tb(1, 0).Name = "txtRoot"
It returns the error 'Object reference not set to an instance of an object'
I am wondering if there is anyway around this? or if this way of creating textboxes isn't possible? Any help would be appreciated.
You have initialized the array but not added initialized TextBoxes, the array contains currently only Nothing. Also note that arrays are zero based, so the first TextBox is in tb(0, 0).
For i As Int32 = 0 To tb.GetLength(0) - 1
For ii As Int32 = 0 To tb.GetLength(1) - 1
tb(i, ii) = New TextBox()
tb(i, ii).Visible = False
' .... '
Next
Next
Now all are initialized.

There's a glitch when adding numerals to a line CSV (VB.NET)

All of the number 6's in column 6 (Item(5)) should be deleted, and the rest of the numbers should be increased by 1. However, when the process is completed, I check the file and the file is unchanged.
Dim liness As New List(Of String)(File.ReadAllLines("F:\Computing\Spelling Bee\stdnt&staffdtls.csv"))
For Each line As String In liness
Dim item() As String = line.Split(","c)
Do
If item(5) = 6 Then
liness.Remove(line)
Else : Exit Do
End If
Exit Do
Loop
Console.WriteLine("Have you already entered the next school years, year 3's? (y/n)")
Dim year3s As String = Console.ReadLine
If year3s = "Y" Or year3s = "y" Then
For i As Integer = 1 To liness.Count - 1 'this will read to the end of the array list once
If item(5) > 3 And item(5) < 6 Then
item(5) = item(5) + 1
End If
Next
ElseIf year3s = "N" Or year3s = "n" Then
For i As Integer = 1 To liness.Count - 1 'this will read to the end of the array list once
If item(5) > 2 And item(5) < 6 Then
item(5) = item(5) + 1
End If
Next
End If
File.WriteAllLines("F:\Computing\Spelling Bee\stdnt&staffdtls.csv", liness)
Exit For
Next
Exit Do
ElseIf enter.Key = ConsoleKey.End Then
Console.Clear()
adminmenu()
End If
You are updating the 'item' array, but not the 'liness' list. When you write the new 'liness' list to the file, any changes you made to the 'item' array are ignored.
Also, you are writing the 'liness' list back to the file for every loop iteration - this has to be wrong - you probably want to do that after the loop.
While I don't condone using the Split() function for parsing CSV data, I'll leave that part alone here in order to highlight other improvements in the code:
Dim minYear As Integer = 2
Console.WriteLine("Have you already entered the next school years, year 3's? (y/n)")
If Console.ReadLine().ToUpper().Trim() = "Y" Then minYear = 3
Dim NewLines = File.ReadLines("F:\Computing\Spelling Bee\stdnt&staffdtls.csv").
Select(Function(l) l.Split(","c) ).
Where(Function(l) Integer.Parse(l(5)) <> 6 ).
Select(Function(l)
Dim x As Integer = Integer.Parse(l(5))
If x >= minYear Then x += 1
l(5) = x.ToString()
Return String.Join(",", l)
End Function).ToList()
File.WriteAllLines("F:\Computing\Spelling Bee\stdnt&staffdtls.csv", NewLines)

Difficulty reading and writing binary files

My code works on my 64-bit machine but I encounter the following error (occasionally the code works fine however) when running it on a 32-bit machine:
InvalidCastException was unhandled
The next few lines provide my code:
To write to the binary file:
Dim writeStream = New FileStream(path, FileMode.Open)
Dim BinReader As BinaryReader
next_byte = Len(CStr(time)) + Len("EndOfHeader") + 16 + 2
first_time = True
BinWriter = New BinaryWriter(writeStream)
For i = 0 To Form1.signals.Length - 1
If IsNothing(Form1.signals(i)) = False Then
'once for each test
BinWriter.Write(Int(Form1.signals(i).picodata.GetLength(0) - 1)) 'n for each signal in test
BinWriter.Write(Form1.signals(i).picodata(1, 0) - Form1.signals(i).picodata(0, 0)) 'timestep
BinWriter.Write(next_byte) 'position of start of test
BinWriter.Write(CStr(time))
Exit For
End If
Next
BinWriter.Write("EndOfHeader")
For i = 0 To Form1.signals.Length - 1
If IsNothing(Form1.signals(i)) = False Then
BinWriter.Write(i)
For j = 1 To Form1.signals(i).picodata.GetLength(0) - 1
BinWriter.Write(Form1.signals(i).picodata(j, 1))
Next
End If
Next
BinWriter.Close()
To read in:
Dim readstream As FileStream
Dim end_test As Integer
Dim Index As Integer
Dim BinReader As BinaryReader
Dim end_head as Boolean=false
Dim count as integer=0
selected_test=0
ReadStream = New FileStream(readFileName, FileMode.Open)
BinReader = New BinaryReader(ReadStream)
'read header
While end_head = False
Try
pos_old = ReadStream.Position
try_string = BinReader.ReadString
If try_string = "EndOfHeader" Then
Exit While
Else
ReadStream.Position = pos_old
End If
Catch ex As Exception
ReadStream.Position = pos_old
End Try
'this approach allows for flexibility
number_arr(count) = BinReader.ReadInt32
TimeStep_arr(count) = BinReader.ReadDouble
position_arr(count) = BinReader.ReadInt32
time_arr(count) = CDate(BinReader.ReadString)
count += 1
End While
'read in data
While readstream.Position <> read_stream.length
ReDim PicoData(number_arr(selected_test), 1)
Index = BinReader.ReadInt32
n = number_arr(selected_test)
For i = 1 To n
PicoData(i, 1) = BinReader.ReadDouble
PicoData(i, 0) = TimeStep_arr(selected_test) * i
Next
ReDim TimeShort(Int(n / 20))
ReDim FiltVoltsShort(Int(n / 20))
ReDim FiltVelShort(Int(n / 20))
ReDim RawVoltsShort(Int(n / 20))
'generate new reading here
Call FourierFilter(PicoData, 0)
signals(Index) = New reading(Index, TimeShort, RawVoltsShort, FiltVelShort, FiltVoltsShort, Points_Store(ii, 2), Points_Store(ii, 1), DataChart, VelocityChart, SelectedTimeBox, SelectedVelocityBox, True, PicoData)
End While
BinReader.Close()
readstream.Close()
The date occasionally is not read in correctly. I will get some character + the date I want. Parts of my code have been cut out (since the program is pretty huge) but hopefully what I have sent will make some sense. Thanks
Your first step should be to find a simple-as-possible reproducible test case where you can make it fail every time. Then it will be much easier to identify the source of the problem.
Code like this might help you narrow down how BinaryWriter encodes strings on different platforms.
Dim content As String = New String("!"c, 255)
Using outStream As New System.IO.MemoryStream()
Using bw As New System.IO.BinaryWriter(outStream)
bw.Write(content)
bw.Flush()
outStream.Flush()
Console.WriteLine("I am a " & If(Environment.Is64BitProcess, "64", "32") & _
"-bit process")
Console.WriteLine("I generated a string of {0} characters into a stream " & _
"of {1} bytes", content.Length, outStream.Length)
End Using
End Using