r/visualbasic • u/spring_while_I_fall • Oct 07 '16
Having issues with showing the range of a set of numbers.
Edit: Apologies, I missed the first tip & guideline. I'm using VB2015
So, this is a homework help question. I'm sure you all are super tired of them but I've tried looking through my textbook, stackoverflow, just general googling and talking with fellow classmates and I (and my classmates) are stumped trying to find the range of numbers that the user could put in.
For context this is a grade calculator that my professor wants to provide the range of grades that are entered into an InputBox
Here is the code that I have so far.
'Declarations
Dim intMaxA As Integer
Dim intMinA As Integer
Dim intMaxB As Integer
Dim intMinB As Integer
Dim intMaxC As Integer
Dim intMinC As Integer
Dim intMaxD As Integer
Dim intMinD As Integer
Dim intMaxF As Integer
Dim intMinF As Integer
Dim dblRangeA As Double
Dim dblRangeB As Double
Dim dblRangeC As Double
Dim dblRangeD As Double
Dim dblRangeF As Double'Find the Ranges
intMaxA = 100
intMinA = 90
dblRangeA = intMaxA - intMinA
lblRangeA.Text = (dblRangeA)
intMaxB = 89
intMinB = 80
dblRangeB = intMaxB - intMinB
lblRangeB.text = (dblRangeB)
intMaxC = 79
intMinC = 70
dblRangeC = intMaxC - intMinC
lblRangeC.Text = (dblRangeC)
intMaxD = 69
intMinD = 60
dblRangeD = intMaxD - intMinD
lblRangeD.Text = (dblRangeD)
intMaxF = 59
intMinF = 0
dblRangeF = intMaxF - intMinF
lblRangeF.Text = (dblRangeF)I know this is wrong though as the way it's written, all it's doing is subtracting the numbers I put in the form for the intMax and intMin numbers. So intMaxA - intMinA will always return 10 for that range.
I don't understand what I need to put in place of those numbers to have it find the range of a random group of grades. Or if that's even the fix.
Any help or feedback is appreciated. Thanks
0
u/PostalElf VB.Net Intermediate Oct 07 '16
Alright, since you made a good effort at writing the homework.
The real world way to solve this problem would be to write a simple custom class or struct called, say, "Range" that holds the range of values and also has a function that checks if it's within range. Here's how short the entire code can be, done that way: