MedVision ad

VB Problem (2 Viewers)

Fosweb

I could be your Doctor...
Joined
Jun 20, 2003
Messages
594
Location
UNSW. Still.
Gender
Male
HSC
2003
vbCtrlMask is a way of telling if the control key has been pressed. It returns value of 2 if true.

If shift is pressed, then it (the Shift which is dim'd in the KeyDown action) returns a positive value (didnt have time to check what sorry).

What this line is saying is:
CtrlDown is True IF Shift and vbCtrlMask > 0

By checking if the total value is greater than 0, you can tell if these keys have been pressed. (ie: if the keys haven't been pressed, then the values stay at 0, therefore the it wouldnt be greater than 0, and ctrlDown would be false.
(Sorry - that was rushed - and probably complete crap...)

Overall: To make it more understandable: You can rewrite this line, and the others as:

Code:
If (Shift And vbShiftMask) > 0 Then ShiftDown = True
If (Shift And vbAltMask) > 0 Then AltDown = True
If (Shift And vbCtrlMask) > 0 Then CtrlDown = True
(NB... I dont know why MS dim'd them as variants to start off with... they try to teach stuff... but its always too complicated... I dont think there is any performance difference this way, is there? And this is easier to understand anyway...
Sunny? Maybe you could answer that...)
 

Kn1ght_M4r3

Member
Joined
Mar 3, 2003
Messages
332
Location
D o w n l o a d C o m p l e t e .....
0ooh i knew the vbnewline stuff. but thankz again for it fosweb =0)
and i kinda understand the code:

CtrlDown = (Shift And vbCtrlMask) > 0
a bit better now. I didn't have a clue what it was going on about reading the msdn site. heheheeh
but thankz again Fosweb you have cleared things up for me.
:D
 

Fosweb

I could be your Doctor...
Joined
Jun 20, 2003
Messages
594
Location
UNSW. Still.
Gender
Male
HSC
2003
That goes against standard control structures...

Can you give some surrounding code, and reasons why, and i'm sure there is a better way...
 

Olivia

New Member
Joined
May 23, 2003
Messages
22
Location
Sydney
Thank you for your advice

Well I'm creating a game called Hide 'n' Seek, as the title suggested this game is base on the children game Hide 'n' Seek.

Oh yeah, the characters in my game is a cat and 10 mice for level 1, 11 mice for level2, 12 mice for level 3, 13 mice for level4. And each level have a time limit of 1 min.

So for the time limit do I use

code:--------------------------------------------------------------------------------
private sub timer()
timCount = timCount + 1
If timCount = 60 then timer.enabled = false
end sub

I have problem making the mouse/mice move around the screen randomly, and make it hide. Do I need an array?

I wrote something like this in VB under the timer
Private Sub tmrRun_Timer()
picmouse1.Top = picmouse.Top - 100

what happened was that the picmouse1 move down the screen and dissappeared. How do I make it reappear? I also tried the Select Case function ie. Set up a random number and if a particular number is reached then it will move up, down, left or right. But it didn't work as well.

What should I do?

If I want to hide the mouse/mice randomly for a short time, do a use random number?

After the cat had caught the mouse/mice, I wanted to produce a report so that the user know how many mouse/mice they have caught.
 

Fosweb

I could be your Doctor...
Joined
Jun 20, 2003
Messages
594
Location
UNSW. Still.
Gender
Male
HSC
2003
So: you have two timers. One controlling random movement and one for the time limit.

Time limit is fine. Just add all the code for what happens when 60 seconds is up in the If timCount = 60 then bit...

(Before I explain: why is it moving down screen in that case? It should be going up scree... (i.e. with -100). So: assume that your picmouse is moving downscreen by going .top + 100 for my explanation)
For moving off screen: you need to make sure that the (.top + .height) of the picmouse1 is never greater than the .Height of your form. You could then reverse the direction, so that the picmouse moves the other way... You can do this for every side of the form using combinations of [.top & .height] and [.left & .width]

So you need to check this every time you move the picmouse1.
Code:
If (picmouse1.top + picmouse1.height) > YOURFORM.height THEN
picmouse1.top = picmouse1.top - 100
Endif
This will reverse the direction (i.e. by reversing the + 100 to -100)

In the case of what should you do:
Why not set your mouse to BEGIN moving on some simple mathematical function, like say, x^2 ( that exactly may not work... you will need a more linear function... ). Set up the randomness by generating a random number and putting this into the equation to start its movement. (It can be more complicated if you try to do this... you will need to change more stuff when you try to reverse direction, like - sign(s) of the function you are using...)
Then reverse direction when it hits the sides of the form. Start the mice in different positions.

To hide mice, cant you just make the .visible property of the picmouse =False, then turn it back on after an amount of time?
You would use a random number, and another counter such as in the first bit of timer code. When the counter reaches that number, then make it visible again.

I hope this has helped and not complicated things. :) (IF it has - then forget the bit about moving randomly using a function such as x^2, that was just an idea...)
 

Olivia

New Member
Joined
May 23, 2003
Messages
22
Location
Sydney
Thanks

I tried to set up a random number for the direction of the mouse to change. However, it changes very quickly ie. the pic is flashing on the screen and not move. Do I have to set up a time for the random number to change? So that it will not change as rapidly?

And do I need an array to add the no. of mice caught?
 

Fosweb

I could be your Doctor...
Joined
Jun 20, 2003
Messages
594
Location
UNSW. Still.
Gender
Male
HSC
2003
You could just add another timer - yeah...

On counting: Why would you need an array?
Counting is just a matter of: countVar = countVar + 1
However, for recording how many mice are caught on each level, you could add the results of this count on each level into an array.

Maybe you should read up a bit on arrays in your sdd text, or a programming book...
 

Olivia

New Member
Joined
May 23, 2003
Messages
22
Location
Sydney
:eek: Do I sound really dumb?

Thank you for helping me sort things clear!

I figured out how to stop the pic from flashing on the screen ie. to make the pic move faster.

yeah that's right, I meant an array to record the number of mice are caught on each game. Thanks.

However, I still don't understand on how to create an array of record. For example, I have to store 20 records, each under Name, Level, score, time, mice No.

Do I code:

Dim I As Integer

Static Records (1 To 20, 1 To 5) As Variant
Records (I,1) = Name of player
Records (I,2) = Level
& etc. for the others

Is 'Records' a keyword in VB? Can I code it like that? :confused:
 

del

Member
Joined
Jul 8, 2002
Messages
412
Gender
Undisclosed
HSC
N/A
you have to create a user defined type that defines your record struture (define it in a seperate module)

Code:
Type levelDetails   (or something more meanigful to your game)
    name as String
    score as Integer
    time as Integer
    miceCaught as Integer
End Type
I don't think you need to store the level, as when u access the array, the index could be used to determine the level at the same time


then to create the array

Code:
Dim levelScores(1 to 20) as levelDetails
then you access each field of the record in the form of:

levelScores(element accessing).field name

where element accessing is whatever your index is, and field name is one of the fields of the record.

e.g

levelScores(1).time


hth, i haven't used vb in a while :p
 

Users Who Are Viewing This Thread (Users: 0, Guests: 2)

Top