Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2007
Posts: 11
Reputation: k8f1 is an unknown quantity at this point 
Solved Threads: 1
k8f1 k8f1 is offline Offline
Newbie Poster

Please help!

 
0
  #1
Nov 4th, 2008
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>
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 65
Reputation: bushman_222 is an unknown quantity at this point 
Solved Threads: 4
bushman_222's Avatar
bushman_222 bushman_222 is offline Offline
Junior Poster in Training

Re: Please help!

 
0
  #2
Nov 5th, 2008
When does it stop, on what line
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: Please help!

 
0
  #3
Nov 5th, 2008
Hi,

Whatever code you have pointed, I guess, there should not be any space between "Else" and "If"..
Check this :
  1. if RandomOrg = 1 Then
  2. Org.src = Org1Pic(Luck)
  3. Elseif RandomOrg = 2 Then
  4. Org.src = Org2Pic(Luck)
  5. Elseif RandomOrg = 3 Then
  6. Org.src = Org3Pic(Luck)
  7. End if

Regards
Veena
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 9
Reputation: vponline is an unknown quantity at this point 
Solved Threads: 0
vponline vponline is offline Offline
Newbie Poster

Re: Please help!

 
0
  #4
Nov 5th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 11
Reputation: k8f1 is an unknown quantity at this point 
Solved Threads: 1
k8f1 k8f1 is offline Offline
Newbie Poster

Re: Please help!

 
0
  #5
Nov 5th, 2008
Thank you all for your help!

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!

Thanks,

Kate
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 300
Reputation: jireh is an unknown quantity at this point 
Solved Threads: 43
jireh's Avatar
jireh jireh is offline Offline
Posting Whiz

Re: Please help!

 
0
  #6
Nov 5th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 9
Reputation: vponline is an unknown quantity at this point 
Solved Threads: 0
vponline vponline is offline Offline
Newbie Poster

Re: Please help!

 
0
  #7
Nov 5th, 2008
agreed i use tab spaces automatically ,i also added mouse scroll dll to be loaded aswell,seeing vb ignores the mouse wheel while loaded
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC