Jump to content


Photo
- - - - -

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


  • Please log in to reply
7 replies to this topic

#1 iamtgo3

iamtgo3

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 16 May 2012 - 01:02 PM

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)


#2 Shotaro I - Seagull Support

Shotaro I - Seagull Support

    Member

  • Moderators
  • 500 posts
  • LocationJapan

Posted 16 May 2012 - 06:58 PM

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, see this movie.

Perhaps this sample gives you some hint - though this is done by .net Print SDK + C#.

#3 iamtgo3

iamtgo3

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 17 May 2012 - 06:05 AM

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.

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, see this movie.

Perhaps this sample gives you some hint - though this is done by .net Print SDK + C#.



#4 iamtgo3

iamtgo3

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 17 May 2012 - 06:46 AM

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()

            btEngine = New Seagull.BarTender.Print.Engine()
            btEngine.Start()


I have added below to the App.Config.

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

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?

            ' 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)


#5 Shotaro I - Seagull Support

Shotaro I - Seagull Support

    Member

  • Moderators
  • 500 posts
  • LocationJapan

Posted 17 May 2012 - 06:47 PM

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()

            btEngine = New Seagull.BarTender.Print.Engine()
            btEngine.Start()


I have added below to the App.Config.

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

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?


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:
<?xml version="1.0"?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>
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'..?

#6 iamtgo3

iamtgo3

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 18 May 2012 - 04:45 AM

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.


    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)



#7 Shotaro I - Seagull Support

Shotaro I - Seagull Support

    Member

  • Moderators
  • 500 posts
  • LocationJapan

Posted 20 May 2012 - 04:36 PM

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 this post.
Try create a very simple project from scratch (such as just start and stop an engine only) to see the same issue still happens.

#8 Bobchill123

Bobchill123

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 28 September 2013 - 07:10 PM

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 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users