1
votes

I am brand new to Visual Basic 6 and have no chance of upgrading to a newer platform. We need to make a couple changes to an existing program.

I have a form (Form1) with 3 textboxes. I need to save each textbox value after the user fills them in.

After the user presses the Enter key, the value for that box should be saved and later tested for empty values from a single function/Sub.

Here is what I have so far:

Private Sub empId_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = 13 Then
    Dim empId As String
    empId = Form1.empId.Text 'Save this for a later test
  End If
End Sub

Private Sub orderNo_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = 13 Then
    Dim orderNo As String
    orderNo = Form1.orderNo.Text 'Save this for a later test
  End If
End Sub

Private Sub partNo_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = 13 Then
    Dim partNo As String
    partNo = Form1.partNo.Text 'Save this for a later test
  End If
End Sub

After all the variables have been set, I would like to do something similar to:

if(!empId || !orderNo || !partNo) {
  // show error
} else{
  // process the data
}

Can someone show me how this should be done?

1

1 Answers

2
votes

The following code is similar to what you already have provided, but should do what you need:

Option Explicit

Private m_empID As String
Private m_orderNo As String
Private m_partNo As String

Private Sub Form_Load()
   Me.KeyPreview = True
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
   m_empID = empID.Text
   m_orderNo = orderNo.Text
   m_partNo = partNo.Text
End Sub

Private Sub ASubCalledLater()
   If m_empID = "" Or m_orderNo = "" Or m_partNo = "" Then
      ' show error
   Else
      ' process the data
   End If
End Sub

You will need to set KeyPreview for the form to True for this to work.