Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercise: Teleport price Please use VBA for Microsoft Excel, thank you! The carg

ID: 3852839 • Letter: E

Question

Exercise: Teleport price

Please use VBA for Microsoft Excel, thank you!

The cargo teleporter from Earth to Mars operates between 3 am and 11 am every day. Write a program that computes the price of sending cargo at a particular time. The price per kilo changes every hour. Teleports from Earth to Mars have different prices than teleports from Mars to Earth.

Here’s a sample:

The user enters the time of the transport, kilos, and whether the destination is Earth or Mars. The program computes the price. The PPK (price per kilo) table is shown.

You can assume that users don’t make any typing mistakes.

Hint: Time is entered as hour, then a space, then minutes. Use the InStr function to find the space. The characters to the left of that give you the hour.

Here is my current code.that I need help figuring out.

Option Explicit

Private Sub cmdCompute_Click()
'Vars
Dim Kilos As Integer
Dim tm1 As Integer
Dim Price As Integer
Dim Time As String
Dim Destination As String
  
'Get Data
Time = Cells(3, 2)
Kilos = Cells(7, 2)
Destination = Cells(9, 2)
  
Price = Left([Time], (InStr(1, [Time], " ")) - 1)

'MsgBox (tm1)
Select Case Val(tm1)
Case 3

'Compute
If Destination = "M" Then
Price = Kilos * Cells(17, 3)
Else
If Destination = "E" Then
Price = Kilos * Cells(17, 4)
End If
End If

Case 4
If Destination = "M" Then
Price = Kilos * Cells(18, 3)
Else
If Destination = "E" Then
Price = Kilos * Cells(18, 4)
End If
End If
  
Case 5
If Destination = "M" Then
Price = Kilos * Cells(19, 3)
Else
If Destination = "E" Then
Price = Kilos * Cells(19, 4)
End If
End If

Case 6
If Destination = "M" Then
Price = Kilos * Cells(20, 3)
Else
If Destination = "E" Then
Price = Kilos * Cells(20, 4)
End If
End If
  
Case 7
If Destination = "M" Then
Price = Kilos * Cells(21, 3)
Else
If Destination = "E" Then
Price = Kilos * Cells(21, 4)
End If
End If
  
Case 8
If Destination = "M" Then
Price = Kilos * Cells(22, 3)
Else
If Destination = "E" Then
Price = Kilos * Cells(22, 4)
End If
End If
  
Case 9
If Destination = "M" Then
Price = Kilos * Cells(23, 3)
Else
If Destination = "E" Then
Price = Kilos * Cells(23, 4)
End If
End If
  
Case 10
If Destination = "M" Then
Price = Kilos * Cells(24, 3)
Else
If Destination = "E" Then
Price = Kilos * Cells(24, 4)
End If
End If
  
Case 11
If Destination = "M" Then
Price = Kilos * Cells(24, 3)
Else
If Destination = "E" Then
Price = Kilos * Cells(24, 4)
End If
End If

End Select
  
Cells(14, 1).Select
Cells(14, 1) = Price
End Sub

1 Earth-Mars Teleport Price 3 When: 710 5 Eg., 10 15 7 Kilos: 2 9 Destination: 10 E or M Compute 12 13 14 Price: 15 16 17 18 836 E to M M to E 3 to 3:59 4 to 4:59 5 to 5:59 6 to 6:59 7 to 7:59 8 to 8:59 9 to 9:59 10 to 11 312 349 401 358 393 418 387 362 21 433 390

Explanation / Answer

Option Explicit

Private Sub cmdCompute_Click()
'Vars
Dim Kilos As Integer
Dim tm1 As Integer
Dim Price As Integer
Dim Time As String
Dim Destination As String
  
'Get Data
Time = Cells(3, 2)
Kilos = Cells(7, 2)
Destination = Cells(9, 2)
  
Price = Left([Time], (InStr(1, [Time], " ")) - 1)

'MsgBox (tm1)
Select Case Val(tm1)
Case 3

'Compute
If Destination = "M" Then
Price = Kilos * Cells(17, 3)
Else
If Destination = "E" Then
Price = Kilos * Cells(17, 4)
End If
End If

Case 4
If Destination = "M" Then
Price = Kilos * Cells(18, 3)
Else
If Destination = "E" Then
Price = Kilos * Cells(18, 4)
End If
End If
  
Case 5
If Destination = "M" Then
Price = Kilos * Cells(19, 3)
Else
If Destination = "E" Then
Price = Kilos * Cells(19, 4)
End If
End If

Case 6
If Destination = "M" Then
Price = Kilos * Cells(20, 3)
Else
If Destination = "E" Then
Price = Kilos * Cells(20, 4)
End If
End If
  
Case 7
If Destination = "M" Then
Price = Kilos * Cells(21, 3)
Else
If Destination = "E" Then
Price = Kilos * Cells(21, 4)
End If
End If
  
Case 8
If Destination = "M" Then
Price = Kilos * Cells(22, 3)
Else
If Destination = "E" Then
Price = Kilos * Cells(22, 4)
End If
End If
  
Case 9
If Destination = "M" Then
Price = Kilos * Cells(23, 3)
Else
If Destination = "E" Then
Price = Kilos * Cells(23, 4)
End If
End If
  
Case 10
If Destination = "M" Then
Price = Kilos * Cells(24, 3)
Else
If Destination = "E" Then
Price = Kilos * Cells(24, 4)
End If
End If
  
Case 11
If Destination = "M" Then
Price = Kilos * Cells(24, 3)
Else
If Destination = "E" Then
Price = Kilos * Cells(24, 4)
End If
End If

End Select
  
Cells(14, 1).Select
Cells(14, 1) = Price
End Sub

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote