Trouble with an depreciated constructor visual basic visual studio 2010

Posted by VBPRIML on Stack Overflow See other posts from Stack Overflow or by VBPRIML
Published on 2010-06-14T13:41:50Z Indexed on 2010/06/14 18:52 UTC
Read the original article Hit count: 294

Filed under:

My goal is to print labels with barcodes and a date stamp from an entry to a zebra TLP 2844 when the user clicks the ok button/hits enter. i found what i think might be the code for this from zebras site and have been integrating it into my program but part of it is depreciated and i cant quite figure out how to update it. below is what i have so far. The printer is attached via USB and the program will also store the entered numbers in a database but i have that part done. any help would be greatly Appreciated.

 
Public Class ScanForm
 
   Inherits System.Windows.Forms.Form
   Public Const GENERIC_WRITE = &H40000000
   Public Const OPEN_EXISTING = 3
   Public Const FILE_SHARE_WRITE = &H2
 
   Dim LPTPORT As String
   Dim hPort As Integer
 
   Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String,
                                                                          ByVal dwDesiredAccess As Integer,
                                                                          ByVal dwShareMode As Integer, <MarshalAs(UnmanagedType.Struct)> ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES,
                                                                          ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer,
                                                                          ByVal hTemplateFile As Integer) As Integer
 
 
 
   Public Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject As Integer) As Integer
 
   Dim retval As Integer
 
 
 
 
  <StructLayout(LayoutKind.Sequential)> Public Structure SECURITY_ATTRIBUTES
 
       Private nLength As Integer
       Private lpSecurityDescriptor As Integer
       Private bInheritHandle As Integer
 
   End Structure
 
 
 
 
   Private Sub OKButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OKButton.Click
 
       Dim TrNum
       Dim TrDate
       Dim SA As SECURITY_ATTRIBUTES
       Dim outFile As FileStream, hPortP As IntPtr
 
       LPTPORT = "USB001"
       TrNum = Me.ScannedBarcodeText.Text()
       TrDate = Now()
 
       hPort = CreateFile(LPTPORT, GENERIC_WRITE, FILE_SHARE_WRITE, SA, OPEN_EXISTING, 0, 0)
 
       hPortP = New IntPtr(hPort) 'convert Integer to IntPtr
 
       outFile = New FileStream(hPortP, FileAccess.Write) 'Create FileStream using Handle
       Dim fileWriter As New StreamWriter(outFile)
 
       fileWriter.WriteLine(" ")
       fileWriter.WriteLine("N")
       fileWriter.Write("A50,50,0,4,1,1,N,")
       fileWriter.Write(Chr(34))
       fileWriter.Write(TrNum) 'prints the tracking number variable
       fileWriter.Write(Chr(34))
       fileWriter.Write(Chr(13))
       fileWriter.Write(Chr(10))
       fileWriter.Write("A50,100,0,4,1,1,N,")
       fileWriter.Write(Chr(34))
       fileWriter.Write(TrDate) 'prints the date variable
       fileWriter.Write(Chr(34))
       fileWriter.Write(Chr(13))
       fileWriter.Write(Chr(10))
       fileWriter.WriteLine("P1")
       fileWriter.Flush()
       fileWriter.Close()
       outFile.Close()
       retval = CloseHandle(hPort)
 
       'Add entry to database
       Using connection As New SqlClient.SqlConnection("Data Source=MNGD-LABS-APP02;Initial Catalog=ScannedDB;Integrated Security=True;Pooling=False;Encrypt=False"), _
       cmd As New SqlClient.SqlCommand("INSERT INTO [ScannedDBTable] (TrackingNumber, Date) VALUES (@TrackingNumber, @Date)", connection)
           cmd.Parameters.Add("@TrackingNumber", SqlDbType.VarChar, 50).Value = TrNum
           cmd.Parameters.Add("@Date", SqlDbType.DateTime, 8).Value = TrDate
           connection.Open()
           cmd.ExecuteNonQuery()
           connection.Close()
       End Using
 
       'Prepare data for next entry
       ScannedBarcodeText.Clear()
       Me.ScannedBarcodeText.Focus()
 
   End Sub
 

© Stack Overflow or respective owner

Related posts about visual-studio-2010