| | |
Please help!
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2007
Posts: 11
Reputation:
Solved Threads: 1
Hi,
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 Window_OnLoad()
startbtn.style.pixelLeft = document.body.clientwidth / 30
startbtn.style.pixeltop = document.body.clientheight / 1.6
Org.style.pixelLeft = document.body.clientwidth / 15
Org.style.pixeltop = document.body.clientheight / 1.25
Luck1.style.pixelTop = (document.body.clientheight / 2.3) - (Luck1.height * 2)
Luck2.style.pixelTop = (document.body.clientheight / 2.3) - Luck2.height
Luck3.style.pixelTop = document.body.clientheight / 2.3
Randomize
noOfMoves = (document.body.clientwidth / 1.8) - (document.body.clientwidth / 6) / 5
p.innertext = noOfMoves
checkDocWidDiv.innertext = CInt (document.body.clientwidth / 1.8)
if n = 0 Then
EntLuck.innertext = "Please enter luck"
End if
Org1Pic(1) = "Org Gradients/Org11.gif"
Org1Pic(2) = "Org Gradients/Org10.gif"
Org1Pic(3) = "Org Gradients/Org9.gif"
Org1Pic(4) = "Org Gradients/Org8.gif"
Org1Pic(5) = "Org Gradients/Org7.gif"
Org1Pic(6) = "Org Gradients/Org6.gif"
Org1Pic(7) = "Org Gradients/Org5.gif"
Org1Pic(8) = "Org Gradients/Org4.gif"
Org1Pic(9) = "Org Gradients/Org3.gif"
Org2Pic(1) = "2ndOrgGradients/2ndOrg9.gif"
Org2Pic(2) = "2ndOrgGradients/2ndOrg8.gif"
Org2Pic(3) = "2ndOrgGradients/2ndOrg7.gif"
Org2Pic(4) = "2ndOrgGradients/2ndOrg6.gif"
Org2Pic(5) = "2ndOrgGradients/2ndOrg5.gif"
Org2Pic(6) = "2ndOrgGradients/2ndOrg4.gif"
Org2Pic(7) = "2ndOrgGradients/2ndOrg3.gif"
Org2Pic(8) = "2ndOrgGradients/2ndOrg2.gif"
Org2Pic(9) = "2ndOrgGradients/2ndOrg1.gif"
Org3Pic(1) = "2ndOrgGradients/3rdOrg9.gif"
Org3Pic(2) = "2ndOrgGradients/3rdOrg8.gif"
Org3Pic(3) = "2ndOrgGradients/3rdOrg7.gif"
Org3Pic(4) = "2ndOrgGradients/3rdOrg6.gif"
Org3Pic(5) = "2ndOrgGradients/3rdOrg5.gif"
Org3Pic(6) = "2ndOrgGradients/3rdOrg4.gif"
Org3Pic(7) = "2ndOrgGradients/3rdOrg3.gif"
Org3Pic(8) = "2ndOrgGradients/3rdOrg2.gif"
Org3Pic(9) = "2ndOrgGradients/3rdOrg1.gif"
End Sub
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
End Sub
Sub checkLuck_OnClick()
n = entluck.value
LuckRes.innertext = n
End Sub
</script>
</head>
<body bgcolor="000000">
<div id="bg"><img id="backGround" src="OrgBackG.jpg" width="100%" height="100%"/></div>
<div id="content">
<img id="startbtn" style="position: absolute" src="startBtn.jpg" height="25"/>
<img id="Org" style="position: absolute" src="Org Gradients/Org1.gif" height="60"/>
<img id="Luck1" style="position: absolute" src="Luck Buttons/Luck1.gif" height="40"/>
<img id="Luck2" style="position: absolute" src="Luck Buttons/Luck2.gif"height="40"/>
<img id="Luck3" style="position: absolute" src="Luck Buttons/Luck3.gif" height="40"/>
Random number:<input type="text" id="xVal" style="width:auto;"/>
Number total:<input type="text" id="yVal" style="width:auto;"/>
Number of moves?<input type="text" id="p" style="width:auto;" />
Number of moves?<input type="text" id="ss" style="width:auto;"/>
Average:<input type="text" id="average" style="width:auto;"/><br/>
<input type="text" id="Entluck"/><input type="button" id="checkLuck" value="Check Luck"/><input type="text" id="LuckRes"/><br/>
Clientwidth / 1.8:<input type="text" id="checkDocWidDiv"/><br/>
</div>
</body>
</html>
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 Window_OnLoad()
startbtn.style.pixelLeft = document.body.clientwidth / 30
startbtn.style.pixeltop = document.body.clientheight / 1.6
Org.style.pixelLeft = document.body.clientwidth / 15
Org.style.pixeltop = document.body.clientheight / 1.25
Luck1.style.pixelTop = (document.body.clientheight / 2.3) - (Luck1.height * 2)
Luck2.style.pixelTop = (document.body.clientheight / 2.3) - Luck2.height
Luck3.style.pixelTop = document.body.clientheight / 2.3
Randomize
noOfMoves = (document.body.clientwidth / 1.8) - (document.body.clientwidth / 6) / 5
p.innertext = noOfMoves
checkDocWidDiv.innertext = CInt (document.body.clientwidth / 1.8)
if n = 0 Then
EntLuck.innertext = "Please enter luck"
End if
Org1Pic(1) = "Org Gradients/Org11.gif"
Org1Pic(2) = "Org Gradients/Org10.gif"
Org1Pic(3) = "Org Gradients/Org9.gif"
Org1Pic(4) = "Org Gradients/Org8.gif"
Org1Pic(5) = "Org Gradients/Org7.gif"
Org1Pic(6) = "Org Gradients/Org6.gif"
Org1Pic(7) = "Org Gradients/Org5.gif"
Org1Pic(8) = "Org Gradients/Org4.gif"
Org1Pic(9) = "Org Gradients/Org3.gif"
Org2Pic(1) = "2ndOrgGradients/2ndOrg9.gif"
Org2Pic(2) = "2ndOrgGradients/2ndOrg8.gif"
Org2Pic(3) = "2ndOrgGradients/2ndOrg7.gif"
Org2Pic(4) = "2ndOrgGradients/2ndOrg6.gif"
Org2Pic(5) = "2ndOrgGradients/2ndOrg5.gif"
Org2Pic(6) = "2ndOrgGradients/2ndOrg4.gif"
Org2Pic(7) = "2ndOrgGradients/2ndOrg3.gif"
Org2Pic(8) = "2ndOrgGradients/2ndOrg2.gif"
Org2Pic(9) = "2ndOrgGradients/2ndOrg1.gif"
Org3Pic(1) = "2ndOrgGradients/3rdOrg9.gif"
Org3Pic(2) = "2ndOrgGradients/3rdOrg8.gif"
Org3Pic(3) = "2ndOrgGradients/3rdOrg7.gif"
Org3Pic(4) = "2ndOrgGradients/3rdOrg6.gif"
Org3Pic(5) = "2ndOrgGradients/3rdOrg5.gif"
Org3Pic(6) = "2ndOrgGradients/3rdOrg4.gif"
Org3Pic(7) = "2ndOrgGradients/3rdOrg3.gif"
Org3Pic(8) = "2ndOrgGradients/3rdOrg2.gif"
Org3Pic(9) = "2ndOrgGradients/3rdOrg1.gif"
End Sub
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
End Sub
Sub checkLuck_OnClick()
n = entluck.value
LuckRes.innertext = n
End Sub
</script>
</head>
<body bgcolor="000000">
<div id="bg"><img id="backGround" src="OrgBackG.jpg" width="100%" height="100%"/></div>
<div id="content">
<img id="startbtn" style="position: absolute" src="startBtn.jpg" height="25"/>
<img id="Org" style="position: absolute" src="Org Gradients/Org1.gif" height="60"/>
<img id="Luck1" style="position: absolute" src="Luck Buttons/Luck1.gif" height="40"/>
<img id="Luck2" style="position: absolute" src="Luck Buttons/Luck2.gif"height="40"/>
<img id="Luck3" style="position: absolute" src="Luck Buttons/Luck3.gif" height="40"/>
Random number:<input type="text" id="xVal" style="width:auto;"/>
Number total:<input type="text" id="yVal" style="width:auto;"/>
Number of moves?<input type="text" id="p" style="width:auto;" />
Number of moves?<input type="text" id="ss" style="width:auto;"/>
Average:<input type="text" id="average" style="width:auto;"/><br/>
<input type="text" id="Entluck"/><input type="button" id="checkLuck" value="Check Luck"/><input type="text" id="LuckRes"/><br/>
Clientwidth / 1.8:<input type="text" id="checkDocWidDiv"/><br/>
</div>
</body>
</html>
Hi,
Whatever code you have pointed, I guess, there should not be any space between "Else" and "If"..
Check this :
Regards
Veena
Whatever code you have pointed, I guess, there should not be any space between "Else" and "If"..
Check this :
vb Syntax (Toggle Plain Text)
if RandomOrg = 1 Then Org.src = Org1Pic(Luck) Elseif RandomOrg = 2 Then Org.src = Org2Pic(Luck) Elseif RandomOrg = 3 Then Org.src = Org3Pic(Luck) End if
Regards
Veena
•
•
Join Date: Jul 2008
Posts: 9
Reputation:
Solved Threads: 0
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>
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
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
A conclusion is the place where you got tired of thinking. http://www.martin2k.co.uk/forums/index.php?showforum=4
http://www.a1vbcode.com/a1vbcode/vbforums/Forum3-1.aspx
http://www.developerfusion.co.uk/for...orum&ForumID=4
![]() |
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Decode CTCSS via soundcard Help needed
- Next Thread: Accessing Listview items
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





