Hi, I'm building an application that reads barcode scanning data into multiple forms and textboxes. At the moment, to handle that data I have created a large nested if statement that checks to see which object has focus so that the scanned data is placed there and focus moves down to the next object:
Private Sub HandleData(ByVal TheReaderData As Symbol.Barcode.ReaderData) 'Scanning Data into frmGetCount If frmName.Name = "frmGetCount" Then If frmGetCount.txtGetCountItemNo.Focused = True Then frmGetCount.txtGetCountItemNo.Text = TheReaderData.Text If frmGetCount.txtGetCountItemNo.TextLength <> 20 Then MessageBox.Show("Sorry, you did not scan an Item No. Please try again.") frmGetCount.txtGetCountItemNo.Text = "" frmGetCount.txtGetCountItemNo.Focus() Else frmGetCount.txtGetCountVariantCode.Focus() End If ElseIf frmGetCount.txtGetCountVariantCode.Focused = True Then frmGetCount.txtGetCountVariantCode.Text = TheReaderData.Text If frmGetCount.txtGetCountVariantCode.TextLength <> 10 Then MessageBox.Show("Sorry, you did not scan a Variant Code, please try again.") frmGetCount.txtGetCountVariantCode.Text = "" frmGetCount.txtGetCountVariantCode.Focus() End If End If End Sub
This is just for one of 5 forms I am currently developing. I am looking for a way to make this code much more dynamic and re-usable by removing the hard-coded objects name. Does anyone know how this might be done?