I know there must be a better way to perform the above sub than using multiple If
statements. I was thinking of storing the obj.PropertName
into a collection and run it through a for
loop.
'Create instance
Dim wellObj As CWell
Set wellObj = New CWell
. . .
Private Sub Well_List_Click()
'Must check if null..
If Not (Well_List.Column(1, row) = "") Then
wellObj.wellName = Well_List.Column(1, row)
End If
If Not (Well_List.Column(2, row) = "") Then
wellObj.wellActive = Well_List.Column(2, row)
End If
If Not (Well_List.Column(3, row) = "") Then
wellObj.wellDiameter = Well_List.Column(3, row)
End If
If Not (Well_List.Column(4, row) = "") Then
wellObj.wellCasing = Well_List.Column(4, row)
End If
If Not (Well_List.Column(5, row) = "") Then
wellObj.screenedInterval = Well_List.Column(5, row)
End If
If Not (Well_List.Column(6, row) = "") Then
wellObj.wellSock = Well_List.Column(6, row)
End If
If Not (Well_List.Column(7, row) = "") Then
wellObj.wellDepth = Well_List.Column(7, row)
End If
End Sub
Refactored:
NB: wellObj has all properties type String
Private Sub Well_List_Click()
Dim properties(1 To 7) As String
Dim value As String
Dim row As Integer
'Skip header
row = Well_List.ListIndex + 1
'Must check if null..
properties(1) = "WellName"
properties(2) = "WellActive"
properties(3) = "WellDiameter"
properties(4) = "wellCasing"
properties(5) = "ScreenedInternal"
properties(6) = "WellSock"
properties(7) = "WellDepth"
For i = 1 To 7
value = Well_List.Column(i, row)
If value <> vbNullString Then
CallByName wellObj, properties(i), VbLet, value
End If
Next
End Sub