Shoutbox

Command Button VB Help - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Command Button VB Help (/showthread.php?tid=43807)

Command Button VB Help by mwe99 on 04-28-2005 at 05:15 PM

Hello, i have to create a game of Mastermind, does anyone know how in Visual Basic

[Image: mm1xo.jpg]


Does anyone know how i can make the colour when clicked, appear in the box below?

Thanks


RE: Command Button VB Help by .blade// on 04-28-2005 at 05:25 PM

I haven't done VB for a while, but this is a fairly simpel way to do it :P

I'm going to call:
The buttons you click by the colours they are.
The choices (at the bottom) "C1", "C2", "C3" and "C4"
The variable "selector" will represent what choice you are on

Put this in the different color buttons.

code:

"C" & selector.backcolor="&H80000007&"
If selector =< 4 then
selector = selector + 1
end if



RE: Command Button VB Help by Stigmata on 04-28-2005 at 05:27 PM

code:
Dim blank1set, blank2set, blank3set, blank4set As Boolean
Public Sub Blue_click()
If blank1set = True Then
    If blank2set = True Then
        If blank3set = True Then
            blank4.BackColor = &HFF0000
            blank4set = True
        Else
            blank3.BackColor = &HFF0000
            blank3set = True
        End If
    Else
        blank2.BackColor = &HFF0000
        blank2set = True
    End If
Else
    blank1.BackColor = &HFF0000
    blank1set = True
End If

End Sub

something like that?
RE: Command Button VB Help by mwe99 on 04-28-2005 at 05:30 PM

lol wow am i confused :P

so do i put all the code in the button that is white or the actual coloured button?

the boxes are called:

cmdred
cmdblue
cmdgreen                     MAIN BOXES
cmdyellow
cmdblack
cmdwhite

cmdfinal1
cmdfinal2                     WHITE BOXES
cmdfinal3
cmdfinal4


RE: Command Button VB Help by .blade// on 04-28-2005 at 05:37 PM

quote:
Originally posted by mwe99
lol wow am i confused :P

so do i put all the code in the button that is white or the actual coloured button?

the boxes are called:

cmdred
cmdblue
cmdgreen                     MAIN BOXES
cmdyellow
cmdblack
cmdwhite

cmdfinal1
cmdfinal2                     WHITE BOXES
cmdfinal3
cmdfinal4



For my code to work you have to rename "Cmdfinal" 1-4 to "C" 1-4.
RE: Command Button VB Help by mwe99 on 04-28-2005 at 05:39 PM

When i do i get an error saying Syntax Error and the

Private Sub cmdred_Click()
"C" & selector.backcolor="&H80000007&"

is highlighted in red


wooo i got it working :D

Cmdfinal1.BackColor = Cmdred.BackColor


RE: Command Button VB Help by .blade// on 04-28-2005 at 05:42 PM

Did you define selector?


RE: Command Button VB Help by mwe99 on 04-28-2005 at 05:45 PM

Nope i did it the different way... i just need a way to get the buttons when its filled to move on to the next box now gr


RE: Command Button VB Help by Stigmata on 04-28-2005 at 05:47 PM

"C" & selector.backcolor="&H80000007&"


the back colour is long not a string

put

"C" & selector.backcolor= &H80000007&

vb will automaticly change it to the right colour value :)


RE: Command Button VB Help by mwe99 on 04-28-2005 at 05:52 PM

nope still comes up red... here look

it doesn't seem to like the & sign

i have the colour going in the box... i just need something to tell the other colours to go to the next box

so after cmdfinal1 has been filled, automatically make the next colour go to cmdfinal2


RE: Command Button VB Help by .blade// on 04-28-2005 at 06:03 PM

quote:
Originally posted by mwe99
nope still comes up red... here look

it doesn't seem to like the & sign

i have the colour going in the box... i just need something to tell the other colours to go to the next box

so after cmdfinal1 has been filled, automatically make the next colour go to cmdfinal2




Well try this code:

(If your version of VB recognises "ME" - otherwise replace "me" with the box name)

code:

"C" & selector.backcolor = me.backcolor
If selector =< 4 then
selector = selector + 1
end if



RE: Command Button VB Help by mwe99 on 04-28-2005 at 06:09 PM

Whats the selector then? the cmdfinal1 ?


RE: Command Button VB Help by .blade// on 04-28-2005 at 06:12 PM

quote:
Originally posted by mwe99
Whats the selector then? the cmdfinal1 ?




:| I told you before - selector is a variable with a number which is between 1 and 4. Every time a colour is picked, the number goes up - so that C & selector always gives you the right selection.
RE: Command Button VB Help by Millenium_edition on 04-28-2005 at 06:15 PM

if you would have used arrays of buttons, you'd only have to write one procedure and it would have been much easier. :-/


RE: Command Button VB Help by segosa on 04-28-2005 at 09:08 PM

code:

"C" & selector.backcolor = me.backcolor
If selector =< 4 then
selector = selector + 1
end if



I really can't see how that's meant to work. It's not logical, and it obviously doesn't work as mwe has said three times it highlights it in red.

What is ""C" & selector.backcolor "? You can't dynamically concatenate a backcolor onto the end of a string and set it to something. You make no sense.
RE: Command Button VB Help by CookieRevised on 04-29-2005 at 08:41 AM

quote:
Originally posted by mwe99
lol wow am i confused :P
no wonder :P

First of all disregard everything Blade has said... sorry Blade, but yours make no sense at all. As Segosa said, that isn't even logic programming code.

quote:
Originally posted by Millenium_edition
if you would have used arrays of buttons, you'd only have to write one procedure and it would have been much easier. :-/
indeed. And this is the way to go for something like this...

code:
Option Explicit

Dim CurrentBox As Byte

Private Sub Form_Load()
  CurrentBox = 1
  Call ClearBoxes
End Sub

Private Sub cmdColor_Click(Index As Integer)
  cmdFinal(CurrentBox).BackColor = cmdColor(Index).BackColor
  CurrentBox = CurrentBox + 1
  If CurrentBox = 5 Then
    Call Validate
    '
    CurrentBox = 1
    Call ClearBoxes
  End If
End Sub
see attached zip for full example code
RE: Command Button VB Help by mwe99 on 04-29-2005 at 07:09 PM

It still makes the code red:s

i don't know why but its not seeming to accept the code so i deleted the code,


i attached this to see if anyone can see the solution.


RE: Command Button VB Help by CookieRevised on 04-30-2005 at 02:20 AM

quote:
Originally posted by mwe99
It still makes the code red:s

i don't know why but its not seeming to accept the code so i deleted the code
We said to disregard Blade's code as that isn't even logical programming code and will never work in any programming language.

quote:
Originally posted by mwe99
i attached this to see if anyone can see the solution.
1) The code you're working in is "VBA" (aka "Visual Basic for Applications"). This is not the same as "Visual Basic" which we were all talking about (although many things are similar)!

2) Look at my code which I attached in the zipfile in my previous post and the related comments... The thing you need to change is to add the code for the colorbutton to each individual color button on your form, as VBA doesn't support array's of controls, the rest of the principle is just the same.
EDIT: I've edited your Excel sheet with working code for that particular form (see attachment in this post).