Printing Barcode In Vb.net Using A Text File As A Database S’abonner

0
Avatar
Legacy Poster

Hello I am trying to print a bartender label from VB.NET 2010. I have done this a million times with other datasources but I can not figure out how to use a text file from inside of VB. Here is a little over view. I first download the text file from an ftp site. Then I need to use the TAB delimited data in the text file to create my labels. Below is the code I have started on but as of right now I am a little stumped. I have used a lot of this code before but never to read in a text file as my database. There will be about 20 line with TAB delimited data representing 20 labels. Any help would be great.

[code]
Dim btApp As BarTender.Application
Dim btFormat As BarTender.Format
Dim btDB As BarTender.Database

btFormat = btApp.Formats.Open(System.AppDomain.CurrentDomain.BaseDirectory() & "labels\mylabel.btw", False, cboPrinters.SelectedItem)
btDB = btFormat.Databases.GetDatabase(1)
btDB.TextFile.FileName = gstLocalDownloadLocation & gstDownloadFilename 'Where my text file is located

'From here I am not sure how to loop thru text file to print the labels I want.

btFormat.SetNamedSubStringValue("PID", "Not Sure What To Put Here")
btFormat.SetNamedSubStringValue("PO", "Not Sure What To Put Here")
btFormat.SetNamedSubStringValue("ITEM", "Not Sure What To Put Here")
btFormat.SetNamedSubStringValue("LOT", "Not Sure What To Put Here")
btFormat.SetNamedSubStringValue("BDFT", "Not Sure What To Put Here")
btFormat.SetNamedSubStringValue("GDT", "Not Sure What To Put Here")
btFormat.SetNamedSubStringValue("PDF", "Not Sure What To Put Here")

btFormat.IdenticalCopiesOfLabel = cboLabelQuantity.Text
btFormat.PrintOut(False, False)

btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges)
[/code]

9 commentaires

0
Avatar
Shotaro Ito
Actions pour les commentaires Permalien

What you need to do is create a BarTender document which connect to text database,
assign text file by Format.Databases.GetDatabase(1).TextFile.FileName,
then PrintOut all records in once.

To create database connection for a document, [url="http://www.seagullscientific.com/aspx/training-video-(reading-data-from-database).aspx"]see this movie[/url].

Perhaps [url="http://seagullscientific.invisionzone.com/index.php?/topic/525-sample-code-create-and-assign-csv-database/page__p__1504#entry1504"]this sample[/url] gives you some hint - though this is done by .net Print SDK + C#.
0
Avatar
Legacy Poster
Actions pour les commentaires Permalien

Thanks for the reply. That was semi helpful however I am not sure how to get the SDK so I can use the Seagull.BarTender.Print.Engine, Seagull.BarTender.Print.LabelFormatDocument and others. I have added the Interop.BarTender reference to my project but it does not allow me to use the namespace Seagull.BarTender. What more do I need to add? I installed the full trial that said included the .NET SDK however the SDK folder only has examples no DLL's or usable references for my project. Can you tell me where to find those so I can reference them in my project. If I can get this up and working we are going to purchase licenses but have to have a working solution before we consider using Bartender.

[quote name='Shotaro I -Seagull Support' timestamp='1337223509' post='2439']
What you need to do is create a BarTender document which connect to text database,
assign text file by Format.Databases.GetDatabase(1).TextFile.FileName,
then PrintOut all records in once.

To create database connection for a document, [url="http://www.seagullscientific.com/aspx/training-video-(reading-data-from-database).aspx"]see this movie[/url].

Perhaps [url="http://seagullscientific.invisionzone.com/index.php?/topic/525-sample-code-create-and-assign-csv-database/page__p__1504#entry1504"]this sample[/url] gives you some hint - though this is done by .net Print SDK + C#.
[/quote]
0
Avatar
Legacy Poster
Actions pour les commentaires Permalien

ok I found the Seagull.BarTender.Print under the .NET references. Now my issue is below:

"Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information."

It errors out on the btEngine.Start()

[code]
btEngine = New Seagull.BarTender.Print.Engine()
btEngine.Start()
[/code]


I have added below to the App.Config.

[code]
<startup useLegacyV2RuntimeActivationPolicy="True">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
[/code]

Which I believe should remedy that error. However it does not. Is there something special you need to do for this to work with VB.NET .NET Framework 4.x winform application?

[code]
' Initialize a new BarTender print engine.
btEngine = New Seagull.BarTender.Print.Engine()

' Start the BarTender print engine.
btEngine.Start()

