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

Using Visual Basic excel Question 2: Create a User Defined Function that accepts

ID: 3890794 • Letter: U

Question

Using Visual Basic excel Question 2: Create a User Defined Function that accepts an unknown range of numbers and determines if a pattern of either 6 consecutive numbers trending up or 6 consecutive numbers trending down exists anywhere within the range. Beware, the range provided may have more than 6 numbers in it. The input range will be a one dimensional range as shown in the example below. How you display to the user that an upward/downward trend exists is up you. 5 257 67 8990 100 Trend Up ll sl 81 5| 4| 8| No Trend 100 9998 876555 74 Trend Down

Explanation / Answer

'Progeram asks for a range of numbrs
'Takes the numbers in that range
'Displays upward or downward trend if 6 numbers are in sequence


Sub Trend()


'Declare variables


Dim user_input As Integer
Dim flag, counter As Integer

'Ask for range

user_input = InputBox("Enter the range")

'Initialize variables

flag = 1
counter = 0

'Declare array

Dim arr(100) As Integer

'Input the digits from user

While (flag < user_input + 1)

Number = InputBox("Enter the " & flag & " number")

'Store the digits

arr(counter) = Number
counter = counter + 1
flag = flag + 1

'End while loop
Wend

'Check for downward trend
seq = 1
For i = 0 To counter
If (arr(i) > arr(i + 1)) Then seq = seq + 1 Else: seq = 1

'If Downward trend found for 6 numbers in a sequence then display Downward trend in msgbox and exit

If seq = 6 Then
MsgBox ("Downward Trend")

'Exit from loop with help of goto operator
GoTo ending
Else
End If

'For loop ending
Next i

'Check for upward trend

seq = 1
For i = 0 To counter
If (arr(i) < arr(i + 1)) Then seq = seq + 1 Else: seq = 1

'If upward trend found for 6 numbers in a sequence then display Downward trend in msgbox and exit

If seq = 6 Then
MsgBox ("Upward Trend")

'Exit from loop with help of goto operator
GoTo ending
Else
End If

'For loop ending
Next i

'Other end of goto operator
ending:

'End of module
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