none
Refresh win form utilise in bar code scanner with VB.NET with VS 2008

    Question

  • I am working on win form on bar code  scanner when I click the  bar code  form get load  when I  reload the form it is never refresh

     so far I have utilize

     me.controls.clear()

    Mr.Close. 

    My code is as follow:

    Public Class ToteHistory

        Private myreader As Symbol.Barcode.Reader = Nothing
        Private myReaderdata As Symbol.Barcode.ReaderData = Nothing
        Private myeventhandler As System.EventHandler = Nothing

        Private Sub ToteHistory_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Try
                startscan()
            Catch ex As Exception

            End Try
        End Sub




        Private Sub ToteHistory_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.GotFocus
            Try
                If myreader.Info.IsEnabled = False Then
                    startscan()
                End If
            Catch ex As Exception

            End Try
        End Sub

        Sub startscan()
            myreader = New Symbol.Barcode.Reader
            myReaderdata = New Symbol.Barcode.ReaderData(Symbol.Barcode.ReaderDataTypes.Text, 500)
            myeventhandler = New System.EventHandler(AddressOf MyReader_ReadNotify)
            AddHandler myreader.ReadNotify, Me.myeventhandler
            myreader.Actions.Enable()
            myreader.Actions.Read(myReaderdata)
        End Sub

        Private Sub MyReader_ReadNotify(ByVal o As Object, ByVal e As EventArgs)
            Cursor.Current = Cursors.WaitCursor
            Dim startTime As String = Date.Now.ToString("HH:mm:ss.fff")
            Dim endTime As String = ""

            Try
                Call ParseScanInfo(myReaderdata.Text)
                If Not masterSerial OrElse Not IsValid Then
                    MessageBox.Show("Must scan GSW Serial Tag")
                Else
                    ' Good scan. Get the history.
                    Lbl_PartNumber.Text = GSW_Item
                    Lbl_SerialNumber.Text = GSWSerial
                    Lbl_Location.Text = fromLocation
                    Lbl_Bin.Text = fromBin

                    Dim data As Data.DataTable = ws.GetSerialNumberHistory(MasterLocation, GSWSerial)

                    Dim displayData As Data.DataTable = BuildDataTableForDisplay()

                    For Each dr As Data.DataRow In data.Rows
                        ' We want to format the time all pretty like.
                        Dim time As String = dr.Item("ITRN_HIS_TIME").ToString()
                        Dim firstSeg As String = time.Substring(0, 2)
                        Dim secondSeg As String = time.Substring(2, 2)
                        Dim ampm As String = "am"

                        If Integer.Parse(firstSeg) > 12 Then
                            ampm = "pm"
                            firstSeg = (Integer.Parse(firstSeg) - 12).ToString
                        ElseIf Integer.Parse(firstSeg) = 0 Then
                            firstSeg = "12"
                        ElseIf Integer.Parse(firstSeg) = 12 Then
                            ampm = "pm"
                        End If

                        displayData.Rows.Add(dr.Item("ITRN_HIS_DATE").ToString, String.Format("{0}:{1} {2}", firstSeg, secondSeg, ampm), dr.Item("LOCATION").ToString, dr.Item("BIN").ToString, dr.Item("BADGE_NUM").ToString)
                    Next

                    DataGrid1.DataSource = displayData

                End If
            Catch ex As Exception
                MessageBox.Show("Read-Notify " + ex.ToString)
            End Try

            endTime = Date.Now.ToString("HH:mm:ss.fff")
            RecordScan(startTime, endTime, "Tote History", "Label Check", ScannerName, myReaderdata.Text)
            Cursor.Current = Cursors.Default
            Call startscan()
        End Sub

        Private Function BuildDataTableForDisplay() As Data.DataTable
            Dim retVal As Data.DataTable = New Data.DataTable("DisplayTable")

            Dim thisColumn As New Data.DataColumn("Date", GetType(Date))
            retVal.Columns.Add(thisColumn)

            thisColumn = New Data.DataColumn("Time", GetType(String))
            retVal.Columns.Add(thisColumn)

            thisColumn = New Data.DataColumn("Location", GetType(String))
            retVal.Columns.Add(thisColumn)

            thisColumn = New Data.DataColumn("Bin", GetType(String))
            retVal.Columns.Add(thisColumn)

            thisColumn = New Data.DataColumn("Badge", GetType(String))
            retVal.Columns.Add(thisColumn)

            Return retVal
        End Function

        Private Sub MenuItem_Close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem_Close.Click
            myreader.Dispose()
            myReaderdata.Dispose()
            Me.Controls.Clear()
            'Me.Visible = False
            Utilities.Show()
            Me.Close()
            DataGrid1.Refresh()


        End Sub

        Private Sub DataGrid1_CurrentCellChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged

        End Sub
    End Class


    Vijay

    Tuesday, March 28, 2017 7:19 PM

Answers

  • once I arrive to ToteHistory form, I scan  bar code that populate  data  in labelcontrols and datagrid and  once  I  perform click event  will clear the form 

     MenuItem_Close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem_Close.Click
            myreader.Dispose()
            myReaderdata.Dispose()
            DataGrid1.Refresh()
            DataGrid1.DataSource = Nothing
            Lbl_PartNumber.Text = String.Empty
            Lbl_SerialNumber.Text = String.Empty
            Lbl_Location.Text = String.Empty
            Lbl_Bin.Text = String.Empty

            Me.Visible = False
            Utilities.Show()
        End Sub


    Vijay

    • Marked as answer by VIJAY361 Tuesday, March 28, 2017 11:07 PM
    Tuesday, March 28, 2017 11:07 PM

All replies

  • I am working on win form on bar code  scanner when I click the  bar code  form get load  when I  reload the form it is never refresh

    What do you mean by 'reload'?   The only code that seems to do the scanning is on load. The GotFocus code will not execute because the reader info has been enabled in the load.  You need to show the code that loads and 'reloads' this form.

    Tuesday, March 28, 2017 8:30 PM
  • Once finish  working on form1 go back to form2 and caame back to form 1

    that what I mean


    Vijay

    Tuesday, March 28, 2017 9:40 PM
  • Once finish  working on form1 go back to form2 and caame back to form 1

    that what I mean

    Show the code that loads and 'reloads' the scanning form.  Which form is form 1 and which form is form2?

    Tuesday, March 28, 2017 10:15 PM
  • Utilities  is form 2 and Totehistory is form 1

    Vijay

    Tuesday, March 28, 2017 10:32 PM
  • Utilities  is form 2 and Totehistory is form 1

    So you are displaying an instance of ToteHistory from code in Utilities.  What is the code that loads and 'reloads' the instance of ToteHistory?

    Tuesday, March 28, 2017 10:41 PM
  • once I arrive to ToteHistory form, I scan  bar code that populate  data  in labelcontrols and datagrid and  once  I  perform click event  will clear the form 

     MenuItem_Close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem_Close.Click
            myreader.Dispose()
            myReaderdata.Dispose()
            DataGrid1.Refresh()
            DataGrid1.DataSource = Nothing
            Lbl_PartNumber.Text = String.Empty
            Lbl_SerialNumber.Text = String.Empty
            Lbl_Location.Text = String.Empty
            Lbl_Bin.Text = String.Empty

            Me.Visible = False
            Utilities.Show()
        End Sub


    Vijay

    • Marked as answer by VIJAY361 Tuesday, March 28, 2017 11:07 PM
    Tuesday, March 28, 2017 11:07 PM