' Open format at same folder as executable
btFormat = btEngine.Documents.Open(System.AppDomain.CurrentDomain.BaseDirectory() & "labels\myLabel.btw", cboPrinters.SelectedItem)

' Assign the text database to curtent format's primary database
Dim LabelTextFile As New Seagull.BarTender.Print.Database.TextFile(gstLocalDownloadLocation & gstDownloadFilename)

btFormat.DatabaseConnections.SetDatabaseConnection(LabelTextFile)

btFormat.PrintSetup.ReloadTextDatabaseFields = True

' Print
btFormat.IdenticalCopiesOfLabel = cboLabelQuantity.Text
btFormat.Print()

' Stop the BarTender print engine.
btEngine.Stop()

btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges)
[/code]
0
Avatar
Shotaro Ito
Actions pour les commentaires Permalien

[quote name='iamtgo3' timestamp='1337265985' post='2448']
ok I found the Seagull.BarTender.Print under the .NET references. Now my issue is below:

"Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information."

It errors out on the btEngine.Start()

[code]
btEngine = New Seagull.BarTender.Print.Engine()
btEngine.Start()
[/code]


I have added below to the App.Config.

[code]
<startup useLegacyV2RuntimeActivationPolicy="True">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
[/code]

Which I believe should remedy that error. However it does not. Is there something special you need to do for this to work with VB.NET .NET Framework 4.x winform application?
[/quote]

You right - in Visual Studio 2010, you need to declare use of .net 2.0 in config file.
In the Solution Explorer edit the file app.config and change the contents to be:
[code]
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
[/code]
The notable change is that "useLegacyV2RuntimeActivationPolicy=true".

Is the error you got the same as before - Mixed mode assembly is built against version 'v2.0.50727'..?
0
Avatar
Legacy Poster
Actions pour les commentaires Permalien

I have changed that previous to posting last message and do get same message "Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information."

So I created a project in VS2010 using vb.net and .NET Framework 3.5 that seems to work with out above issue. As you can see the code is almost identical to the example you did minus the "buf". I would however like to get this to work with a vb.net desktop application using .net framework 4.x with out above errors. A lot of the tools I use for VS2010 are .net framework 4.x components.

Again just to recap my objective. I am downloading a tab delimited text file from an FTP site in vb.net. Then need to read in the text file and print each lines of the text file as its own label. I have created the label in bartender 10.x and have assinged the text file as the database and printed the labels from bartender successfully. Here is the code in a VB.NET desktop application that works for printing labels from a tab delimited file in VB.NET.

[code]

Dim btEngine As New Seagull.BarTender.Print.Engine
Dim btFormat As Seagull.BarTender.Print.LabelFormatDocument

frmMain_Load
' Initialize a new BarTender print engine.
btEngine = New Seagull.BarTender.Print.Engine()

' Start the BarTender print engine.
btEngine.Start()

btEngine.Window.VisibleWindows = Seagull.BarTender.Print.VisibleWindows.All

Button1_Click
' Open format at same folder as executable
btFormat = btEngine.Documents.Open(Application.StartupPath & "\labels\myLabel.btw", cboPrinters.SelectedItem)

' Assign the text database to curtent format's primary database
Dim LabelTextFile As Seagull.BarTender.Print.Database.TextFile = New Seagull.BarTender.Print.Database.TextFile(btFormat.DatabaseConnections(0).Name)

LabelTextFile.FileName = Application.StartupPath & "\download\" & gstDownloadFilename

btFormat.DatabaseConnections.SetDatabaseConnection(LabelTextFile)

btFormat.PrintSetup.ReloadTextDatabaseFields = True

' Print
btFormat.Print()

' Stop the BarTender print engine.
btEngine.Stop(Seagull.BarTender.Print.SaveOptions.DoNotSaveChanges)

[/code]
0
Avatar
Shotaro Ito
Actions pour les commentaires Permalien

Good to hear you could run the code, and thanks for the code posted - this would be a nice code sample for VB.net users.
For mixed mode assembly issue, BarTender .net SDK requires .net 2.0 SP2 however it supposed to work along with 4.0 with mixed mode setup above, like [url="http://seagullscientific.invisionzone.com/index.php?/topic/81-cannot-load-seagullbartenderprintdll/page__p__159__hl__%26lt%3Bsupportedruntime__fromsearch__1#entry159"]this post[/url].
Try create a very simple project from scratch (such as just start and stop an engine only) to see the same issue still happens.
0
Avatar
Legacy Poster
Actions pour les commentaires Permalien

