dcsimg
Results 1 to 18 of 18

Thread: count box to box values using backcolor

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2019
    Posts
    7

    count box to box values using backcolor

    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.

  2. #2
    Lively Member
    Join Date
    May 2017
    Posts
    69

    Re: count box to box values using backcolor

    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.

  3. #3
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,520

    Re: count box to box values using backcolor

    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

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,455

    Re: count box to box values using backcolor

    Welcome to the forums

    Sounds like you want a sorting routine? There are plenty of examples on this site. But as already said, not really sure what you are asking for.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2019
    Posts
    7

    Re: count box to box values using backcolor

    I'm definitely using VB6 visual basic 6.

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2019
    Posts
    7

    Re: count box to box values using backcolor

    this is my game form pics file in vb6. im using a sample of seven times to roll box to box.
    Attached Images Attached Images   

  7. #7
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,171

    Re: count box to box values using backcolor

    Ah....Crystal Clear.

    NOT!

  8. #8
    Fanatic Member
    Join Date
    Nov 2017
    Posts
    827

    Re: count box to box values using backcolor

    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.

  9. #9

    Thread Starter
    New Member
    Join Date
    Sep 2019
    Posts
    7

    Re: count box to box values using backcolor

    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.

  10. #10
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,171

    Re: count box to box values using backcolor

    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
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by SamOscarBrown; Sep 30th, 2019 at 04:56 AM.

  11. #11
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,520

    Re: count box to box values using backcolor

    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:
    Code:
    Cmd Btn: 25, 24, 34, 37, 36, 35, 37
    Values:   1,  5,  6,  1,  6,  0,  1
    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

  12. #12

    Thread Starter
    New Member
    Join Date
    Sep 2019
    Posts
    7

    Re: count box to box values using backcolor

    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.
    Attached Images Attached Images   

  13. #13
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,171

    Re: count box to box values using backcolor

    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?

  14. #14

    Thread Starter
    New Member
    Join Date
    Sep 2019
    Posts
    7

    Re: count box to box values using backcolor

    Quote Originally Posted by SamOscarBrown View Post
    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.

  15. #15
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,171

    Re: count box to box values using backcolor

    So---the object of the game is to find out the LONGEST string of command buttons one can legally make? Yes? If so, interesting....

  16. #16
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,520

    Re: count box to box values using backcolor

    Quote Originally Posted by TravismarkI View Post
    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

  17. #17

    Thread Starter
    New Member
    Join Date
    Sep 2019
    Posts
    7

    Re: count box to box values using backcolor

    Quote Originally Posted by TravismarkI View Post
    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.
    Attached Files Attached Files
    • File Type: zip 1.zip (2.0 KB, 11 views)

  18. #18
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,520

    Re: count box to box values using backcolor

    Quote Originally Posted by TravismarkI View Post
    so far this is what ive done but still missing some elements.
    Apparently they are all missing. I get a message that either there are no files in the zip, or the zip is corrupt.
    "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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width