Help with Multiple If/Then Statements
Help with Multiple If/Then Statements
(OP)
I am new to Visual Basic and I am having a difficulty setting multiple strings of If/Then statements for a command buttons click procedure. I know I must be missing something or have something in the wrong order. The first set of if statements works fine but my second set gives me a "Compile error: End If without Block If". As I have all my If's paired with then's and end if's, I don't understand what is wrong. Maybe one of you experts out there can take a look at the following code and give me some advice (Please O Please) :-)
If you need to know anything else about what I am trying to accomplish here just drop me a line.
Thanks,
Aleena
Private Sub cmdComputate_Click()
picScore.Cls
picGrade.Cls
x = 0
If cboScore1.Text <> "N/A" Then
A = Val(cboScore1.Text)
x = x + 10
End If
If cboScore2.Text <> "N/A" Then
b = Val(cboScore2.Text)
x = x + 10
End If
If cboScore3.Text <> "N/A" Then
c = Val(cboScore3.Text)
x = x + 10
End If
If cboScore4.Text <> "N/A" Then
d = Val(cboScore4.Text)
x = x + 10
End If
If cboScore5.Text <> "N/A" Then
e = Val(cboScore5.Text)
x = x + 10
End If
If cboScore6.Text <> "N/A" Then
f = Val(cboScore6.Text)
x = x + 10
End If
If cboScore7.Text <> "N/A" Then
g = Val(cboScore7.Text)
x = x + 10
End If
If cboScore8.Text <> "N/A" Then
h = Val(cboScore8.Text)
x = x + 10
End If
If cboScore9.Text <> "N/A" Then
j = Val(cboScore9.Text)
x = x + 10
End If
If cboScore10.Text <> "N/A" Then
k = Val(cboScore10.Text)
x = x + 50
End If
If cboScore11.Text <> "N/A" Then
m = Val(cboScore11.Text)
x = x + 10
End If
If cboScore12.Text <> "N/A" Then
n = Val(cboScore12.Text)
x = x + 10
End If
If cboScore13.Text <> "N/A" Then
p = Val(cboScore13.Text)
x = x + 10
End If
If cboScore14.Text <> "N/A" Then
r = Val(cboScore14.Text)
x = x + 10
End If
If cboScore15.Text <> "N/A" Then
s = Val(cboScore15.Text)
x = x + 10
End If
If cboScore16.Text <> "N/A" Then
t = Val(cboScore16.Text)
x = x + 10
End If
If cboScore17.Text <> "N/A" Then
u = Val(cboScore17.Text)
x = x + 10
End If
If cboScore18.Text <> "N/A" Then
v = Val(cboScore18.Text)
x = x + 10
End If
z = A + b + c + d + e + f + g + h + j + k + m + n + p + r + s + t + u + v
q = (100 * z) \ x
(Right here is where my problem develops)
If q >= 93 Then picGrade.Print "A"
End If
If q >= 90 Then picGrade.Print "A-"
End If
If q >= 88 Then picGrade.Print "B+"
End If
If q >= 82 Then picGrade.Print "B"
End If
If q >= 80 Then picGrade.Print "B-"
End If
If q >= 78 Then picGrade.Print "C+"
End If
If q >= 72 Then picGrade.Print "C"
End If
If q >= 70 Then picGrade.Print "C-"
End If
If q >= 68 Then picGrade.Print "D+"
End If
If q >= 62 Then picGrade.Print "D"
End If
If q >= 60 Then picGrade.Print "D-"
End If
If q >= 1 Then picGrade.Print "F"
End If
picScore.Print q
End Sub
If you need to know anything else about what I am trying to accomplish here just drop me a line.
Thanks,
Aleena
Private Sub cmdComputate_Click()
picScore.Cls
picGrade.Cls
x = 0
If cboScore1.Text <> "N/A" Then
A = Val(cboScore1.Text)
x = x + 10
End If
If cboScore2.Text <> "N/A" Then
b = Val(cboScore2.Text)
x = x + 10
End If
If cboScore3.Text <> "N/A" Then
c = Val(cboScore3.Text)
x = x + 10
End If
If cboScore4.Text <> "N/A" Then
d = Val(cboScore4.Text)
x = x + 10
End If
If cboScore5.Text <> "N/A" Then
e = Val(cboScore5.Text)
x = x + 10
End If
If cboScore6.Text <> "N/A" Then
f = Val(cboScore6.Text)
x = x + 10
End If
If cboScore7.Text <> "N/A" Then
g = Val(cboScore7.Text)
x = x + 10
End If
If cboScore8.Text <> "N/A" Then
h = Val(cboScore8.Text)
x = x + 10
End If
If cboScore9.Text <> "N/A" Then
j = Val(cboScore9.Text)
x = x + 10
End If
If cboScore10.Text <> "N/A" Then
k = Val(cboScore10.Text)
x = x + 50
End If
If cboScore11.Text <> "N/A" Then
m = Val(cboScore11.Text)
x = x + 10
End If
If cboScore12.Text <> "N/A" Then
n = Val(cboScore12.Text)
x = x + 10
End If
If cboScore13.Text <> "N/A" Then
p = Val(cboScore13.Text)
x = x + 10
End If
If cboScore14.Text <> "N/A" Then
r = Val(cboScore14.Text)
x = x + 10
End If
If cboScore15.Text <> "N/A" Then
s = Val(cboScore15.Text)
x = x + 10
End If
If cboScore16.Text <> "N/A" Then
t = Val(cboScore16.Text)
x = x + 10
End If
If cboScore17.Text <> "N/A" Then
u = Val(cboScore17.Text)
x = x + 10
End If
If cboScore18.Text <> "N/A" Then
v = Val(cboScore18.Text)
x = x + 10
End If
z = A + b + c + d + e + f + g + h + j + k + m + n + p + r + s + t + u + v
q = (100 * z) \ x
(Right here is where my problem develops)
If q >= 93 Then picGrade.Print "A"
End If
If q >= 90 Then picGrade.Print "A-"
End If
If q >= 88 Then picGrade.Print "B+"
End If
If q >= 82 Then picGrade.Print "B"
End If
If q >= 80 Then picGrade.Print "B-"
End If
If q >= 78 Then picGrade.Print "C+"
End If
If q >= 72 Then picGrade.Print "C"
End If
If q >= 70 Then picGrade.Print "C-"
End If
If q >= 68 Then picGrade.Print "D+"
End If
If q >= 62 Then picGrade.Print "D"
End If
If q >= 60 Then picGrade.Print "D-"
End If
If q >= 1 Then picGrade.Print "F"
End If
picScore.Print q
End Sub
RE: Help with Multiple If/Then Statements
Your problem is that you r writing the end if statement after the if then statement which gets finished off in a line.
Your code which compiles goes like this :
Private Sub Command1_Click()
picScore.Cls
picGrade.Cls
x = 0
If cboScore1.Text <> "N/A" Then
A = Val(cboScore1.Text)
x = x + 10
End If
If cboScore2.Text <> "N/A" Then
b = Val(cboScore2.Text)
x = x + 10
End If
If cboScore3.Text <> "N/A" Then
c = Val(cboScore3.Text)
x = x + 10
End If
If cboScore4.Text <> "N/A" Then
d = Val(cboScore4.Text)
x = x + 10
End If
If cboScore5.Text <> "N/A" Then
e = Val(cboScore5.Text)
x = x + 10
End If
If cboScore6.Text <> "N/A" Then
f = Val(cboScore6.Text)
x = x + 10
End If
If cboScore7.Text <> "N/A" Then
g = Val(cboScore7.Text)
x = x + 10
End If
If cboScore8.Text <> "N/A" Then
h = Val(cboScore8.Text)
x = x + 10
End If
If cboScore9.Text <> "N/A" Then
j = Val(cboScore9.Text)
x = x + 10
End If
If cboScore10.Text <> "N/A" Then
k = Val(cboScore10.Text)
x = x + 50
End If
If cboScore11.Text <> "N/A" Then
m = Val(cboScore11.Text)
x = x + 10
End If
If cboScore12.Text <> "N/A" Then
n = Val(cboScore12.Text)
x = x + 10
End If
If cboScore13.Text <> "N/A" Then
p = Val(cboScore13.Text)
x = x + 10
End If
If cboScore14.Text <> "N/A" Then
r = Val(cboScore14.Text)
x = x + 10
End If
If cboScore15.Text <> "N/A" Then
s = Val(cboScore15.Text)
x = x + 10
End If
If cboScore16.Text <> "N/A" Then
t = Val(cboScore16.Text)
x = x + 10
End If
If cboScore17.Text <> "N/A" Then
u = Val(cboScore17.Text)
x = x + 10
End If
If cboScore18.Text <> "N/A" Then
v = Val(cboScore18.Text)
x = x + 10
End If
z = A + b + c + d + e + f + g + h + j + k + m + n + p + r + s + t + u + v
q = (100 * z) \ x
'(Right here is where my problem develops)
If q >= 93 Then
picGrade.Print "A"
End If
If q >= 90 Then
picGrade.Print "A-"
End If
If q >= 88 Then
picGrade.Print "B+"
End If
If q >= 82 Then
picGrade.Print "B"
End If
If q >= 80 Then
picGrade.Print "B-"
End If
If q >= 78 Then
picGrade.Print "C+"
End If
If q >= 72 Then
picGrade.Print "C"
End If
If q >= 70 Then
picGrade.Print "C-"
End If
If q >= 68 Then
picGrade.Print "D+"
End If
If q >= 62 Then
picGrade.Print "D"
End If
If q >= 60 Then
picGrade.Print "D-"
End If
If q >= 1 Then
picGrade.Print "F"
End If
picScore.Print q
End Sub
If you have any other probs please feel free
Ravi
E-Mail : rkochher@velos.ssind.com
Ravi Kochher
rkochher@velos.ssind.com
RE: Help with Multiple If/Then Statements
It works great now. I guess I just didn't format it correctly. It had me tearing my hair out for awhile there...
Aleena
RE: Help with Multiple If/Then Statements
RE: Help with Multiple If/Then Statements
I will check it out
Aleena
RE: Help with Multiple If/Then Statements
Select Case q
Case 93
picGrade.Print "A"
Case 90
picGrade.Print "A-"
Case 88
picGrade.Print "B+"
Case 82
picGrade.Print "B"
Case 80
picGrade.Print "B-"
'..... and so on
End Select
Now, when we are able to tab-indent on Tek-Tips, the code will be even easier to read.
RE: Help with Multiple If/Then Statements
RE: Help with Multiple If/Then Statements
You guys have been a great help. This is my sophomore year at college and I am just now starting my programming class (like just this week..hehe) and we have not discussed any of this in class. I decided to experiment on my own for a bit. (I think that is always the best way to learn something new) My text is not too specific on some items so I really appreciate all of your advice.
Thanks again Elizabeth :-)
Aleena
RE: Help with Multiple If/Then Statements
RE: Help with Multiple If/Then Statements
Consider creating a control array. When designing your form, add your combo box and call it cboScore (no number)
Select & copy it to the clip board, then paste. VB will ask if you want to create a control array - reply yes and paste it as many times as necessary (18 in the example).
Then, in code you can replace the 18 if statements:
If cboScoreNN.Text <> "N/A" Then
t = Val(cboScoreNN.Text)
x = x + 10
End If
with a single if statement within a loop:
for i = 1 to 18
If cboScore(i).Text <> "N/A" Then
z = z + Val(cboScore(i).Text)
x = x + 10
End If
next i
if you really need to keep track of the individual score values (a,b,c...) cretae a score array (Dim intScore(18) As Integer)and use it in your if statement:
intScore(i) = Val(cboScore(i).Text)
RE: Help with Multiple If/Then Statements
RE: Help with Multiple If/Then Statements
I will play around with that. I would sure make the whole thing quite a bit shorter... hehe
Aleena
Aleena
petersen@cdsnet.net
My Personal Website
"I can picture a world without war, a world without hate.
And I can picture us attacking this world, because they'd never expect it"