Hello I am trying to print a bartender label from VB.NET 2010. I have done this a million times with other datasources but I can not figure out how to use a text file from inside of VB. Here is a little over view. I first download the text file from an ftp site. Then I need to use the TAB delimited data in the text file to create my labels. Below is the code I have started on but as of right now I am a little stumped. I have used a lot of this code before but never to read in a text file as my database. There will be about 20 line with TAB delimited data representing 20 labels. Any help would be great.
 

            Dim btApp As BarTender.Application
  	    Dim btFormat As BarTender.Format
	    Dim btDB As BarTender.Database
				
	    btFormat = btApp.Formats.Open(System.AppDomain.CurrentDomain.BaseDirectory() & "labels\mylabel.btw", False, cboPrinters.SelectedItem)
            btDB = btFormat.Databases.GetDatabase(1)
            btDB.TextFile.FileName = gstLocalDownloadLocation & gstDownloadFilename 'Where my text file is located

	    'From here I am not sure how to loop thru text file to print the labels I want.
			
            btFormat.SetNamedSubStringValue("PID", "Not Sure What To Put Here")
            btFormat.SetNamedSubStringValue("PO", "Not Sure What To Put Here")
            btFormat.SetNamedSubStringValue("ITEM", "Not Sure What To Put Here")
            btFormat.SetNamedSubStringValue("LOT", "Not Sure What To Put Here")
            btFormat.SetNamedSubStringValue("BDFT", "Not Sure What To Put Here")
            btFormat.SetNamedSubStringValue("GDT", "Not Sure What To Put Here")
            btFormat.SetNamedSubStringValue("PDF", "Not Sure What To Put Here")

            btFormat.IdenticalCopiesOfLabel = cboLabelQuantity.Text
            btFormat.PrintOut(False, False)

            btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges)

can this VB.NET help you solve your problem? hope it helps.

 

http://www.keepautomation.com/how_to/vbnet/

0
Avatar
Legacy Poster
Actions pour les commentaires Permalien

Hello I am trying to print a bartender label from VB.NET  2010. I have done this a million times with other datasources but I can not figure out how to use a text file from inside of VB. Here is a little over view. I first download the text file from an ftp site. Then I need to use the TAB delimited data in the text file to create my labels. Below is the code I have started on but as of right now I am a little stumped. I have used a lot of this code before but never to read in a text file as my database. There will be about 20 line with TAB delimited data representing 20 labels. Any help would be great.
 

            Dim btApp As BarTender.Application
  	    Dim btFormat As BarTender.Format
	    Dim btDB As BarTender.Database
				
	    btFormat = btApp.Formats.Open(System.AppDomain.CurrentDomain.BaseDirectory() & "labels\mylabel.btw", False, cboPrinters.SelectedItem)
            btDB = btFormat.Databases.GetDatabase(1)
            btDB.TextFile.FileName = gstLocalDownloadLocation & gstDownloadFilename 'Where my text file is located

	    'From here I am not sure how to loop thru text file to print the labels I want.
			
            btFormat.SetNamedSubStringValue("PID", "Not Sure What To Put Here")
            btFormat.SetNamedSubStringValue("PO", "Not Sure What To Put Here")
            btFormat.SetNamedSubStringValue("ITEM", "Not Sure What To Put Here")
            btFormat.SetNamedSubStringValue("LOT", "Not Sure What To Put Here")
            btFormat.SetNamedSubStringValue("BDFT", "Not Sure What To Put Here")
            btFormat.SetNamedSubStringValue("GDT", "Not Sure What To Put Here")
            btFormat.SetNamedSubStringValue("PDF", "Not Sure What To Put Here")

            btFormat.IdenticalCopiesOfLabel = cboLabelQuantity.Text
            btFormat.PrintOut(False, False)

            btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges)

Hi,have you try an easier code to do this?Why don't you try another data,maybe it will work out.This is a sample code i usually use,now i share it with you,i hope you will get a good result.

VB Sample code:

 

Dim code128 As KeepAutomation.Barcode.Bean.BarCode = New KeepAutomation.Barcode.Bean.BarCode
code128.Symbology = KeepAutomation.Barcode.Symbology.Code128Auto
code128.CodeToEncode = "0128"

'Apply checksum for Code 128 barcode.
code128.ChecksumEnabled = True
'Display checksum in the Code 128 barcode text
code128.DisplayChecksum = True

'Unit of measure, Pixel, Cm and Inch supported. 
code128.BarcodeUnit = KeepAutomation.Barcode.BarcodeUnit.Pixel
'Code 128 image resolution in DPI.
code128.DPI = 72

