Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 05-16-2005, 07:27 AM   #1
Beta Member
 
Join Date: May 2005
Posts: 2
Default Need help asap

Hi im new here and i need some help with vb code. I have some code(below) which i have to describe how it works. can anybody help me as i dont have a clue. thanks

------------------------------------
option explicit

dim fsFruits(5) As String
dim fiReels(2) As Integer
dim fiSpins As Integer

Const MAX_SPINS As integer = 10 '2 a second

Const Orange As Integer = 0
Const Pear As integer = 1
Const Grapes As Integer = 2
Const Banana As Integer = 3

Const MAX_FRUITS As integer = 4

Const MAX_REELS As integer = 3

Private sub cmdspin_click()
dim liHoldBtn

fiSpins = MAX_spins

cmdSpin.Enabled = False

timSpin.Enabled = True
End Sub

Private Sub Form_Load()
Randomize


fsFruits(Orange) = "Orange.gif"
fsFruits(Orange) = "pear.gif"
fsFruits(Orange) = "grapes.gif"
fsFruits(Orange) = "banana.gif"

end sub

Private Sub timSpin_Timer()
Dim liCnt As Integer


For liCnt - 0 To MAX_REELS - 1
fiReels(liCnt) = int(Rnd * MAX_FRUITS)
imgReel(liCnt).Picture = Loadpicture(app.path & "\..\fruits\" & fsFruits (fiReels(liCnt)))
Next liCnt

fiSpins = fiSpins - 1

if fiSpins = 0 then
CheckScore
timSpin.Enabled = False
End If
End Sub

Private Sub CheckScore()
Dim liScore As Integer

liScore As Integer

cmdSpin.Enabled = True

if fiReels(0) = fiReels(1) And fiReels(0) = fiReels(2) Then
liScore = liScore +30
ElseIf fiReels(0) = fiReels(1) Then
liScore = liScore +20
ElseIf fiReels(0) = fiReels(2) Then
liScore = liScore +20
ElseIf fiReels(1) = fiReels(2) Then
liScore = liScore +20
End If

lblScore.Caption = liScore


End Sub

---------------------------------------
__________________

wass05 is offline   Reply With Quote
Old 05-16-2005, 07:40 AM   #2
BSOD
 
Computergen's Avatar
 
Join Date: Dec 2004
Posts: 3,175
Default Re: Need help asap

I don't have an idea either but I am guessing it has to do with those fruits and with calculations such as adding.
__________________

Computergen is offline   Reply With Quote
Old 05-16-2005, 10:31 AM   #3
BSOD
 
Masahiro's Avatar
 
Join Date: May 2004
Posts: 1,896
Default Re: Need help asap

.
Masahiro is offline   Reply With Quote
Old 05-16-2005, 12:48 PM   #4
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,006
Default Re: Need help asap

hey masahiro I love the location...

I however am feeling a little nicer than you so I'll help,


option explicit
This is a compalation option it basically means that all variables HAVE to be decalred and you cannot just introduce a variable without declaring it, this is a good idea to turn on as it means if you make a spelling error with a variable it will be reported as a variable that doesn't exist, rather than just assuming it's a new variable.

dim fsFruits(5) As String
Declares the variable name fsFruits as a string 5 chars long
dim fiReels(2) As Integer
Declares the variable fReels as an integer two chars long, (i.e 00 - 99)
dim fiSpins As Integer
declares fspin as an integer, (I.e a non decimal number)

Const MAX_SPINS As integer = 10 '2 a second
Defines MAX_SPIN as a constant, (static variable) -oxymoron there so you might want to reword)

Const Orange As Integer = 0
Const Pear As integer = 1
Const Grapes As Integer = 2
Const Banana As Integer = 3

Definies constant integers (constant meaning does not change, as a variable can change).

Const MAX_FRUITS As integer = 4

Const MAX_REELS As integer = 3
More constants defined, the bonus is that a constant is allocated less memory than a variable.

Private sub cmdspin_click()
A private sub is a subroutine that is private from the rest of the program, it is different from a public sub. this sub is called when the button cmdspin_click is pressed

dim liHoldBtnMakes a variable

fiSpins = MAX_spinsDoes nothing since the variable in question is MAX_SPINS, though the option explicit will pick this up.
what is it meant to do is assign the value in MAX_SPINS to fiSpins

cmdSpin.Enabled = FalsecmdSpin is an object on the form, (a button) it is clicked to call this subroutine, once it has been clicked it is diabled to prevent further clicking.

timSpin.Enabled = TrueI'll assume this is a button that is disabled on the form load, (you should really describe more about the form)
Anyway this just enables the button

End Subends the subroutine.


Private Sub Form_Load() Private subroutine that is run when the form is loaded


Randomize
a VB function for generating random numbers!

fsFruits(Orange) = "Orange.gif"
fsFruits(Orange) = "pear.gif"
fsFruits(Orange) = "grapes.gif"
fsFruits(Orange) = "banana.gif"
setting the variables

end subend subroutine

[b]
Private Sub timSpin_Timer()[b] where I assumed timSpin was a button it's actually not it's a timer, when the first button is clicked the timer is enabled and starts counting down, when it reaches zero this subroutine is run.

Dim liCnt As Integer
declare integer variable


For liCnt - 0 To MAX_REELS - 1
set up loop.
fiReels(liCnt) = int(Rnd * MAX_FRUITS)
imgReel(liCnt).Picture = Loadpicture(app.path & "\..\fruits\" & fsFruits (fiReels(liCnt)))
Next liCnt
Loop through the four reels selecting a rndom picture for each (the rnd * MAX_FRUITS selects the random picture.
the variable used in the loop is liCnt (this is the reel position count) this increments 1 to four (for each reel)
the line imgRels(licnt) simply selects the graphic imgreels(reel number) and loads an image.

fiSpins = fiSpins - 1 decrement the counter that is tracking spins, this makes sure the spinner changes 10 times

if fiSpins = 0 then find out if 10 spins have been done
CheckScore if 10 spins have been done then check the score
timSpin.Enabled = False disablethe timer to stop this function from running
End If
End Sub

end the 10 spins checknig bit and end the sub routine, if there have not been 10 reel changes then the timer will count down to zero and the function will rnu again.

Private Sub CheckScore() subfunction for checking the score
Dim liScore As Integer Declare a new integer.

liScore As Integer not sure why the integer would be declared twice? any ideas?

cmdSpin.Enabled = True enable the spin button so the user can have another go.


if fiReels(0) = fiReels(1) And fiReels(0) = fiReels(2) Then
liScore = liScore +30
ElseIf fiReels(0) = fiReels(1) Then
liScore = liScore +20
ElseIf fiReels(0) = fiReels(2) Then
liScore = liScore +20
ElseIf fiReels(1) = fiReels(2) Then
liScore = liScore +20
End If
check the scores on the reels.

lblScore.Caption = liScore fill a labe box with the scre generated by the reels.


End Sub end sub routine.
root is offline   Reply With Quote
Old 05-17-2005, 05:57 PM   #5
Beta Member
 
Join Date: May 2005
Posts: 2
Talking Cheers

top man much appreciated.
wass05 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 05:58 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0