EDN Admin
Well-known member
I wrote a bar code program sometime ago with vb.net that when the end user clicks the print button, the program will open the text file that contains the ZPL bar code, increment the serial number by 1, write the new serial number back to the text file, and
then print out the predetermined amount of bar codes to a zebra printer.
Now I am trying to rewrite the code so that it will print the number of bar codes the end user wants from the number they type into the PrintDialog. In my updated code, I tried putting in a DO......LOOP UNTIL . It will print out the number of bar codes the
user puts into the PrintDialog box, but it doesnt serialize. By that I mean if the user enters 5 into the PrintDialog, the program will print serial # 01 five times instead of printing 02, 03, 04, 05, 06.
Can anyone give me some pointers on how to have the program read, write, and print the desired x amount of times based on the number a user inputs into the PrintDialog?
Here is my original code:
<pre class="prettyprint lang-vb Dim sL() As String = IO.File.ReadAllLines("C:Labelsloop test.txt")
Dim CurrentBar(2) As String
For i = 0 To 2
CurrentBar(i) = sL(sL.Length - 3 + i)
Next
If CurrentBar(1).Length >= 28 Then
CurrentBar(1) = CurrentBar(1).Substring(0, 18) & Format(CInt(CurrentBar(1).Substring(18, 10) + 1), "0000000000") & CurrentBar(1).Substring(28)
Else
MessageBox.Show("String is not long enough!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Write the updated vaules back to the Text File
IO.File.WriteAllText("C:Labelsloop test.txt",
CurrentBar(0) & vbNewLine &
CurrentBar(1) & vbNewLine &
CurrentBar(2))
Dim psi As New ProcessStartInfo
psi.UseShellExecute = True
psi.Verb = "print"
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.FileName = "C:Labelsloop test.txt"
Process.Start(psi)
[/code]
And here is my updated code:
<pre class="prettyprint lang-vb Dim PrintDialog1 As New PrintDialog()
Dim psi As New ProcessStartInfo
Do
Put the text file into an array and increment the line containing the Serial # by 1
Dim sL() As String = IO.File.ReadAllLines("\10.5.2.250TxtFiles$4x6LoopTest.txt")
Dim CurrentBar(2) As String
For i = 0 To 2
CurrentBar(i) = sL(sL.Length - 3 + i)
Next
If CurrentBar(1).Length >= 28 Then
CurrentBar(1) = CurrentBar(1).Substring(0, 18) & Format(CInt(CurrentBar(1).Substring(18, 10) + 1), "0000000000") & CurrentBar(1).Substring(28)
Else
MessageBox.Show("String is not long enough!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Write the updated vaules back to the Text File
IO.File.WriteAllText("\10.5.2.250TxtFiles$4x6LoopTest.txt",
CurrentBar(0) & vbNewLine &
CurrentBar(1) & vbNewLine &
CurrentBar(2))
Print the labels
Get the number of copies to print
If (PrintDialog1.ShowDialog() = DialogResult.OK) Then
For i = 0 To PrintDialog1.PrinterSettings.Copies - 1
psi.UseShellExecute = True
psi.Verb = "print"
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.Arguments = PrintDialog1.PrinterSettings.PrinterName.ToString()
psi.FileName = "\10.5.2.250TxtFiles$4x6LoopTest.txt"
Process.Start(psi)
Next
End If
Loop Until PrintDialog1.PrinterSettings.Copies[/code]
And my text file:
<pre class="prettyprint ^XA
^LH20,85^BY3^AE^SN0000000001R,,Y^B3N,,60,,Y^FS
^XZ[/code]
<br/>
View the full article
then print out the predetermined amount of bar codes to a zebra printer.
Now I am trying to rewrite the code so that it will print the number of bar codes the end user wants from the number they type into the PrintDialog. In my updated code, I tried putting in a DO......LOOP UNTIL . It will print out the number of bar codes the
user puts into the PrintDialog box, but it doesnt serialize. By that I mean if the user enters 5 into the PrintDialog, the program will print serial # 01 five times instead of printing 02, 03, 04, 05, 06.
Can anyone give me some pointers on how to have the program read, write, and print the desired x amount of times based on the number a user inputs into the PrintDialog?
Here is my original code:
<pre class="prettyprint lang-vb Dim sL() As String = IO.File.ReadAllLines("C:Labelsloop test.txt")
Dim CurrentBar(2) As String
For i = 0 To 2
CurrentBar(i) = sL(sL.Length - 3 + i)
Next
If CurrentBar(1).Length >= 28 Then
CurrentBar(1) = CurrentBar(1).Substring(0, 18) & Format(CInt(CurrentBar(1).Substring(18, 10) + 1), "0000000000") & CurrentBar(1).Substring(28)
Else
MessageBox.Show("String is not long enough!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Write the updated vaules back to the Text File
IO.File.WriteAllText("C:Labelsloop test.txt",
CurrentBar(0) & vbNewLine &
CurrentBar(1) & vbNewLine &
CurrentBar(2))
Dim psi As New ProcessStartInfo
psi.UseShellExecute = True
psi.Verb = "print"
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.FileName = "C:Labelsloop test.txt"
Process.Start(psi)
[/code]
And here is my updated code:
<pre class="prettyprint lang-vb Dim PrintDialog1 As New PrintDialog()
Dim psi As New ProcessStartInfo
Do
Put the text file into an array and increment the line containing the Serial # by 1
Dim sL() As String = IO.File.ReadAllLines("\10.5.2.250TxtFiles$4x6LoopTest.txt")
Dim CurrentBar(2) As String
For i = 0 To 2
CurrentBar(i) = sL(sL.Length - 3 + i)
Next
If CurrentBar(1).Length >= 28 Then
CurrentBar(1) = CurrentBar(1).Substring(0, 18) & Format(CInt(CurrentBar(1).Substring(18, 10) + 1), "0000000000") & CurrentBar(1).Substring(28)
Else
MessageBox.Show("String is not long enough!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Write the updated vaules back to the Text File
IO.File.WriteAllText("\10.5.2.250TxtFiles$4x6LoopTest.txt",
CurrentBar(0) & vbNewLine &
CurrentBar(1) & vbNewLine &
CurrentBar(2))
Print the labels
Get the number of copies to print
If (PrintDialog1.ShowDialog() = DialogResult.OK) Then
For i = 0 To PrintDialog1.PrinterSettings.Copies - 1
psi.UseShellExecute = True
psi.Verb = "print"
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.Arguments = PrintDialog1.PrinterSettings.PrinterName.ToString()
psi.FileName = "\10.5.2.250TxtFiles$4x6LoopTest.txt"
Process.Start(psi)
Next
End If
Loop Until PrintDialog1.PrinterSettings.Copies[/code]
And my text file:
<pre class="prettyprint ^XA
^LH20,85^BY3^AE^SN0000000001R,,Y^B3N,,60,,Y^FS
^XZ[/code]
<br/>
View the full article