'Set Size for Generated Code 128 image

'Code 128 bar module width (X dimention)
code128.X = 2
'Code 128 barcode image width (X dimention)
code128.BarCodeWidth = 100
'Code 128 bar module height (Y dimention)
code128.Y = 60

'Image left margin size, a 10X is automatically added according to specification.
code128.LeftMargin = 0
'Image right margin size, a 10X is automatically added according to specification.
code128.RightMargin = 0
'Code 128 image top margin size'
code128.TopMargin = 0
'Code 128 image bottom margin size'
code128.BottomMargin = 0

'Orientation, 90, 180, 270 degrees supported' Code 128 image bottom margin size
code128.Orientation = KeepAutomation.Barcode.Orientation.Degree0
'Code 128 image formats in Png, Gif, Jpeg/Jpg, Tiff, Bmp/Bitmap, etc.
code128.ImageFormat = System.Drawing.Imaging.ImageFormat.Png

'Set Code 128 human readable text style

code128.DisplayText = True
code128.TextFont = New Drawing.Font("Arial", 10.0F, Drawing.FontStyle.Regular)
'Space between barcode and text
code128.TextMargin = 6

code128.generateBarcodeToImageFile("C://code128-vb-net.png")

 
0
Avatar
Legacy Poster
Actions pour les commentaires Permalien

Hi,

 


I have the problem..

 


I have written a small .NET windows application which prints a
specific label and fills a few label fields from a TextFile database.
The label will print properly when run bartender manually, but does not
function properly when try to print from my application. It give error, 
A sharing violation occurred while accessing file
D:\BartenderRD\Demo.txt. Please any one help. I am using trial Version
of bartender.

 

Here my Code..

private void btnPrint_Click(object sender, EventArgs e)
        {
            try
            {
                string pipe = string.Empty;
                DataSet dsPipe = new DataSet();
                DataTable dt = new DataTable();
                DataSet dsSubstring = new DataSet();
                string strPipeNo = string.Empty;
                string strHeatNo = string.Empty;
                string strCoat = string.Empty;
                string strDiameter = string.Empty;
                string strLength = string.Empty;
                string strThick = string.Empty;
                string path = string.Empty;
              if (cmbPipeNo.SelectedIndex > 0)
                {
                
                    pipe = cmbPipeNo.Text.ToString();              
                    dsPipe = GetPipeDetail(pipe);
              
                    
                    path = @"D:\BartenderRD\Demo.txt";

                    if (dsPipe.Tables[0] != null)
                    {
                        dt = dsPipe.Tables[0].Copy();
                        // string st = dt.Columns[1].ColumnName.ToString();
                        if (!File.Exists(path))
                        {
                            // Create a file to write to.
                            using (StreamWriter sw = File.CreateText(path))
                            {
                                for (int i = 0; i < dt.Rows.Count; i++)
                                {
                                    strPipeNo = dt.Rows[i][1].ToString();
                                    strHeatNo = dt.Rows[i][2].ToString();
                                    strCoat = dt.Rows[i][3].ToString();
                                    strDiameter = dt.Rows[i][4].ToString();
                                    strLength = dt.Rows[i][5].ToString();
                                    strThick = dt.Rows[i][6].ToString();
                                    sw.WriteLine(strPipeNo + "," + strHeatNo + "," + strCoat + "," + strDiameter + "," + strLength + "," + strThick);   
                                }                                                          
                            }
                        }
                        else if (File.Exists(path))
                        {
                            // Create a file to write to.
                            using (StreamWriter sw = File.CreateText(path))
                            {
                                for (int i = 0; i < dt.Rows.Count; i++)
                                {
                                    strPipeNo = dt.Rows[i][1].ToString();
                                    strHeatNo = dt.Rows[i][2].ToString();
                                    strCoat = dt.Rows[i][3].ToString();
                                    strDiameter = dt.Rows[i][4].ToString();
                                    strLength = dt.Rows[i][5].ToString();
                                    strThick = dt.Rows[i][6].ToString();
                                    sw.WriteLine(strPipeNo + "," + strHeatNo + "," + strCoat + "," + strDiameter + "," + strLength + "," + strThick);
                                    
                                }
                                labelFormat = objEngine.Documents.Open(@"D:\BartenderRD\Demopipe.btw");
                              
                                // Print
                                labelFormat.Print();
                                objEngine.Stop(SaveOptions.DoNotSaveChanges);
                             
                            }
                        }
                        
                    }     

            }

            catch (Exception ex)
            {

            }
        }

Vous devez vous connecter pour laisser un commentaire.