I'm trying to finish a college project for tommorrow, but am having real problems with my code. Every time I try and run it, I get an error message saying 'Expected If'. I looked and looked at it, but can't for the life of me work out whatthe problem is!! I would be very grateful if someone would take a look and solve the mystery for me! I've put an * where I think the problem is. Thank you. (The code is very clumsy in places, but unfortunately I'm on a tight deadline!)
<html>
<head>
<title>Organism</title>
<style type="text/css">
html {height:100%;}
body {height:100%; margin:0; padding:0;}
#bg {position:absolute; top:0; left:0; width:100%; height:100%;}
#content {position:relative; z-index:1;}
</style>
<script language="vbscript">
Option Explicit
Dim Org1Pic(9)
Dim Org2Pic(9)
Dim Org3Pic(9)
Dim x
x = 9
Dim y
y = 0
Dim noOfMoves
Dim s
s = 0
Dim n
n = 0
Dim Av
Dim Luck
Dim RandomOrg
RandomOrg = 0
Sub Luck1_OnMouseOver()
Luck1.src="Luck Buttons/Luck1Over.gif"
End Sub
Sub Luck1_OnMouseOut()
Luck1.src="Luck Buttons/Luck1.gif"
End Sub
Sub Luck1_OnClick()
Luck = 1
Luck1.src="Luck Buttons/Luck1OnClick.gif"
End Sub
Sub Luck2_OnMouseOver()
Luck2.src="Luck Buttons/Luck2Over.gif"
End Sub
Sub Luck2_OnMouseOut()
Luck2.src="Luck Buttons/Luck2.gif"
End Sub
Sub Luck2_OnClick()
Luck = 5
Luck2.src="Luck Buttons/Luck2OnClick.gif"
End Sub
Sub Luck3_OnMouseOver()
Luck3.src="Luck Buttons/Luck3Over.gif"
End Sub
Sub Luck3_OnMouseOut()
Luck3.src="Luck Buttons/Luck3.gif"
End Sub
Sub Luck3_OnClick()
Luck = 9
Luck3.src="Luck Buttons/Luck3OnClick.gif"
End Sub
Sub startbtn_OnClick()
Window.SetInterval"MoveOrgRight", 20
x = Luck
RandomOrg = 1 + CInt(Rnd() * 2)
if RandomOrg = 1 Then * I think the problem may be in this if staement.
Org.src = Org1Pic(Luck)
Else if RandomOrg = 2 Then
Org.src = Org2Pic(Luck)
Else if RandomOrg = 3 Then
Org.src = Org3Pic(Luck)
End if
End Sub
Sub MoveOrgRight()
if CInt(Org.style.pixelLeft) < CInt (document.body.clientwidth / 1.3) Then
Org.style.pixelLeft = Org.style.pixelLeft + 1
End if
if x <= 3 And CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 5.5) Or CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 5) Or CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 4.5) Or CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 4) Or CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 3.5) Or CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 3) Or CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 2.5) Or CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 2) Then
generateLowX
Elseif x > 3 And x <= 6 And CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 5.5) Or CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 5) Or CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 4.5) Or CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 4) Or CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 3.5) Or CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 3) Or CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 2.5) Or CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 2) Then
generateMedX
Elseif x > 6 And x <= 9 And CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 5.5) Or CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 5) Or CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 4.5) Or CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 4) Or CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 3.5) Or CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 3) Or CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 2.5) Or CInt(Org.style.pixelLeft) = CInt(document.body.clientwidth / 2) Then
generateHighX
End if
End Sub
Sub generateLowX()
n = entluck.value
x = 1 + CInt(Rnd() * 2)
y = x + y
xVal.innertext = x
yVal.innertext = y
s = s + 1
Org.src = OrgPic(Av)
ss.innertext = s
Av = CInt(y / s)
average.innertext = y / s
End Sub
Sub generateMedX()
n = entluck.value
x = 1 + CInt(Rnd() * 5)
y = x + y
xVal.innertext = x
yVal.innertext = y
s = s + 1
Org.src = OrgPic(Av)
ss.innertext = s
Av = CInt(y / s)
average.innertext = y / s
End Sub
Sub generateHighX()
n = entluck.value
x = 1 + CInt(Rnd() * 8)
y = x + y
xVal.innertext = x
yVal.innertext = y
s = s + 1
Org.src = OrgPic(Av)
ss.innertext = s
Av = CInt(y / s)
average.innertext = y / s
There are other alternatives to the end if, elseif,else if, and if statments,I have in the past used the same as a toolbar code is in a browser to handle events
case and select case is another way to perform events
example:
Dim Whatever as Integer
Select Case whatever
case whatever = somthing
case whatever could do somthing here
case else could be somthing else here
End Select
End Sub
this could be used instead of else if statments,Your going to need to play with it
<snip plug>
Last edited by Ancient Dragon; Nov 13th, 2008 at 10:18 pm. Reason: snipped plug/self promotion
The solution was as simple as taking out the space between the 'Else' and the 'If'. I spent ages trying to work it out, but sometimes you just can't see for looking!
Best practice in coding is using a "tab spaces" and align the conditional statement so that it can be easily to read and debug... as what example did of QVeen
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.