Hello everyone!!!
I'm new to this forum site. I just started using visual basics a while ago but still learning the basics if, then, not, and, or, not, else, etc.
I need some help designing a game, kind like switching option game.
This game uses 49 click command buttons which each has a different caption value which I generate randomly with a code I already made. I need to count the values from box to box using backcolor as a way to track each time it counts from lower to high value the box backcolor also changes.
I'm still learning but I need a mentor to guide me.
It's unclear what you actually want to achieve. Arbitrarily changing BackColour to store a value will create a riot of colours.
As you say you're a beginner, I suggest you research Control Arrays and using the Index property to identify which command button has been pressed.
Then store your 'count value' either in a numeric array using the same index value as the control array index. Or you could look at storing your value in the .Tag property of the command button.
Code snippet:
Code:
' Increment .Tag each time the Commmand button is pressed
'
Private Sub cmdCommand_Click(Index As Integer)
Me.cmdCommand.Item(Index).Tag = Val(Me.cmdCommand.Item(Index).Tag) + 1
Debug.Print Me.cmdCommand.Item(Index).Tag
End Sub
Last edited by MikeSW17; Sep 29th, 2019 at 06:17 AM.
Also, since you're a beginner, I would want to confirm you're using VB6, and not one of the VB.Net versions when you're saying you're using Visual Basic. They are different languages, and questions for them are in different parts of the forum.
What does the code you've written so far look like.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
OP - Your example image doesn't really explain what it is your code is supposed to be doing as far as I can tell.
Here's a tip. Remember that everyone that tries to offer help on this site is doing so for free in their own spare time. That being said, when people come into a thread and find that the person seeking help hasn't done a great job explaining what exactly they are looking for, they have three options:
1. Attempt to help by taking a wild guess about what the problem is and offer a solution via code
Result: Almost always, the suggestion offered is not what the thread creator was looking for, and the person who offered their help wasted their time.
2. Attempt to help by posting followup questions seeking clarification as to what the problem actually is
Result: Sometimes the thread creator clarifies the issue well, most of the time they don't, and the person who asked for clarification wastes their time going back and forth with the thread creator trying to get a better idea of what the thread creator is truly trying to accomplish.
3. Close the thread because they've done option 1 or 2 multiple times in the past and have vowed to not do that again because it ends up being too much of a time sink.
In your OP you mentioned needing a mentor. I'm not sure if you'll find someone willing to be that for you here. That sounds like a fairly large time/availability commitment. If you browse around some of the other threads, most of the content here is people asking very specific questions about writing code that is intended to do xyz, it isn't working right, they post the code they've written, and people try to help.
So, what I would suggest, clarify to excruciating detail what the rules of your game are, post the code you are currently using, and maybe then someone will be able to offer helpful assistance.
No, is not a diamond neither stars constellation coordinates, its just a simple example how the game should work. When i press count sever times, it should start counting seven times from command25, each time it counts commandclick. Backcolor changes as it counts up to sever times.
Am not sure what you really want, but attached is an example possibly close to your desires:
Look at this image, however. You will see 13 commandbuttons have changed color, even though I selected the "Count 14 times" button. That is because I did not check for duplicates when I did the RND function. You will have to solve that one on your own (easy to do, but want to see YOUR efforts).
Code:
Code:
Option Explicit
Dim gNumCounts As Integer
Private Sub Command3_Click()
setDefaultColors
gNumCounts = 14
Timer1.Enabled = True
End Sub
Private Sub Command4_Click()
setDefaultColors
gNumCounts = 7
Timer1.Enabled = True
End Sub
Private Sub Command5_Click()
setDefaultColors
Dim rannum As Integer
rannum = Int(48 * Rnd)
Command1(rannum).BackColor = RGB(0, 193, 192)
End Sub
Private Sub setDefaultColors()
Dim x As Integer
For x = 0 To 48
Command1(x).BackColor = RGB(240, 240, 240)
Next x
End Sub
Private Sub Form_Load()
Randomize
genRandom
End Sub
Private Sub genRandom()
Dim myValue As Integer
Dim y As Integer
For y = 0 To 48
myValue = Int((9 * Rnd)) ' Generate random value between 1 and 48.
Command1(y).Caption = CStr(myValue)
Next y
End Sub
Private Sub Timer1_Timer()
Static x As Integer
x = x + 1
Dim rannum As Integer
rannum = Int(48 * Rnd)
Command1(rannum).BackColor = RGB(0, 193, 192)
If x = gNumCounts Or x > gNumCounts Then
x = 0
Timer1.Enabled = False
End If
End Sub
Last edited by SamOscarBrown; Sep 30th, 2019 at 04:56 AM.
Well, I don't know if your diagram in post 6 is suppose to be showing "one move", or six moves.
I can see a pattern as far as the Count 7 Times is concerned, i.e. the player selects Count 7 Times, and then clicks on Command25.
It looks like you would then pick a random button that surrounds command25, and decrement (or increment) your count, depending on which way you like to count off the selected "distance". You then repeat this using the selected button as you start point, until you have "step" the number of the count selected.
You diagram looks like it is showing six paths of seven steps, which ended up in five different locations. The paths can step on the same point more than once.
You mention changing the backcolor when the step goes from a lower to higher value.
So, assuming your diagram is showing six possible examples, and we just take one of them, then it looks like one path would be:
So, one question would be which button do you want to change color.
Cmd 25 to 24, is from value 1 to 5, so that is a low to high transition, so you want to change the background color, but which box, 25 or 24 or both?
Then 24 goes to 34, which is value 5 to 6, so another background color change is in order.
34 to 37, goes from value 6 to 1, so no background change.
37 to 36 (1 to 6) change background
36 to 35 (6 to 0) no change
35 to 37 (0 to 1) change background
So the final destination of that path happens to be 37, it it also happens to be higher then the previous box so should it be changed?
Also, since you can step over yourself in your path, it would be possible for the box to have been changed earlier because of a low to high value step, but later you step on it again, and you may be going from a high to low.
I'm not sure of the point of highlighting the boxes when only changing from low to high as it may not be easy to deduce the steps taken to get there as you don't may not have a continuous path displayed.
Doesn't seem like a fun game at the moment.
p.s. Perhaps there is a bit of a language issue here, and I'm interpreting the low to high meaning incorrectly. Perhaps you're just saying that for the given count, as you count up and move to the next adjacent box, you want to highlight the move by changing the background color of the box moved to, in which case that makes more sense. I assume that with each click of the button you want to start from, the previous path should be cleared so that the new path is somewhat obvious. I say somewhat because since the path can double back on itself, you can't always tell the real sequence of steps that were taken. Assuming you're showing six examples, it looks like only one of the six actually doubled back, so you can be sure if it went (37,36,35,37) or (37,35,36,37). All the other paths are determinable and two of them appear to share the first six steps.
Last edited by passel; Sep 30th, 2019 at 12:07 PM.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
Thank you for your support friend. i don't need the code to generate, i already had it and modified well enough for this game project.
I just need something that will switch color every time it counts up from the surrounding numbers in every box. im posting two sample pictures. one couting one time and another 4 times.
The start point should be always from any box in the corner of the game, this one is starting counting from the bottom right side. thanks again.
Care to share your project? Would be far easier to make suggestions if we had the code.
BUT, TO ME, the issue is not very well explained (maybe others can decipher).
Maybe I can figure it out...is this correct (for your example)?---starting in (in this case) the bottom right corner (command1), ....NOPE...can't....
from 1 to 6-7-8-0 (ok...got that one), but, 1 to 6-8-0 (no 7)...okay, maybe I see your example, but logic???
Let's see start at some number (an adjacent button to the start button)...from there count until one gets to 0 (IOW TEN)--can skip numbers along each path. Right?
If so, let me see if I can start in bottom left (command7--coincidentally its caption is 7 in this case). The only option I see is to go to 0 (command6) as the "4" and "6" captions are not increasing. CORRECT?
Care to share your project? Would be far easier to make suggestions if we had the code.
BUT, TO ME, the issue is not very well explained (maybe others can decipher).
Maybe I can figure it out...is this correct (for your example)?---starting in (in this case) the bottom right corner (command1), ....NOPE...can't....
from 1 to 6-7-8-0 (ok...got that one), but, 1 to 6-8-0 (no 7)...okay, maybe I see your example, but logic???
Let's see start at some number (an adjacent button to the start button)...from there count until one gets to 0 (IOW TEN)--can skip numbers along each path. Right?
If so, let me see if I can start in bottom left (command7--coincidentally its caption is 7 in this case). The only option I see is to go to 0 (command6) as the "4" and "6" captions are not increasing. CORRECT?
Am I getting CLOSER?
The point is to always count to the next greater value in the sorroundings of every textbox no matter what number you in and also use 0 to 9, cannot exceed 9, must start from 0 to 9 in case you in a textbox that has ""9", you start looking for the 0, 1,2,3,4,5,6,7,8,9
That's why I'm trying to make this game unique than others.
Thank you for your support friend. i don't need the code to generate, i already had it and modified well enough for this game project.
I just need something that will switch color every time it counts up from the surrounding numbers in every box. im posting two sample pictures. one couting one time and another 4 times.
The start point should be always from any box in the corner of the game, this one is starting counting from the bottom right side. thanks again.
I don't understand. If you already have all the code and logic to step from box to box, why is adding a line to change the backcolor of the box you stepped to a sticking point, i.e.
box.Backcolor = someColor
seems like a fairly simple line to add.
Also, if you already have it figured out, then I guess we don't need to know what you do when there are two paths that can be taken, i.e. you mention that you start from a corner, so using the upper left corner, the sequence would be 4,8,1,2,3,4 and then you have two boxes with 5 in them adjacent to the 4, which one would you choose? I suppose since you have it figured out, it shouldn't matter to us. All you want help with is changing the background color as you step from box to box. I really don't understand why that is a problem.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
Hello everyone!!!
I'm new to this forum site. I just started using visual basics a while ago but still learning the basics if, then, not, and, or, not, else, etc.
I need some help designing a game, kind like switching option game.
This game uses 49 click command buttons which each has a different caption value which I generate randomly with a code I already made. I need to count the values from box to box using backcolor as a way to track each time it counts from lower to high value the box backcolor also changes.
I'm still learning but I need a mentor to guide me.
so far this is what ive done but still missing some elements.