Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

Heres a sample:

image text in transcribed

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 dont 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.

image text in transcribed

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is the preferred personality?

Answered: 1 week ago