1
\$\begingroup\$

I have a mapping application and the marker I'm using is based on the field rep assigned to that visit. My code is just a Select Case based on the rep's name and then it sets the bitmap for that person.

My code works fine, but there are 19 different field reps and I feel there must be a better way.

The code loops through a CSV file and grabs the Field Rep's name. Based on who it is, a System Resource image for that person is assigned to the image.

Select Case CurrentRecord(iAssignedToCol)
  Case "Al B. Connor"
    If CurrentRecord(iStatusCol) = "Scheduled" Then
      MapIcon = New Bitmap(My.Resources.Scheduled_ABC)
    ElseIf CurrentRecord(iStatusCol) = "Tentatively Scheduled" Then
      MapIcon = New Bitmap(My.Resources.Tentative_ABC)
    End If
  Case "Donald E. Firestone"
    If CurrentRecord(iStatusCol) = "Scheduled" Then
      MapIcon = New Bitmap(My.Resources.Scheduled_DEF)
    ElseIf CurrentRecord(iStatusCol) = "Tentatively Scheduled" Then
      MapIcon = New Bitmap(My.Resources.Tentative_DEF)
    End If
  Case "3rd name"
    If CurrentRecord(iStatusCol) = "Scheduled" Then
      MapIcon = New Bitmap(My.Resources.Scheduled_GHI)
    ElseIf CurrentRecord(iStatusCol) = "Tentatively Scheduled" Then
      MapIcon = New Bitmap(My.Resources.Tentative_GHI)
    End If
  Case "4th name"
    If CurrentRecord(iStatusCol) = "Scheduled" Then
      MapIcon = New Bitmap(My.Resources.Scheduled_JKL)
    ElseIf CurrentRecord(iStatusCol) = "Tentatively Scheduled" Then
      MapIcon = New Bitmap(My.Resources.Tentative_JKL)
    End If
  Case "5th name"
    If CurrentRecord(iStatusCol) = "Scheduled" Then
      MapIcon = New Bitmap(My.Resources.Scheduled_MNO)
    ElseIf CurrentRecord(iStatusCol) = "Tentatively Scheduled" Then
      MapIcon = New Bitmap(My.Resources.Tentative_MNO)
    End If
  Case "6th name"
    If CurrentRecord(iStatusCol) = "Scheduled" Then
      MapIcon = New Bitmap(My.Resources.Scheduled_PQR)
    ElseIf CurrentRecord(iStatusCol) = "Tentatively Scheduled" Then
      MapIcon = New Bitmap(My.Resources.Tentative_PQR)
    End If
  Case "7th name"
    If CurrentRecord(iStatusCol) = "Scheduled" Then
      MapIcon = New Bitmap(My.Resources.Scheduled_STU)
    ElseIf CurrentRecord(iStatusCol) = "Tentatively Scheduled" Then
      MapIcon = New Bitmap(My.Resources.Tentative_STU)
    End If
  Case "8th name"
    If CurrentRecord(iStatusCol) = "Scheduled" Then
      MapIcon = New Bitmap(My.Resources.Scheduled_VWX)
    ElseIf CurrentRecord(iStatusCol) = "Tentatively Scheduled" Then
      MapIcon = New Bitmap(My.Resources.Tentative_VWX)
    End If
  Case "9th name"
    If CurrentRecord(iStatusCol) = "Scheduled" Then
      MapIcon = New Bitmap(My.Resources.Scheduled_YZA)
    ElseIf CurrentRecord(iStatusCol) = "Tentatively Scheduled" Then
      MapIcon = New Bitmap(My.Resources.Tentative_YZA)
    End If
End Select

marker = New GMarkerGoogle(New PointLatLng(sSearchLat, sSearchLong), MapIcon)

Thanks!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Welcome to Code Review! Please add the full code (where's currently "Etc...") so there's enough context to properly evaluate the code. At the moment your post is going to be closed due to lack of this. Hope you get some good answers once that's fixed. Enjoy your stay! \$\endgroup\$
    – ferada
    Commented Sep 21, 2019 at 14:20
  • \$\begingroup\$ The etc. etc. is just 18 more names and 18 more images names. It's not needed to explain the context. \$\endgroup\$
    – Elwood472
    Commented Sep 23, 2019 at 14:11

1 Answer 1

1
\$\begingroup\$

this should be written once like this:

private sub whatever(byref res As Bitmap)
  If CurrentRecord(iStatusCol) = "Scheduled" Then
      MapIcon = New Bitmap(res)
  ElseIf CurrentRecord(iStatusCol) = "Tentatively Scheduled" Then
      MapIcon = New Bitmap(res)
  End If
end sub

and

Select Case CurrentRecord(iAssignedToCol)
    Case "Al B. Connor"
         whatever(My.Resources.Scheduled_ABC)
    Case "Donald E. Firestone"
         whatever(My.Resources.Scheduled_DEF)
    Case....

Hope you get my point..

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.