Imports System Imports System.ComponentModel Imports System.Threading Imports System.IO.Ports Imports System.Data Imports System.Data.Odbc Imports OpcLabs.EasyOpc.DataAccess Imports OpcLabs.BaseLib Imports OpcLabs.EasyOpc Public Class Recipe_Selector Delegate Sub SetTextCallback(ByVal [text] As String) 'Added to prevent threading errors during receiving of data Dim Batch_ID As String Dim BatchNum As Integer Dim WithEvents OPCDAClient As EasyDAClient Dim Cnn As OdbcConnection Dim Cmd As OdbcCommand Const ODBCConnstring = "DSN=BOC_GasFilling" Const OPCSVR = "" Const OPCSVRNAME = "ArchestrA.DASSIDirect.3" Const OPCTagPrefix = "Channel1.Device1." Const NumProcs = 20 Dim ProcData(,) As Object ' For 15-30 Procedures with 75 parameters - zero indexed Dim writeItems() As OpcLabs.EasyOpc.DataAccess.DAItemValueArguments Dim writeResults() As OperationResult Dim Recipe_ID(200) As Integer 'To refer the collume in Recipe Table '===================================================================' '================== This Code Disables The 'X' ===================' Protected Overrides ReadOnly Property CreateParams() As CreateParams Get Dim cp As CreateParams = MyBase.CreateParams Const CS_NOCLOSE As Integer = &H200 cp.ClassStyle = cp.ClassStyle Or CS_NOCLOSE Return cp End Get End Property '================== This Code Disables The 'X' ===================' '===================================================================' Private Sub Main_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed For i As Integer = 0 To UBound(writeItems) Step 1 If writeItems(i) IsNot Nothing Then writeItems(i) = Nothing End If Next If OPCDAClient IsNot Nothing Then OPCDAClient.Dispose() End If If Cmd IsNot Nothing Then Cmd.Dispose() End If If Cnn IsNot Nothing Then Cnn.Close() Cnn.Dispose() End If If SerialPort1.IsOpen Then SerialPort1.Close() End If End Sub Private Sub Recipe_Selector_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim Ra As OdbcDataReader Dim i As Integer Dim CmdString As String Dim Barcode_Enable As Boolean Dim M1_Barcode_No, M2_Barcode_No, M3_Barcode_No, M4_Barcode_No, M5_Barcode_No, M6_Barcode_No As Integer Me.TopMost = True ComboBox1.Enabled = True ' Enable the combobox1 ' To load all Barcode Number into the application Try Cnn = New OdbcConnection(ODBCConnstring) Cnn.Open() CmdString = "Select Barcode_No From [Barcode_Table] Order by Barcode_No" Cmd = New OdbcCommand(CmdString, Cnn) Ra = Cmd.ExecuteReader() Me.ComboBox5.Items.Clear() Do While Ra.Read() If Ra.Item(0) = 0 Then Me.ComboBox5.Items.Add("No Barcode") Else Me.ComboBox5.Items.Add(Ra.Item(0)) End If Loop ComboBox5.SelectedIndex = 0 Ra.Close() Cmd.Dispose() Catch ex As System.Data.Odbc.OdbcException MessageBox.Show(ex.Message, "ODBC Exception111", MessageBoxButtons.OK, MessageBoxIcon.Error) Catch ex As System.Exception MessageBox.Show(ex.Message, "System Exception111", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try ReDim ProcData(NumProcs - 1, 74) ReDim writeItems(((NumProcs * 75) - 1) + 3) ReDim writeResults(((NumProcs * 75) - 1) + 3) BatchNum = 0 'Change the back color according to Module 1 to 6 Try Me.Text = "Module " & Module_Num & ": Recipe Selection" & "Version1.3" Me.TopMost = True Select Case Module_Num Case 1 Me.BackColor = Color.FromArgb(192, 192, 255) Case 2 Me.BackColor = Color.FromArgb(0, 255, 255) Case 3 Me.BackColor = Color.Red Case 4 Me.BackColor = Color.Orange Case 5 Me.BackColor = Color.Yellow Case 6 Me.BackColor = Color.FromArgb(255, 128, 255) End Select Me.GroupBox2.Enabled = True Me.GroupBox3.Enabled = True Button9.Enabled = False OPCDAClient = New EasyDAClient OPCDAClient.ClientMode.AllowAsynchronousMethod = True 'When True, Async reads and write are allowed OPCDAClient.ClientMode.AllowSynchronousMethod = True 'When True, Sync reads and writes are allowed OPCDAClient.ClientMode.DesiredMethod = 1 'Determines if reads and writes are done async (1) or sync (2). 'We now populate the list box with recipes for the specific module Barcode_Enable = OPCDAClient.ReadItemValue("", "ArchestrA.DASSIDirect.3", "Channel1.Device1.DB200,X24.0") If Barcode_Enable Then TextBox6.BackColor = Color.Green Else TextBox6.BackColor = Color.Red End If 'TextBox6.Text = Barcode_Enable If Barcode_Enable = True Then 'If Barcode Function is Enable Select Case Module_Num 'Module 1 Barcode Handle Case 1 M1_Barcode_No = OPCDAClient.ReadItemValue("", "ArchestrA.DASSIDirect.3", "Channel1.Device1.DB200,DINT26") 'MessageBox.Show(M1_Barcode_No) TextBox7.Text = M1_Barcode_No Cnn = New OdbcConnection(ODBCConnstring) Cnn.Open() CmdString = "Select Recipe_ID, Recipe_Name From [Recipe_Table] Where Manifold1 = 1 and Barcode_ID =" & M1_Barcode_No & " ORDER BY Recipe_Name ASC" Cmd = New OdbcCommand(CmdString, Cnn) Ra = Cmd.ExecuteReader() ListBox1.Items.Clear() i = 1 Do While Ra.Read() ListBox1.Items.Add(Ra.Item(1)) ListBox1.ItemHeight = 30 Recipe_ID(i) = Ra.Item(0) i = i + 1 Loop Ra.Close() If ListBox1.Items.Count < 1 Then MessageBox.Show("Can't find any recipes related to Barcode No: " & M1_Barcode_No & "Please try again!!!", "Recipe not found", MessageBoxButtons.OK, MessageBoxIcon.Warning) Exit Sub End If 'Module 2 Barcode Handle Case 2 M2_Barcode_No = OPCDAClient.ReadItemValue("", "ArchestrA.DASSIDirect.3", "Channel1.Device1.DB200,DINT30") Cnn = New OdbcConnection(ODBCConnstring) Cnn.Open() CmdString = "Select Recipe_ID, Recipe_Name From [Recipe_Table] Where Manifold2 = 1 and Barcode_ID =" & M2_Barcode_No & " ORDER BY Recipe_Name ASC" Cmd = New OdbcCommand(CmdString, Cnn) Ra = Cmd.ExecuteReader() ListBox1.Items.Clear() i = 1 Do While Ra.Read() ListBox1.Items.Add(Ra.Item(1)) ListBox1.ItemHeight = 30 Recipe_ID(i) = Ra.Item(0) i = i + 1 Loop Ra.Close() If ListBox1.Items.Count < 1 Then MessageBox.Show("Can't find any recipes related to Barcode No: " & M2_Barcode_No & "Please try again!!!", "Recipe not found", MessageBoxButtons.OK, MessageBoxIcon.Warning) Exit Sub End If 'Module 3 Barcode Handle Case 3 M3_Barcode_No = OPCDAClient.ReadItemValue("", "ArchestrA.DASSIDirect.3", "Channel1.Device1.DB200,DINT34") Cnn = New OdbcConnection(ODBCConnstring) Cnn.Open() CmdString = "Select Recipe_ID, Recipe_Name From [Recipe_Table] Where Manifold3 = 1 and Barcode_ID =" & M3_Barcode_No & " ORDER BY Recipe_Name ASC" Cmd = New OdbcCommand(CmdString, Cnn) Ra = Cmd.ExecuteReader() ListBox1.Items.Clear() i = 1 Do While Ra.Read() ListBox1.Items.Add(Ra.Item(1)) ListBox1.ItemHeight = 30 Recipe_ID(i) = Ra.Item(0) i = i + 1 Loop Ra.Close() If ListBox1.Items.Count < 1 Then MessageBox.Show("Can't find any recipes related to Barcode No: " & M3_Barcode_No & "Please try again!!!", "Recipe not found", MessageBoxButtons.OK, MessageBoxIcon.Warning) Exit Sub End If 'Module 4 Barcode Handle Case 4 M4_Barcode_No = OPCDAClient.ReadItemValue("", "ArchestrA.DASSIDirect.3", "Channel1.Device1.DB200,DINT38") Cnn = New OdbcConnection(ODBCConnstring) Cnn.Open() CmdString = "Select Recipe_ID, Recipe_Name From [Recipe_Table] Where Manifold4 = 1 and Barcode_ID =" & M4_Barcode_No & " ORDER BY Recipe_Name ASC" Cmd = New OdbcCommand(CmdString, Cnn) Ra = Cmd.ExecuteReader() ListBox1.Items.Clear() i = 1 Do While Ra.Read() ListBox1.Items.Add(Ra.Item(1)) ListBox1.ItemHeight = 30 Recipe_ID(i) = Ra.Item(0) i = i + 1 Loop Ra.Close() If ListBox1.Items.Count < 1 Then MessageBox.Show("Can't find any recipes related to Barcode No: " & M4_Barcode_No & "Please try again!!!", "Recipe not found", MessageBoxButtons.OK, MessageBoxIcon.Warning) Exit Sub End If 'Module 5 Barcode Handle Case 5 M5_Barcode_No = OPCDAClient.ReadItemValue("", "ArchestrA.DASSIDirect.3", "Channel1.Device1.DB200,DINT42") Cnn = New OdbcConnection(ODBCConnstring) Cnn.Open() CmdString = "Select Recipe_ID, Recipe_Name From [Recipe_Table] Where Manifold5 = 1 and Barcode_ID =" & M5_Barcode_No & " ORDER BY Recipe_Name ASC" Cmd = New OdbcCommand(CmdString, Cnn) Ra = Cmd.ExecuteReader() ListBox1.Items.Clear() i = 1 Do While Ra.Read() ListBox1.Items.Add(Ra.Item(1)) ListBox1.ItemHeight = 30 Recipe_ID(i) = Ra.Item(0) i = i + 1 Loop Ra.Close() If ListBox1.Items.Count < 1 Then MessageBox.Show("Can't find any recipes related to Barcode No: " & M5_Barcode_No & "Please try again!!!", "Recipe not found", MessageBoxButtons.OK, MessageBoxIcon.Warning) Exit Sub End If 'Module 6 Barcode Handle Case 6 M6_Barcode_No = OPCDAClient.ReadItemValue("", "ArchestrA.DASSIDirect.3", "Channel1.Device1.DB200,DINT46") Cnn = New OdbcConnection(ODBCConnstring) Cnn.Open() CmdString = "Select Recipe_ID, Recipe_Name From [Recipe_Table] Where Manifold6 = 1 and Barcode_ID =" & M6_Barcode_No & " ORDER BY Recipe_Name ASC" Cmd = New OdbcCommand(CmdString, Cnn) Ra = Cmd.ExecuteReader() ListBox1.Items.Clear() i = 1 Do While Ra.Read() ListBox1.Items.Add(Ra.Item(1)) ListBox1.ItemHeight = 30 Recipe_ID(i) = Ra.Item(0) i = i + 1 Loop Ra.Close() If ListBox1.Items.Count < 1 Then MessageBox.Show("Can't find any recipes related to Barcode No: " & M6_Barcode_No & "Please try again!!!", "Recipe not found", MessageBoxButtons.OK, MessageBoxIcon.Warning) Exit Sub End If End Select Else Cnn = New OdbcConnection(ODBCConnstring) Cnn.Open() CmdString = "Select Recipe_ID, Recipe_Name From [Recipe_Table] Where Manifold" & Module_Num.ToString() & " = 1 ORDER BY Recipe_Name ASC" Cmd = New OdbcCommand(CmdString, Cnn) Ra = Cmd.ExecuteReader() i = 1 Do While Ra.Read() ListBox1.Items.Add(Ra.Item(1)) ListBox1.ItemHeight = 30 Recipe_ID(i) = Ra.Item(0) i = i + 1 Loop Ra.Close() End If If ListBox1.Items.Count < 1 Then MessageBox.Show("Can't find any recipes for this Module please consult the Supervisor", "Items not found", MessageBoxButtons.OK, MessageBoxIcon.Warning) Exit Sub End If ListBox1.SelectedIndex = 0 'We now populate the Shift and Operator ComboBoxes from the Database CmdString = "Select Operator_Name From [Operators]" Cmd.CommandText = CmdString Ra = Cmd.ExecuteReader() Do While Ra.Read() ComboBox1.Items.Add(Ra.Item(0)) Loop Ra.Close() CmdString = "Select Batch_Size From [Batch_Sizes]" Cmd.CommandText = CmdString Ra = Cmd.ExecuteReader() Do While Ra.Read() ComboBox3.Items.Add(Ra.Item(0)) Loop Ra.Close() CmdString = "Select Cylinder From [Cylinder_Sizes]" Cmd.CommandText = CmdString Ra = Cmd.ExecuteReader() Do While Ra.Read() ComboBox2.Items.Add(Ra.Item(0)) Loop Ra.Close() CmdString = "Select Shift_Name From [Shift_Data]" Cmd.CommandText = CmdString Ra = Cmd.ExecuteReader() Do While Ra.Read() ComboBox4.Items.Add(Ra.Item(0)) Loop Ra.Close() 'Need to load the pre select the Operator Name, Cylinder Size, Batch Size and Shift with the data from the last run CmdString = "Select Cylinder_Size, Batch_Size, Shift_Name, Operator_Name From [Current_BatchData] where Module_Num = " & Module_Num.ToString Cmd.CommandText = CmdString Ra = Cmd.ExecuteReader() If Ra.Read() Then If ComboBox2.Items.Contains(Ra.Item(0)) Then ComboBox2.SelectedIndex = ComboBox2.Items.IndexOf(Ra.Item(0)) End If If ComboBox3.Items.Contains(Ra.Item(1)) Then ComboBox3.SelectedIndex = ComboBox3.Items.IndexOf(Ra.Item(1)) End If If ComboBox4.Items.Contains(Ra.Item(2)) Then ComboBox4.SelectedIndex = ComboBox4.Items.IndexOf(Ra.Item(2)) End If If ComboBox1.Items.Contains(Ra.Item(3)) Then ComboBox1.SelectedIndex = ComboBox1.Items.IndexOf(Ra.Item(3)) End If End If Ra.Close() ''Now we commect to the Comm Port ''Need to load the pre select the Operator Name, Cylinder Size, Batch Size and Shift with the data from the last run 'CmdString = "Select Config_Value From [Configuration_Data] where Config_Name = 'COM_PORT'" 'Cmd.CommandText = CmdString 'Ra = Cmd.ExecuteReader 'If Ra.Read Then ' SerialPort1.PortName = Ra.Item(0) 'Set SerialPort1 to the selected COM port at startup 'End If 'Ra.Close() 'CmdString = "Select Config_Value From [Configuration_Data] where Config_Name = 'COM_BAUDRATE'" 'Cmd.CommandText = CmdString 'Ra = Cmd.ExecuteReader 'If Ra.Read Then ' SerialPort1.BaudRate = Ra.Item(0) 'Set Baud rate to the selected value on 'End If 'Ra.Close() ''Other Serial Port Property 'SerialPort1.Parity = IO.Ports.Parity.None 'SerialPort1.StopBits = IO.Ports.StopBits.One 'SerialPort1.DataBits = 8 'Open our serial port 'Try ' SerialPort1.Open() 'Catch ex As System.IO.IOException ' MessageBox.Show(SerialPort1.PortName & " could not be opened. Please check the Serial Port settings. Program running without barcode scanning functionality", "Serial Port Exception", MessageBoxButtons.OK, MessageBoxIcon.Error) 'Catch ex As System.Exception ' MessageBox.Show(ex.Message, "System Exception", MessageBoxButtons.OK, MessageBoxIcon.Error) 'End Try SetupOPCLink() Catch ex As System.Data.Odbc.OdbcException MessageBox.Show(ex.Message, "ODBC Exception111", MessageBoxButtons.OK, MessageBoxIcon.Error) Catch ex As System.Exception MessageBox.Show(ex.Message, "System Exception111", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived ReceivedText(SerialPort1.ReadExisting()) 'Automatically called every time a data is received at the serialPort End Sub Private Sub ReceivedText(ByVal [text] As String) 'compares the ID of the creating Thread to the ID of the calling Thread If Me.rtbReceived.InvokeRequired Then Dim x As New SetTextCallback(AddressOf ReceivedText) Me.Invoke(x, New Object() {(text)}) Else Me.rtbReceived.Text &= [text] End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Ra As OdbcDataReader Dim CmdString As String Dim i As Integer = 1 Try CmdString = "Select Recipe_ID, Recipe_Name From [Recipe_Table] Where Manifold" & Module_Num.ToString() & " = 1 ORDER BY Recipe_Name ASC" Cmd.CommandText = CmdString Ra = Cmd.ExecuteReader() ListBox1.Items.Clear() Do While Ra.Read() ListBox1.Items.Add(Ra.Item(1)) ListBox1.ItemHeight = 30 Recipe_ID(i) = Ra.Item(0) i = i + 1 Loop If ListBox1.Items.Count < 1 Then MessageBox.Show("Can't find any recipes for this Module please consult the Supervisor", "Recipes not found", MessageBoxButtons.OK, MessageBoxIcon.Warning) Exit Sub End If ListBox1.SelectedIndex = 0 Ra.Close() Catch ex As System.Data.Odbc.OdbcException MessageBox.Show(ex.Message, "ODBC Exception", MessageBoxButtons.OK, MessageBoxIcon.Error) Catch ex As System.Exception MessageBox.Show(ex.Message, "System Exception", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Try If ListBox1.SelectedIndex >= 10 Then ListBox1.SelectedIndex = ListBox1.SelectedIndex - 10 Else ListBox1.SelectedIndex = 0 End If Catch ex As System.Exception MessageBox.Show(ex.Message, "System Exception", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click Try If ListBox1.SelectedIndex <= ListBox1.Items.Count - 11 Then ListBox1.SelectedIndex = ListBox1.SelectedIndex + 10 Else ListBox1.SelectedIndex = ListBox1.Items.Count - 1 End If Catch ex As System.Exception MessageBox.Show(ex.Message, "System Exception", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Enter) Then Dim Ra As OdbcDataReader Dim CmdString As String Dim i As Integer = 1 Try 'If there is no search data in Textbox then exit sub otherwise it will query all data If TextBox1.Text = "" Then Exit Sub End If CmdString = "Select Recipe_ID, Recipe_Name From dbo.Recipe_Table Where Recipe_Name Like " & " '%" & TextBox1.Text & "%' AND Manifold" & Module_Num & "=1 ORDER BY Recipe_Name ASC" Cmd.CommandText = CmdString Ra = Cmd.ExecuteReader() ListBox1.Items.Clear() Do While Ra.Read() ListBox1.Items.Add(Ra.Item(1)) Recipe_ID(i) = Ra.Item(0) i = i + 1 Loop ' If the SQLStatement query with no data then show the message "Data not found" and Exit Sub If ListBox1.Items.Count < 1 Then MessageBox.Show("Can't find any recipes. Please change your search criteria and try again", "Recipe not found", MessageBoxButtons.OK, MessageBoxIcon.Warning) Ra.Close() Exit Sub End If ListBox1.SelectedIndex = 0 Ra.Close() Catch ex As System.Data.Odbc.OdbcException MessageBox.Show(ex.Message, "ODBC Exception", MessageBoxButtons.OK, MessageBoxIcon.Error) Catch ex As System.Exception MessageBox.Show(ex.Message, "System Exception", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End If End Sub Private Sub TextBox1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseClick Process.Start("C:\Program Files\ComfortKeyboard\CKeyboard.exe") End Sub Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click Dim Ra As OdbcDataReader Dim CmdString As String Dim i As Integer = 1 Try 'If there is no search data in Textbox then exit sub otherwise it will query all data If TextBox1.Text = "" Then Exit Sub End If CmdString = "Select Recipe_ID, Recipe_Name From dbo.Recipe_Table Where Recipe_Name Like " & " '%" & TextBox1.Text & "%' AND Manifold" & Module_Num & "=1 ORDER BY Recipe_Name ASC" Cmd.CommandText = CmdString Ra = Cmd.ExecuteReader() ListBox1.Items.Clear() Do While Ra.Read() ListBox1.Items.Add(Ra.Item(1)) Recipe_ID(i) = Ra.Item(0) i = i + 1 Loop ' If the SQLStatement query with no data then show the message "Data not found" and Exit Sub If ListBox1.Items.Count < 1 Then MessageBox.Show("Can't find any recipes. Please change your search criteria and try again", "Recipe not found", MessageBoxButtons.OK, MessageBoxIcon.Warning) Ra.Close() Exit Sub End If ListBox1.SelectedIndex = 0 Ra.Close() Catch ex As System.Data.Odbc.OdbcException MessageBox.Show(ex.Message, "ODBC Exception", MessageBoxButtons.OK, MessageBoxIcon.Error) Catch ex As System.Exception MessageBox.Show(ex.Message, "System Exception", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub ListBox1_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged 'To show the seleectedIndex in the list box out of total items. Label1.Text = "Item: " & ListBox1.SelectedIndex + 1 & " Of " & ListBox1.Items.Count End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click 'To close every Forms and return memory to the system Me.Close() End Sub Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click Dim Ra As OdbcDataReader Dim CmdString As String If ListBox1.SelectedIndex > -1 Then Try CmdString = "Select Barcode_ID,Recipe_ID, Recipe_Name, Recipe_Description From Recipe_Table where Recipe_Name = '" & ListBox1.Items(ListBox1.SelectedIndex) & "'" Cmd.CommandText = CmdString Ra = Cmd.ExecuteReader() TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" TextBox5.Text = "" Dim i As Integer = 1 Do While Ra.Read() TextBox2.Text = Ra.Item(0) TextBox5.Text = Ra.Item(1) TextBox3.Text = Ra.Item(2) TextBox4.Text = Ra.Item(3) Loop Ra.Close() GenerateBatchNumber() TextBox9.Text = Batch_ID Button9.Enabled = True Catch ex As System.Data.Odbc.OdbcException MessageBox.Show(ex.Message, "ODBC Exception", MessageBoxButtons.OK, MessageBoxIcon.Error) Catch ex As System.Exception MessageBox.Show(ex.Message, "System Exception", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End If End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click Dim Ra As OdbcDataReader Dim CmdString As String Dim SiteName As String Button9.Enabled = False Try 'First need to check that all the variables have been selected prior to downloading If TextBox3.Text.Length < 2 Then MessageBox.Show("A recipe has not been selected yet. Please select a recipe prior to dowloading the recipe to the PLC", "PLC Download cannot be executed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Exit Sub End If If ComboBox1.SelectedIndex < 0 Then MessageBox.Show("A Operator Name has not been selected yet. Please select an Operator prior to dowloading the recipe to the PLC", "PLC Download cannot be executed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Exit Sub End If If ComboBox2.SelectedIndex < 0 Then MessageBox.Show("A Cylinder Size has not been selected yet. Please select a Cylinder Size prior to dowloading the recipe to the PLC", "PLC Download cannot be executed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Exit Sub End If If ComboBox3.SelectedIndex < 0 Then MessageBox.Show("A Batch Size has not been selected yet. Please select a Batch Size prior to dowloading the recipe to the PLC", "PLC Download cannot be executed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Exit Sub End If If ComboBox4.SelectedIndex < 0 Then MessageBox.Show("The Shift has not been selected yet. Please select a Shift prior to dowloading the recipe to the PLC", "PLC Download cannot be executed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Exit Sub End If 'Now the data can be downloaded to the PLC Me.Hide() 'AM1 'If WriteBatchToPLC() Then ' 'Current Batch data is updated/recorded in the database ' CmdString = "Select Module_Num From [Current_BatchData] where Module_Num = " & Module_Num.ToString ' Cmd.CommandText = CmdString ' Ra = Cmd.ExecuteReader() ' If Ra.Read() Then ' Ra.Close() ' 'There is data in the table so the row entry has to be updated ' CmdString = "UPDATE [Current_BatchData] SET [Batch_ID] = '" & Batch_ID & "', [Recipe_ID] = " & TextBox5.Text & ", [Recipe_Name] = '" & TextBox3.Text & "', [Cylinder_Size] = '" & ComboBox2.SelectedItem.ToString & "', " ' CmdString = CmdString & "[Batch_Size] = " & ComboBox3.SelectedItem.ToString & ", [Shift_Name] = '" & ComboBox4.SelectedItem.ToString & "', [Operator_Name] = '" & ComboBox1.SelectedItem.ToString & "', " ' CmdString = CmdString & "[Start_Time] = GetDate() WHERE Module_Num = " & Module_Num ' Cmd.CommandText = CmdString ' Cmd.ExecuteNonQuery() ' Else ' Ra.Close() ' 'There is no data in the table so a new row has to be added ' 'Note this will only ever occur once!! ' CmdString = "INSERT INTO [Current_BatchData] ([Module_Num],[Batch_ID],[Recipe_ID],[Recipe_Name],[Cylinder_Size],[Batch_Size],[Shift_Name],[Operator_Name],[Start_Time]) VALUES (" ' CmdString = CmdString & Module_Num.ToString & ", '" & Batch_ID & "', " & TextBox5.Text & ", '" & TextBox3.Text & "', '" & ComboBox2.SelectedItem.ToString & "', " & ComboBox3.SelectedItem.ToString ' CmdString = CmdString & ", '" & ComboBox4.SelectedItem.ToString & "', '" & ComboBox1.SelectedItem.ToString & "', GetDate() )" ' Cmd.CommandText = CmdString ' Cmd.ExecuteNonQuery() ' End If ' 'Batch Data is recorded in the report log ' 'First we have to retrieve the Site Name from the database and write it to the report file ' CmdString = "Select [Config_Value] from [Configuration_Data] where [Config_Name] = 'Site'" ' Cmd.CommandText = CmdString ' Ra = Cmd.ExecuteReader() ' If Ra.Read() Then ' SiteName = Ra.Item(0) ' Else ' SiteName = "Unknown" ' End If ' Ra.Close() ' CmdString = "INSERT INTO [Module_Batch_Log] ([Module], [Batch_ID], [Report_String]) VALUES (" & Module_Num & ", '" & Batch_ID & "', 'Site: " & SiteName & "')" ' Cmd.CommandText = CmdString ' Cmd.ExecuteNonQuery() ' 'Second need to record the date to the report ' CmdString = "INSERT INTO [Module_Batch_Log] ([Module], [Batch_ID], [Report_String]) VALUES (" & Module_Num & ", '" & Batch_ID & "', 'Date: " & Now.ToString("dd-MM-yy hh:mm:ss tt") & "')" ' Cmd.CommandText = CmdString ' Cmd.ExecuteNonQuery() ' 'Third need to record the operator name to the report ' CmdString = "INSERT INTO [Module_Batch_Log] ([Module], [Batch_ID], [Report_String]) VALUES (" & Module_Num & ", '" & Batch_ID & "', 'Operator: " & ComboBox1.SelectedItem.ToString & "')" ' Cmd.CommandText = CmdString ' Cmd.ExecuteNonQuery() ' 'Fourth need to record the recipe name ' CmdString = "INSERT INTO [Module_Batch_Log] ([Module], [Batch_ID], [Report_String]) VALUES (" & Module_Num & ", '" & Batch_ID & "', 'Recipe: " & TextBox3.Text & "')" ' Cmd.CommandText = CmdString ' Cmd.ExecuteNonQuery() ' 'Fifth need to record the barcode ' If TextBox2.Text.Length < 2 Then ' CmdString = "INSERT INTO [Module_Batch_Log] ([Module], [Batch_ID], [Report_String]) VALUES (" & Module_Num & ", '" & Batch_ID & "', 'Barcode: Unknown')" ' Else ' CmdString = "INSERT INTO [Module_Batch_Log] ([Module], [Batch_ID], [Report_String]) VALUES (" & Module_Num & ", '" & Batch_ID & "', 'Barcode: " & TextBox2.Text & "')" ' End If ' Cmd.CommandText = CmdString ' Cmd.ExecuteNonQuery() ' 'Sixth need to record cylinder size ' CmdString = "INSERT INTO [Module_Batch_Log] ([Module], [Batch_ID], [Report_String]) VALUES (" & Module_Num & ", '" & Batch_ID & "', 'Cylinder Size: " & ComboBox2.SelectedItem.ToString & "')" ' Cmd.CommandText = CmdString ' Cmd.ExecuteNonQuery() ' 'Seventh need to record the batch size ' CmdString = "INSERT INTO [Module_Batch_Log] ([Module], [Batch_ID], [Report_String]) VALUES (" & Module_Num & ", '" & Batch_ID & "', 'Batch Size: " & ComboBox3.SelectedItem.ToString & "')" ' Cmd.CommandText = CmdString ' Cmd.ExecuteNonQuery() ' 'Eigth the Module Number ' CmdString = "INSERT INTO [Module_Batch_Log] ([Module], [Batch_ID], [Report_String]) VALUES (" & Module_Num & ", '" & Batch_ID & "', 'Module: " & Module_Num.ToString & "')" ' Cmd.CommandText = CmdString ' Cmd.ExecuteNonQuery() ' 'Ninth the batch ID ' CmdString = "INSERT INTO [Module_Batch_Log] ([Module], [Batch_ID], [Report_String]) VALUES (" & Module_Num & ", '" & Batch_ID & "', 'Batch ID: " & Batch_ID & "')" ' Cmd.CommandText = CmdString ' Cmd.ExecuteNonQuery() ' 'Tenth the Shift ' CmdString = "INSERT INTO [Module_Batch_Log] ([Module], [Batch_ID], [Report_String]) VALUES (" & Module_Num & ", '" & Batch_ID & "', 'Shift: " & ComboBox4.SelectedItem.ToString & "')" ' Cmd.CommandText = CmdString ' Cmd.ExecuteNonQuery() ' Me.Close() 'Else ' MessageBox.Show("Errors occurred while downloading the Recipe to the PLC. Please consult your supervisor", "Recipe Download Failed", MessageBoxButtons.OK, MessageBoxIcon.Error) ' Button9.Enabled = True 'End If 'Current Batch data is updated/recorded in the database CmdString = "Select Module_Num From [Current_BatchData] where Module_Num = " & Module_Num.ToString Cmd.CommandText = CmdString Ra = Cmd.ExecuteReader() If Ra.Read() Then Ra.Close() 'There is data in the table so the row entry has to be updated CmdString = "UPDATE [Current_BatchData] SET [Batch_ID] = '" & Batch_ID & "', [Recipe_ID] = " & TextBox5.Text & ", [Recipe_Name] = '" & TextBox3.Text & "', [Cylinder_Size] = '" & ComboBox2.SelectedItem.ToString & "', " CmdString = CmdString & "[Batch_Size] = " & ComboBox3.SelectedItem.ToString & ", [Shift_Name] = '" & ComboBox4.SelectedItem.ToString & "', [Operator_Name] = '" & ComboBox1.SelectedItem.ToString & "', " CmdString = CmdString & "[Start_Time] = GetDate() WHERE Module_Num = " & Module_Num Cmd.CommandText = CmdString Cmd.ExecuteNonQuery() Else Ra.Close() 'There is no data in the table so a new row has to be added 'Note this will only ever occur once!! CmdString = "INSERT INTO [Current_BatchData] ([Module_Num],[Batch_ID],[Recipe_ID],[Recipe_Name],[Cylinder_Size],[Batch_Size],[Shift_Name],[Operator_Name],[Start_Time]) VALUES (" CmdString = CmdString & Module_Num.ToString & ", '" & Batch_ID & "', " & TextBox5.Text & ", '" & TextBox3.Text & "', '" & ComboBox2.SelectedItem.ToString & "', " & ComboBox3.SelectedItem.ToString CmdString = CmdString & ", '" & ComboBox4.SelectedItem.ToString & "', '" & ComboBox1.SelectedItem.ToString & "', GetDate() )" Cmd.CommandText = CmdString Cmd.ExecuteNonQuery() End If 'Batch Data is recorded in the report log 'First we have to retrieve the Site Name from the database and write it to the report file CmdString = "Select [Config_Value] from [Configuration_Data] where [Config_Name] = 'Site'" Cmd.CommandText = CmdString Ra = Cmd.ExecuteReader() If Ra.Read() Then SiteName = Ra.Item(0) Else SiteName = "Unknown" End If Ra.Close() CmdString = "INSERT INTO [Module_Batch_Log] ([Module], [Batch_ID], [Report_String]) VALUES (" & Module_Num & ", '" & Batch_ID & "', 'Site: " & SiteName & "')" Cmd.CommandText = CmdString Cmd.ExecuteNonQuery() 'Second need to record the date to the report CmdString = "INSERT INTO [Module_Batch_Log] ([Module], [Batch_ID], [Report_String]) VALUES (" & Module_Num & ", '" & Batch_ID & "', 'Date: " & Now.ToString("dd-MM-yy hh:mm:ss tt") & "')" Cmd.CommandText = CmdString Cmd.ExecuteNonQuery() 'Third need to record the operator name to the report CmdString = "INSERT INTO [Module_Batch_Log] ([Module], [Batch_ID], [Report_String]) VALUES (" & Module_Num & ", '" & Batch_ID & "', 'Operator: " & ComboBox1.SelectedItem.ToString & "')" Cmd.CommandText = CmdString Cmd.ExecuteNonQuery() 'Fourth need to record the recipe name CmdString = "INSERT INTO [Module_Batch_Log] ([Module], [Batch_ID], [Report_String]) VALUES (" & Module_Num & ", '" & Batch_ID & "', 'Recipe: " & TextBox3.Text & "')" Cmd.CommandText = CmdString Cmd.ExecuteNonQuery() 'Fifth need to record the barcode If TextBox2.Text.Length < 2 Then CmdString = "INSERT INTO [Module_Batch_Log] ([Module], [Batch_ID], [Report_String]) VALUES (" & Module_Num & ", '" & Batch_ID & "', 'Barcode: Unknown')" Else CmdString = "INSERT INTO [Module_Batch_Log] ([Module], [Batch_ID], [Report_String]) VALUES (" & Module_Num & ", '" & Batch_ID & "', 'Barcode: " & TextBox2.Text & "')" End If Cmd.CommandText = CmdString Cmd.ExecuteNonQuery() 'Sixth need to record cylinder size CmdString = "INSERT INTO [Module_Batch_Log] ([Module], [Batch_ID], [Report_String]) VALUES (" & Module_Num & ", '" & Batch_ID & "', 'Cylinder Size: " & ComboBox2.SelectedItem.ToString & "')" Cmd.CommandText = CmdString Cmd.ExecuteNonQuery() 'Seventh need to record the batch size CmdString = "INSERT INTO [Module_Batch_Log] ([Module], [Batch_ID], [Report_String]) VALUES (" & Module_Num & ", '" & Batch_ID & "', 'Batch Size: " & ComboBox3.SelectedItem.ToString & "')" Cmd.CommandText = CmdString Cmd.ExecuteNonQuery() 'Eigth the Module Number CmdString = "INSERT INTO [Module_Batch_Log] ([Module], [Batch_ID], [Report_String]) VALUES (" & Module_Num & ", '" & Batch_ID & "', 'Module: " & Module_Num.ToString & "')" Cmd.CommandText = CmdString Cmd.ExecuteNonQuery() 'Ninth the batch ID CmdString = "INSERT INTO [Module_Batch_Log] ([Module], [Batch_ID], [Report_String]) VALUES (" & Module_Num & ", '" & Batch_ID & "', 'Batch ID: " & Batch_ID & "')" Cmd.CommandText = CmdString Cmd.ExecuteNonQuery() 'Tenth the Shift CmdString = "INSERT INTO [Module_Batch_Log] ([Module], [Batch_ID], [Report_String]) VALUES (" & Module_Num & ", '" & Batch_ID & "', 'Shift: " & ComboBox4.SelectedItem.ToString & "')" Cmd.CommandText = CmdString Cmd.ExecuteNonQuery() Me.Close() If WriteBatchToPLC() Then Exit Sub Else MessageBox.Show("Errors occurred while downloading the Recipe to the PLC. Please consult your supervisor", "Recipe Download Failed", MessageBoxButtons.OK, MessageBoxIcon.Error) Button9.Enabled = True End If Catch ex As System.Data.Odbc.OdbcException MessageBox.Show(ex.Message, "ODBC Exceptionpor", MessageBoxButtons.OK, MessageBoxIcon.Error) Button9.Enabled = True Catch ex As System.Exception MessageBox.Show(ex.Message, "System Exceptionpor", MessageBoxButtons.OK, MessageBoxIcon.Error) Button9.Enabled = True End Try End Sub Private Sub Button7_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Try If ListBox1.SelectedIndex >= 1 Then ListBox1.SelectedIndex = ListBox1.SelectedIndex - 1 Else ListBox1.SelectedIndex = 0 End If Catch ex As System.Exception MessageBox.Show(ex.Message, "System Exception", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub Button8_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click Try If ListBox1.SelectedIndex <= ListBox1.Items.Count - 2 Then ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1 Else ListBox1.SelectedIndex = ListBox1.Items.Count - 1 End If Catch ex As System.Exception MessageBox.Show(ex.Message, "System Exception", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub GenerateBatchNumber() Dim Ra As OdbcDataReader Dim MB_Num As Integer Dim Old_Batch_ID As String Dim CmdString As String Try CmdString = "Select Batch_ID From [Current_BatchData] where Module_Num = " & Module_Num.ToString Cmd = New OdbcCommand(CmdString, Cnn) Ra = Cmd.ExecuteReader() If Ra.Read() Then 'What we do here is first check the data 'If the date matches then the number at the end only has to be incremented. 'If the date does not match we need to create the batch ID with a new data and start at 1 Old_Batch_ID = Ra.Item(0) MB_Num = Int32.Parse(Old_Batch_ID.Substring(3)) + 1 BatchNum = MB_Num Batch_ID = "M" & Module_Num & "_" If MB_Num < 10 Then Batch_ID = Batch_ID & "000000" & MB_Num Else If MB_Num < 100 Then Batch_ID = Batch_ID & "00000" & MB_Num Else If MB_Num < 1000 Then Batch_ID = Batch_ID & "0000" & MB_Num Else If MB_Num < 10000 Then Batch_ID = Batch_ID & "000" & MB_Num Else If MB_Num < 100000 Then Batch_ID = Batch_ID & "00" & MB_Num Else If MB_Num < 1000000 Then Batch_ID = Batch_ID & "0" & MB_Num Else Batch_ID = Batch_ID & MB_Num End If End If End If End If End If End If Else 'What we need to do here is create a new batch ID at the table is empty Batch_ID = "M" & Module_Num & "_0000001" BatchNum = 1 End If Ra.Close() Catch ex As System.Data.Odbc.OdbcException MessageBox.Show(ex.Message, "ODBC Exception", MessageBoxButtons.OK, MessageBoxIcon.Error) Catch ex As System.Exception MessageBox.Show(ex.Message, "System Exception", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub SetupOPCLink() Dim OPCModuleTag As String Dim Param(74) As Integer Dim Offset As Integer Dim wrtOffset As Integer Dim i As Integer Try OPCDAClient = New EasyDAClient OPCDAClient.ClientMode.AllowAsynchronousMethod = True 'When True, Async reads and write are allowed OPCDAClient.ClientMode.AllowSynchronousMethod = True 'When True, Sync reads and writes are allowed OPCDAClient.ClientMode.DesiredMethod = 1 'Determines if reads and writes are done async (1) or sync (2). Offset = 0 Param(0) = 0 Param(1) = 2 Param(2) = 2 Param(3) = 2 Param(4) = 2 Param(5) = 2 Param(6) = 2 Param(7) = 2 Param(8) = 2 Param(9) = 3 Param(10) = 3 Param(11) = 3 Param(12) = 3 Param(13) = 3 Param(14) = 3 Param(15) = 3 Param(16) = 3 Param(17) = 4 Param(18) = 6 Param(19) = 8 Param(20) = 10 Param(21) = 12 Param(22) = 14 Param(23) = 16 Param(24) = 18 Param(25) = 20 Param(26) = 22 Param(27) = 24 Param(28) = 26 Param(29) = 28 Param(30) = 30 Param(31) = 32 Param(32) = 34 Param(33) = 36 Param(34) = 38 Param(35) = 40 Param(36) = 42 Param(37) = 44 Param(38) = 46 Param(39) = 48 Param(40) = 50 Param(41) = 52 Param(42) = 54 Param(43) = 56 Param(44) = 58 Param(45) = 60 Param(46) = 64 Param(47) = 68 Param(48) = 72 Param(49) = 76 Param(50) = 80 Param(51) = 84 Param(52) = 88 Param(53) = 92 Param(54) = 96 Param(55) = 100 Param(56) = 104 Param(57) = 108 Param(58) = 112 Param(59) = 116 Param(60) = 120 Param(61) = 124 Param(62) = 128 Param(63) = 132 Param(64) = 136 Param(65) = 140 Param(66) = 144 Param(67) = 148 Param(68) = 152 Param(69) = 156 Param(70) = 160 Param(71) = 164 Param(72) = 168 Param(73) = 172 Param(74) = 176 OPCModuleTag = OPCTagPrefix & "DB101," i = NumProcs * 75 Select Case Module_Num Case 1 OPCModuleTag = OPCTagPrefix & "DB101," writeItems(i) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCTagPrefix & "MX56.0", 1) 'Start Request writeItems(i + 1) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCTagPrefix & "DB7,INT274", TextBox5.Text) 'Recipe ID writeItems(i + 2) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCTagPrefix & "DB200,DINT0", BatchNum) 'Batch Number Case 2 OPCModuleTag = OPCTagPrefix & "DB102," writeItems(i) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCTagPrefix & "MX56.1", 1) 'Start Request writeItems(i + 1) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCTagPrefix & "DB7,INT338", TextBox5.Text) 'Recipe ID writeItems(i + 2) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCTagPrefix & "DB200,DINT4", BatchNum) 'Batch Number Case 3 OPCModuleTag = OPCTagPrefix & "DB103," writeItems(i) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCTagPrefix & "MX56.2", 1) 'Start Request writeItems(i + 1) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCTagPrefix & "DB7,INT362", TextBox5.Text) 'Recipe ID writeItems(i + 2) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCTagPrefix & "DB200,DINT8", BatchNum) 'Batch Number Case 4 OPCModuleTag = OPCTagPrefix & "DB104," writeItems(i) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCTagPrefix & "MX56.3", 1) 'Start Request writeItems(i + 1) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCTagPrefix & "DB7,INT386", TextBox5.Text) 'Recipe ID writeItems(i + 2) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCTagPrefix & "DB200,DINT12", BatchNum) 'Batch Number Case 5 OPCModuleTag = OPCTagPrefix & "DB105," writeItems(i) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCTagPrefix & "MX56.4", 1) 'Start Request writeItems(i + 1) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCTagPrefix & "DB7,INT410", TextBox5.Text) 'Recipe ID writeItems(i + 2) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCTagPrefix & "DB200,DINT16", BatchNum) 'Batch Number Case 6 OPCModuleTag = OPCTagPrefix & "DB106," writeItems(i) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCTagPrefix & "MX56.5", 1) 'Start Request writeItems(i + 1) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCTagPrefix & "DB7,INT434", TextBox5.Text) 'Recipe ID writeItems(i + 2) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCTagPrefix & "DB200,DINT20", BatchNum) 'Batch Number End Select wrtOffset = 0 Offset = 0 i = 0 For i = 0 To (NumProcs - 1) Step 1 writeItems(wrtOffset + 0) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(0) + Offset), ProcData(i, 0)) 'INT0 writeItems(wrtOffset + 1) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "X" & CStr(Param(1) + Offset) & ".0", ProcData(i, 1)) 'INTX2.0 writeItems(wrtOffset + 2) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "X" & CStr(Param(2) + Offset) & ".1", ProcData(i, 2)) 'X2.1 writeItems(wrtOffset + 3) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "X" & CStr(Param(3) + Offset) & ".2", ProcData(i, 3)) 'X2.2 writeItems(wrtOffset + 4) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "X" & CStr(Param(4) + Offset) & ".3", ProcData(i, 4)) 'X2.3 writeItems(wrtOffset + 5) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "X" & CStr(Param(5) + Offset) & ".4", ProcData(i, 5)) 'X2.4 writeItems(wrtOffset + 6) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "X" & CStr(Param(6) + Offset) & ".5", ProcData(i, 6)) 'X2.5 writeItems(wrtOffset + 7) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "X" & CStr(Param(7) + Offset) & ".6", ProcData(i, 7)) 'X2.6 writeItems(wrtOffset + 8) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "X" & CStr(Param(8) + Offset) & ".7", ProcData(i, 8)) 'X2.7 writeItems(wrtOffset + 9) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "X" & CStr(Param(9) + Offset) & ".0", ProcData(i, 9)) 'X3.0 writeItems(wrtOffset + 10) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "X" & CStr(Param(10) + Offset) & ".1", ProcData(i, 10)) 'X3.1 writeItems(wrtOffset + 11) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "X" & CStr(Param(11) + Offset) & ".2", ProcData(i, 11)) 'X3.2 writeItems(wrtOffset + 12) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "X" & CStr(Param(12) + Offset) & ".3", ProcData(i, 12)) 'X3.3 writeItems(wrtOffset + 13) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "X" & CStr(Param(13) + Offset) & ".4", ProcData(i, 13)) 'X3.4 writeItems(wrtOffset + 14) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "X" & CStr(Param(14) + Offset) & ".5", ProcData(i, 14)) 'X3.5 writeItems(wrtOffset + 15) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "X" & CStr(Param(15) + Offset) & ".6", ProcData(i, 15)) 'X3.6 writeItems(wrtOffset + 16) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "X" & CStr(Param(16) + Offset) & ".7", ProcData(i, 16)) 'X3.7 writeItems(wrtOffset + 17) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(17) + Offset), ProcData(i, 17)) 'INT4 writeItems(wrtOffset + 18) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(18) + Offset), ProcData(i, 18)) 'INT6 writeItems(wrtOffset + 19) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(19) + Offset), ProcData(i, 19)) 'INT8 writeItems(wrtOffset + 20) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(20) + Offset), ProcData(i, 20)) 'INT10 writeItems(wrtOffset + 21) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(21) + Offset), ProcData(i, 21)) 'INT12 writeItems(wrtOffset + 22) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(22) + Offset), ProcData(i, 22)) 'INT14 writeItems(wrtOffset + 23) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(23) + Offset), ProcData(i, 23)) 'INT16 writeItems(wrtOffset + 24) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(24) + Offset), ProcData(i, 24)) 'INT18 writeItems(wrtOffset + 25) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(25) + Offset), ProcData(i, 25)) 'INT20 writeItems(wrtOffset + 26) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(26) + Offset), ProcData(i, 26)) 'INT22 writeItems(wrtOffset + 27) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(27) + Offset), ProcData(i, 27)) 'INT24 writeItems(wrtOffset + 28) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(28) + Offset), ProcData(i, 28)) 'INT26 writeItems(wrtOffset + 29) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(29) + Offset), ProcData(i, 29)) 'INT28 writeItems(wrtOffset + 30) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(30) + Offset), ProcData(i, 30)) 'INT30 writeItems(wrtOffset + 31) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(31) + Offset), ProcData(i, 31)) 'INT32 writeItems(wrtOffset + 32) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(32) + Offset), ProcData(i, 32)) 'INT34 writeItems(wrtOffset + 33) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(33) + Offset), ProcData(i, 33)) 'INT36 writeItems(wrtOffset + 34) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(34) + Offset), ProcData(i, 34)) 'INT38 writeItems(wrtOffset + 35) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(35) + Offset), ProcData(i, 35)) 'INT40 writeItems(wrtOffset + 36) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(36) + Offset), ProcData(i, 36)) 'INT42 writeItems(wrtOffset + 37) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(37) + Offset), ProcData(i, 37)) 'INT44 writeItems(wrtOffset + 38) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(38) + Offset), ProcData(i, 38)) 'INT46 writeItems(wrtOffset + 39) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(39) + Offset), ProcData(i, 39)) 'INT48 writeItems(wrtOffset + 40) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(40) + Offset), ProcData(i, 40)) 'INT50 writeItems(wrtOffset + 41) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(41) + Offset), ProcData(i, 41)) 'INT52 writeItems(wrtOffset + 42) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(42) + Offset), ProcData(i, 42)) 'INT54 writeItems(wrtOffset + 43) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(43) + Offset), ProcData(i, 43)) 'INT56 writeItems(wrtOffset + 44) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "INT" & CStr(Param(44) + Offset), ProcData(i, 44)) 'INT58 writeItems(wrtOffset + 45) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(45) + Offset), ProcData(i, 45)) 'REAL60 writeItems(wrtOffset + 46) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(46) + Offset), ProcData(i, 46)) 'REAL64 writeItems(wrtOffset + 47) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(47) + Offset), ProcData(i, 47)) 'REAL68 writeItems(wrtOffset + 48) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(48) + Offset), ProcData(i, 48)) 'REAL72 writeItems(wrtOffset + 49) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(49) + Offset), ProcData(i, 49)) 'REAL76 writeItems(wrtOffset + 50) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(50) + Offset), ProcData(i, 50)) 'REAL80 writeItems(wrtOffset + 51) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(51) + Offset), ProcData(i, 51)) 'REAL84 writeItems(wrtOffset + 52) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(52) + Offset), ProcData(i, 52)) 'REAL88 writeItems(wrtOffset + 53) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(53) + Offset), ProcData(i, 53)) 'REAL92 writeItems(wrtOffset + 54) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(54) + Offset), ProcData(i, 54)) 'REAL96 writeItems(wrtOffset + 55) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(55) + Offset), ProcData(i, 55)) 'REAL100 writeItems(wrtOffset + 56) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(56) + Offset), ProcData(i, 56)) 'REAL104 writeItems(wrtOffset + 57) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(57) + Offset), ProcData(i, 57)) 'REAL108 writeItems(wrtOffset + 58) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(58) + Offset), ProcData(i, 58)) 'REAL112 writeItems(wrtOffset + 59) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(59) + Offset), ProcData(i, 59)) 'REAL116 writeItems(wrtOffset + 60) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(60) + Offset), ProcData(i, 60)) 'REAL120 writeItems(wrtOffset + 61) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(61) + Offset), ProcData(i, 61)) 'REAL124 writeItems(wrtOffset + 62) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(62) + Offset), ProcData(i, 62)) 'REAL128 writeItems(wrtOffset + 63) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(63) + Offset), ProcData(i, 63)) 'REAL132 writeItems(wrtOffset + 64) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(64) + Offset), ProcData(i, 64)) 'REAL136 writeItems(wrtOffset + 65) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(65) + Offset), ProcData(i, 65)) 'REAL140 writeItems(wrtOffset + 66) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(66) + Offset), ProcData(i, 66)) 'REAL144 writeItems(wrtOffset + 67) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(67) + Offset), ProcData(i, 67)) 'REAL148 writeItems(wrtOffset + 68) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(68) + Offset), ProcData(i, 68)) 'REAL152 writeItems(wrtOffset + 69) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(69) + Offset), ProcData(i, 69)) 'REAL156 writeItems(wrtOffset + 70) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(70) + Offset), ProcData(i, 70)) 'REAL160 writeItems(wrtOffset + 71) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(71) + Offset), ProcData(i, 71)) 'REAL164 writeItems(wrtOffset + 72) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(72) + Offset), ProcData(i, 72)) 'REAL168 writeItems(wrtOffset + 73) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(73) + Offset), ProcData(i, 73)) 'REAL172 writeItems(wrtOffset + 74) = New OpcLabs.EasyOpc.DataAccess.DAItemValueArguments(OPCSVR, OPCSVRNAME, OPCModuleTag & "REAL" & CStr(Param(74) + Offset), ProcData(i, 74)) 'REAL176 wrtOffset = wrtOffset + 75 Offset = Offset + 180 Next Catch ex As System.Exception MessageBox.Show(ex.Message, "System Exception", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Function WriteBatchToPLC() As Boolean 'Recipe is downloaded to the PLC Dim Ra As OdbcDataReader Dim CmdString As String Dim HasRows As Boolean Dim i As Integer = 1 Dim RowNum As Integer = 0 Dim strWriteValue As New System.Text.StringBuilder Dim writeError As Boolean = False Try CmdString = "Select [Proc_Param_0], " _ & "[Proc_Param_1_0], " _ & "[Proc_Param_1_1], " _ & "[Proc_Param_1_2], " _ & "[Proc_Param_1_3], " _ & "[Proc_Param_1_4], " _ & "[Proc_Param_1_5], " _ & "[Proc_Param_1_6], " _ & "[Proc_Param_1_7], " _ & "[Proc_Param_1_8], " _ & "[Proc_Param_1_9], " _ & "[Proc_Param_1_10], " _ & "[Proc_Param_1_11], " _ & "[Proc_Param_1_12], " _ & "[Proc_Param_1_13], " _ & "[Proc_Param_1_14], " _ & "[Proc_Param_1_15], " _ & "[Proc_Param_2], " _ & "[Proc_Param_3], " _ & "[Proc_Param_4], " _ & "[Proc_Param_5], " _ & "[Proc_Param_6], " _ & "[Proc_Param_7], " _ & "[Proc_Param_8], " _ & "[Proc_Param_9], " _ & "[Proc_Param_10], " _ & "[Proc_Param_11], " _ & "[Proc_Param_12], " _ & "[Proc_Param_13], " _ & "[Proc_Param_14], " _ & "[Proc_Param_15], " _ & "[Proc_Param_16], " _ & "[Proc_Param_17], " _ & "[Proc_Param_18], " _ & "[Proc_Param_19], " _ & "[Proc_Param_20], " _ & "[Proc_Param_21], " _ & "[Proc_Param_22], " _ & "[Proc_Param_23], " _ & "[Proc_Param_24], " _ & "[Proc_Param_25], " _ & "[Proc_Param_26], " _ & "[Proc_Param_27], " _ & "[Proc_Param_28], " _ & "[Proc_Param_29], " _ & "[Proc_Param_30], " _ & "[Proc_Param_31], " _ & "[Proc_Param_32], " _ & "[Proc_Param_33], " _ & "[Proc_Param_34], " _ & "[Proc_Param_35], " _ & "[Proc_Param_36], " _ & "[Proc_Param_37], " _ & "[Proc_Param_38], " _ & "[Proc_Param_39], " _ & "[Proc_Param_40], " _ & "[Proc_Param_41], " _ & "[Proc_Param_42], " _ & "[Proc_Param_43], " _ & "[Proc_Param_44], " _ & "[Proc_Param_45], " _ & "[Proc_Param_46], " _ & "[Proc_Param_47], " _ & "[Proc_Param_48], " _ & "[Proc_Param_49], " _ & "[Proc_Param_50], " _ & "[Proc_Param_51], " _ & "[Proc_Param_52], " _ & "[Proc_Param_53], " _ & "[Proc_Param_54], " _ & "[Proc_Param_55], " _ & "[Proc_Param_56], " _ & "[Proc_Param_57], " _ & "[Proc_Param_58], " _ & "[Proc_Param_59], " _ & "[Proc_Position], " _ & "[Recipe_ID] " _ & "From Procedure_Table Where [Recipe_ID] = " & TextBox5.Text & " Order By [Proc_Position]" Cmd.CommandText = CmdString Ra = Cmd.ExecuteReader() HasRows = Ra.HasRows If HasRows = False Then MessageBox.Show("There are no procedures in the recipe. Data not downloaded to the PLC", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) Return False End If Do While Ra.Read() For i = 0 To 74 Step 1 ProcData(RowNum, i) = Ra.Item(i) writeItems((RowNum * 75) + i).Value = ProcData(RowNum, i) Next RowNum = RowNum + 1 Loop Ra.Close() 'Now we set the start command and the Recipe ID and Batch Number which are downloaded to the PLC i = NumProcs * 75 'AM1 Changed from 75 to 1 writeItems(i).Value = 1 writeItems(i + 1).Value = CInt(TextBox5.Text) writeItems(i + 2).Value = BatchNum If RowNum <> NumProcs Then MessageBox.Show("Recipe no corectly configured in the database. Please consult your Supervisor", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) Return False End If writeResults = OPCDAClient.WriteMultipleItemValues(writeItems) If Not writeResults Is Nothing Then 'iterate through the array For i = LBound(writeResults) To UBound(writeResults) If writeResults(i).Succeeded Then 'append our message with a "success" strWriteValue.Append("Element " & i & ": success") Else strWriteValue.Append(writeResults(i).ErrorCode & ": " & writeResults(i).ErrorMessage) writeError = True End If 'add a carriage-return + linefeed to the message strWriteValue.Append(vbCrLf) Next End If If writeError Then Return False End If Return True Catch ex As System.Data.Odbc.OdbcException MessageBox.Show(ex.Message, "ODBC Exception1", MessageBoxButtons.OK, MessageBoxIcon.Error) Return False Catch ex As System.Exception MessageBox.Show(ex.Message, "System Exception1", MessageBoxButtons.OK, MessageBoxIcon.Error) Return False End Try End Function Private Sub rtbReceived_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rtbReceived.TextChanged 'Now need to query the database and update the screen Dim Ra As OdbcDataReader Dim Barcode As String Dim Barcode_ID As Integer Dim CmdString As String Dim i As Integer = 1 'Need to get some complete sample data Try If rtbReceived.Text.Contains(vbCrLf) Or rtbReceived.Text.Contains(vbCr) Or rtbReceived.Text.Contains(vbLf) Then Barcode = rtbReceived.Text rtbReceived.Text = "" If IsNumeric(Barcode) Then CmdString = "Select Barcode_No from [Barcode_Table] where Barcode_Value = " & Barcode Cmd.CommandText = CmdString Ra = Cmd.ExecuteReader() If Ra.Read() Then Barcode_ID = Ra.Item(0) Else MessageBox.Show("Can't find the Barcode", "Barcode is not found", MessageBoxButtons.OK, MessageBoxIcon.Warning) Exit Sub End If CmdString = "Select Barcode_ID,Recipe_ID, Recipe_Name, Recipe_Description From Recipe_Table where Barcode_ID = " & Barcode_ID.ToString & "AND Manifold" & Module_Num.ToString() & " = 1" ListBox1.Items.Clear() Do While Ra.Read() ListBox1.Items.Add(Ra.Item(1)) Recipe_ID(i) = Ra.Item(0) i = i + 1 Loop TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" TextBox5.Text = "" Batch_ID = "" TextBox9.Text = Batch_ID Ra.Close() ' If the SQLStatement query with no data then show the message "Data not found" and Exit Sub If ListBox1.Items.Count < 1 Then MessageBox.Show("Can't find any recipes for the Barcode", "Barcode is not found", MessageBoxButtons.OK, MessageBoxIcon.Warning) Exit Sub End If ListBox1.SelectedIndex = 0 End If End If Catch ex As System.Data.Odbc.OdbcException MessageBox.Show(ex.Message, "ODBC Exception", MessageBoxButtons.OK, MessageBoxIcon.Error) Catch ex As System.Exception MessageBox.Show(ex.Message, "System Exception", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub GroupBox3_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox3.Enter End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) End Sub Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim CmdString As String Dim Ra As OdbcDataReader Dim i As Integer Try CmdString = "Select Recipe_ID, Recipe_Name From [Recipe_Table] Where Manifold" & Module_Num.ToString() & " = 1 and Barcode_ID = " & Val(ComboBox5.SelectedItem) & " ORDER BY Recipe_Name ASC" Cmd = New OdbcCommand(CmdString, Cnn) Ra = Cmd.ExecuteReader() i = 1 ListBox1.Items.Clear() Do While Ra.Read() ListBox1.Items.Add(Ra.Item(1)) ListBox1.ItemHeight = 30 Recipe_ID(i) = Ra.Item(0) i = i + 1 Loop Ra.Close() If ListBox1.Items.Count < 1 Then MessageBox.Show("Can't find any recipes. Please change your search criteria and try again", "Recipe not found", MessageBoxButtons.OK, MessageBoxIcon.Warning) Exit Sub End If ListBox1.SelectedIndex = 0 Catch ex As System.Data.Odbc.OdbcException MessageBox.Show(ex.Message, "ODBC Exception", MessageBoxButtons.OK, MessageBoxIcon.Error) Catch ex As System.Exception MessageBox.Show(ex.Message, "System Exception", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub Label11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label11.Click End Sub Private Sub GroupBox2_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox2.Enter End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged End Sub End Class