|
-
Jul 4th, 2000, 11:31 PM
#1
Thread Starter
Hyperactive Member
what this program is supposed to do is find the average of 2 grades ... then display the average n depending on what the average is ... it will give u a letter value ... (please try this on ur comp n see if it works for u or not)
u need 4 textboxes, 1 command button
Private Sub Command1_Click()
Dim a1 As Integer, a2 As Integer, b As Integer, c As String
a1 = Text1.Text
a2 = Text2.Text
b = (a1 + a2) / 2
Text3.Text = b
Call test(b)
c = test(b)
Text4.Text = c
End Sub
Public Function test(b As Integer)
Dim wha As String
Select Case b
Case Is >= 97
wha = "A+"
Case Is >= 55
what = "C"
Case Is >= 0
wha = "F"
test = wha
End Select
End Function
i don't know y it won't give me the value letters for anything above 54 ...
-
Jul 4th, 2000, 11:38 PM
#2
I have three things to say: Use Option Explicit, use Option Explicit, Use Option Explicit.
And a fourth: Change "what" to "wha"
-
Jul 5th, 2000, 09:25 PM
#3
Lively Member
hi,
i know what the problem is and will explain it before writing the correct code. the problem is in the select case. say you were given to say if 88 is larger than 55 or larger than 0, you would say that both are correct, right? that is exactly what is going on in the select case you wrote so, here is the code not in a select case (i dont like it, and it is not ussefull here):
Private Sub Command1_Click()
Dim a1, a2, b As Integer, c As String
a1 = Text1.Text
a2 = Text2.Text
b = (a1 + a2) / 2
Text3.Text = b
Call test(b)
c = test(b)
Text4.Text = c
End Sub
Public Function test(b As Integer)
Dim wha As String
If b >= 97 Then wha = "A+"
If b >= 55 And b < 97 Then wha = "C"
If b >= 0 And b < 55 Then wha = "F"
test = wha
End Function
hope u like it and it is helpfull, it worked on my computer, bye,
yair
-
Jul 5th, 2000, 10:31 PM
#4
Thread Starter
Hyperactive Member
i don't think u understood my question
i agree with ur example that 0 n 55 r less than 88 ... making an if then statement saying that it should be x >= n x <= .... but my select case code works fine ... any number it will give the right letter value to ... EXCEPT for anything bigger than 100 ... i don't know y ...
-
Jul 5th, 2000, 10:45 PM
#5
Frenzied Member
Select Case is the right thing to use here, ysa1441 has highlighted a C++ thing with the switch statement (the C++ equivilent of Select Case) which doesn't apply here.
there may be others but you have a bug here
Code:
Public Function test(b As Integer)
Dim wha As String
Select Case b
Case Is >= 97
wha = "A+"
Case Is >= 55
what = "C"
Case Is >= 0
wha = "F"
test = wha 'Here Is Your bug.
End Select 'By putting test = wha before End Select it
'only sets the return value if the grade is an F
' Switch these two statement's around
End Function
-
Jul 5th, 2000, 11:05 PM
#6
Thread Starter
Hyperactive Member
fix that
ok i put the test = wha after the select case ... i only get the letter value for anything from 97 n up (a+) n 55 n below (f) i don't get the letter value for anything ranging from 56 to 96
-
Jul 6th, 2000, 12:55 AM
#7
Frenzied Member
Code:
Public Function test(b As Integer)
Dim wha As String
Select Case b
Case Is >= 97
wha = "A+"
Case Is >= 55
what = "C" 'Bug Here You put what instead of wha
Case Is >= 0
wha = "F"
End Select
test = wha
End Function
You really should use option explicit at the begining of your code, it sorts out bugs like that before they happen.
go to options and check require variable declaration, that puts it in automaticly.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|