private void nextScanButton_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(dataValueTextBox.Text)) { MessageBox.Show("Input value cannot be empty.", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!Validator.isIntDouble(dataValueTextBox.Text)) { MessageBox.Show("Input value contains invalid characters.", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } byte[] scanValue; switch (dataTypeComboBox.SelectedIndex) { case 0: try { scanValue = BitConverter.GetBytes(Convert.ToInt16(dataValueTextBox.Text)); } catch { MessageBox.Show("Input value is too large or too small to be an Int16.", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } break; case 1: try { scanValue = BitConverter.GetBytes(Convert.ToInt32(dataValueTextBox.Text)); } catch { MessageBox.Show("Input value is too large or too small to be an Int32.", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } break; case 2: try { scanValue = BitConverter.GetBytes(Convert.ToInt64(dataValueTextBox.Text)); } catch { MessageBox.Show("Input value is too large or too small to be an Int64.", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } break; case 3: try { scanValue = BitConverter.GetBytes(Convert.ToSingle(dataValueTextBox.Text)); } catch { MessageBox.Show("Input value is too large or too small to be a Float.", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } break; case 4: try { scanValue = BitConverter.GetBytes(Convert.ToDouble(dataValueTextBox.Text)); } catch { MessageBox.Show("Input value is too large or too small to be an Double.", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } break; default: MessageBox.Show("An unknown error occurred.", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _ms.nextScan(scanValue, completeScan); }