ClassExamples

# ClassExamples - The variables assignment ONE WAY TO DO...

• Test Prep
• 12

This preview shows pages 1–4. Sign up to view the full content.

The variables assignment ‘ONE WAY TO DO IT 'Dim intAmount As Double 'For this part the amount has to be as double because there are decimals involved. 'Dim intDay As String 'intDay shouldn't be considered a integer because it is a word, we use String instead. 'intAmount = 25.9 'intDay = "Monday" 'MsgBox intAmount & " pounds were ordered on " & intDay 'EXAMPLE TO HAVE THE PERSON PUT IN THE DATA (Another way to do it) Dim dblAmount As Double Dim strDay As String 'this part is the input from the user dblAmount = Application.InputBox("Enter the ordered amount", , , , , , , 1) strDay = InputBox("Enter the day of the week") 'output Sheet1.Cells(1, 1).Value = dblAmount & " pounds were ordered on " & strDay Heart rate assignment 'Dim intAge, intRestHRt, intTrainHRt As Double ' ' intAge = InputBox("Please enter your age") ' ' intRestHRt = InputBox("Please enter your resting heart rate") ' ' intTrainHRt = (0.7 * (220 - intAge)) + (0.3 * intRestHRt) ' ' MsgBox " A " & intAge & "-yr old person with a resting heart rate of " & intRestHRt & " should maintain his/her training heart rate at " & intTrainHRt & " beats per minute. " ' Dim intAge As Integer Dim intRestHRt As Integer Dim dblTrainHRt As Double 'Input intAge = InputBox("Please enter your age") intRestHRt = InputBox("Please enter your resting heart rate") 'Calculation

This preview has intentionally blurred sections. Sign up to view the full version.

dblTrainHRt = (0.7 * (220 - intAge)) + (0.3 * intRestHRt) 'Output MsgBox dblTrainHRt CALCULATOR EXAMPLE (ADD TWO NUMBERS BY THE INPUT OF USER) Dim intAmount1, intAmount2, intAmount3 As Integer intAmount1 = Application.InputBox("Enter a number", , , , , , , 1) intAmount2 = Application.InputBox("Enter a number", , , , , , , 1) intAmount3 = intAmount1 + intAmount2 'output Sheet1.Cells(1, 1).Value = intAmount1 Sheet1.Cells(1, 2).Value = "+" Sheet1.Cells(1, 3).Value = intAmount2 Sheet1.Cells(1, 4).Value = "=" Sheet1.Cells(1, 5).Value = intAmount3 Sheet1.Cells(1, 1).HorizontalAlignment = xlCenter Sheet1.Cells(1, 2).HorizontalAlignment = xlCenter Sheet1.Cells(1, 3).HorizontalAlignment = xlCenter Sheet1.Cells(1, 4).HorizontalAlignment = xlCenter Sheet1.Cells(1, 5).HorizontalAlignment = xlCenter MsgBox intAmount1 & vbTab & "+" & vbTab & intAmount2 & vbCrLf & "=" & vbCrLf & intAmount3 BREAK-EVEN,PROFIT, LOSS EXAMPLE WITH ERROR TRAPPING On Error GoTo TrappingError13 'Indicating that it should trap that error, to handle an error incase your not using an input box. Error Trapping/Handling Dim intRevenue As Integer Dim intCost As Integer intRevenue = Sheet1.Cells(2, 1).Value intCost = Sheet1.Cells(2, 2).Value If intRevenue > intCost Then Sheet1.Cells(2, 4).Value = "Profit" ' ElseIf intRevenue = intCost Then Else 'like writing ElseIf statement/with this you wouldn't need to use two End If 'for this you need two END IFs
If intRevenue = intCost Then 'like writing ElseIf statement/with this you wouldn't need to use two End If 'for this you need two END IFs Sheet1.Cells(2, 4).Value = "Break-even" Else Sheet1.Cells(2, 4).Value = "Loss" End If End If Exit Sub 'TO MAKE SURE THIS PART DOESNT EXECUTE USE Exit Sub TrappingError13: If Err = 13 Then MsgBox ("Please check the revenue and expense.") Sheet1.Cells(2, 1).Value = "" 'This empty string value deletes what you put in so you can correct it.

This preview has intentionally blurred sections. Sign up to view the full version.

This is the end of the preview. Sign up to access the rest of the document.
• Spring '16
• heart rate, Sheet1.Cells

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern