✅ Help with basic guessing game
Hi guys. I just started programming classes last week and it's all very new to me. This is a guessing game. You have ten tries, the lights on each side tell you if the number you're guessing is higher or lower than the hidden number.
I'm having a hard time even getting started. I have to get the button "Accepter" to work and "Nombre d"essais" has to have a max value of 10 display. I tried;
vsb.NbEssais.Value = 10;
But that just makes my button become the number 10 with the accept button serving no purpose. I'm trying to show the properties in my screenshot. The button's name is "btnAccepter". I'll post the code page too but I doubt it's any help if you don't speak French.
46 Replies
and "Nombre d"essais" has to have a max value of 10 display. I tried; vsb.NbEssais.Value = 10; But that just makes my button become the number 10You're using a button as a label? I don't get it. Setting the value of a label is quite simple
It is a label. I use the word button loosely here, sorry
so the label has to shows how many tries left. So the label value needs to be assigned (changed) each time the button is pressed
The label has to show how many tries you have done, with a maximum of 10 tries
ok. So start it at "0", when you push the button, update the label value. That's the general process
I still can't seem to get this started for the life of me. Everything I try fails.
Nobody can help without details
Every time the "Accepter" button is pressed, the "Nombre d'essais" value has to go up by one to a maximum of 10. I can't figure out how the two link together. The only line I've managed to run without error is
vsiNbEssais.Value = 10;
But that only sets the value of "Nombre d'essais" to 10 without the button doing anything or the number ever changing.
I'm guessing I have to do an if statement but again I get nothing but errors. For example
vsiNbEssais.Value = 0;
if (btnAccepter = true)
{
vsiNbEssais.Value = (vsiNbEssais.Value +1)
}
This is literally from my third class and it's all very overwhelming.
Keep the number in a field or a property, and when the click method runs, increment it and change the label text accordingly
Yeah, I think you're a bit ahead of yourself.
Do you know how buttons and events and event handlers interact?
Quick and dirty pseudocode example:
Nope, I have no idea how those work. The thing is, I know it's simple code to get it to work because well we're on our third class. For example, this was the previous problem (which I managed to solve yay)
Alright I'll ask one last time and if I get no answer I will go to school early and ask the prof. All I'm trying to do is get the counter to start going up every time I click the accept button. I really cannot figure out this logic for the life of me. Pic related is a terrible attempt and the properties of them
Every time the "Accepter" button is pressed, the "Nombre d'essais" value has to go up by one to a maximum of 10. I can't figure out how the two link together.Well you have your btnAccepter_Click method yes? Which is called whenever you click the button You found that doing:
vsiNbEssais.Value = 10;Just sets the value to 10 straight away, so obviously you don't want to do exactly, you instead want to add 1 to the value instead
I'm not sure what method refers to but yes that's my issue
that is a method, and any code inside that method will run when you click the
btnAccepter
buttonWe learned none of this so I don't think it's that. We pretty much learned true/false and if/else so far. That's kind of why I'm tripping balls here
I'm guessing your teacher's supplied all the above code and given you the TODO comments to indicate where your code should be added and what it should be doing, so that you don't strictly need to worry about all those existing parts just yet (I'm not sure my french is basically non existent...)?
so in that method you need to:
1) Check
if
the Value of vsiNbEssais
is less than 10
2) If it is, increase it by 1Yeah that soudns about right
ok, so you said you've been over if/else statements, so you should know the format of what you're entering
and you were given above a line for how to increase the value of something by one:
myValue++;
or you can also do:
myValue += 1;
Does that make sense?Am I getting there? Again it just sets it to 1
Have you clicked the button more than once?
Is that in the right method, should it not be inside
btnAccepter_Click
?
In this case you also don't need the else
statementThe program starts with the number of tries already being 1 and clicking accept does nothing
yes I think because you have your code inside the wrong method, shouldn't it be inside
btnAccepter_Click
? Try moving it there insteadWhat do you mean? We haven't learned anything about click. The accept button itself works right now. When I click it it just does nothing, but it's functional. I have to make the tries number go up when it's clicked
you have the method
btnAccepter_Click
in your file, yes? Can you find it now?
it's in the first screenshot you sentI'm saying, put that new code you've just written inside that method instead
He put us a TO-DO list in order. What you highlighted is the last step (TO-DO 6) where the lightbulb lights up according to if the number you are guessing is higher or lower than the number that is hidden. What I'm trying to do is step 1 which is just initializing the number of tries counter
None of this code is mine
I know, I just think it's not been very clear which part you're trying to work on
So what exactly are you trying to do right now?
One minute I will get his demo exe running and record what I'm trying to do
Ok so, here is the full thing running. All I want to do right now is step 1, which is to get the counter going up (to a max of 10 tries) every time the Accpeter is pressed
vsinbessais
is the label that displays the count?Yes
Labels are usually text, not numbers
You can't exactly increment a string
I'd store the number of clicks in a field
I feel stupid and this is not getting through to me. We really have not learned anything advanced so idk wtf is going on. Sorry for wasting your time fellas. I'll try to see a professor today. I'll update this later I guess if I figure it out.
Starts and stuck on 1 with this
I just told you, you cannot increment the value of a label
Furthermore, label has the
Text
property to set what it shows
Not Value
So... is it even a label?Wdym? Nombre d'essais is VisualInt
tf is
VisualInt
?I have no idea man. I'm sorry but thanks anyways.
I don't know why we're assuming it's some text based control when there's no intellisense showing up when
vsiNbEssais.Value
is used, and it successfully changes the control content, it's clearly some sort of numeric control, so I still say try putting the code you've written inside the btnAccepter_Click
methodYou were absolutely right. I didn’t understand what you meant but after it was explained to me, yeah what you were saying was exactly it. Thanks again.
$close
Use the /close command to mark a forum thread as answered