[RESOLVED] Simple if statement problem
:wave:
I'm trying to create a soccer prediction program for someone else on another forum. I've managed to do the easy bit, just slightly confused over what to do next.
Points are given out for every result you predict correctly, with bonus points on offer if you get the correct scoreline as well
- 2 points are won for guessing the correct result, i.e. Home win, Away win, or Draw.
- 3 extra points for guessing the correct scoreline
Those are the rules.
The preson will enter the predicted scorelines in one set of textboxes, and then enters the real scorelines in another set of text boxes.
Click me to see form
VB Code:
Private Sub cmdcalculate_Click()
Dim totalpoints As Integer
If user1.Text = real1.Text And user2.Text = real2.Text Then
totalpoints = 5
End If
lbloutput.Caption = totalpoints
End Sub
That works fine if they predict the first scoreline correctly, but I'm stuck on what code to use for the correct result.
Any help?
Re: Simple if statement problem
Welcome to the forums. :wave:
I'm not completely sure I understand your question, so this may be way off, but it appears to me as though you are asking how to have them select Home Win, Away Win and Draw. Is that correct?
If so, you could you a group of three option buttons.
Re: Simple if statement problem
In essence, yes.
Would I still be able to have the correct scoreline option if I used option buttons as well?
Re: Simple if statement problem
Quote:
Originally Posted by dragonskin
In essence, yes.
Would I still be able to have the correct scoreline option if I used option buttons as well?
On the surface, it appears to me as though you have the scoreline figured out all ready. What effect would selecting one of the option buttons have on that?
Re: Simple if statement problem
I'm not sure, that's why I was asking you :)
Re: Simple if statement problem
Quote:
Originally Posted by dragonskin
I'm not sure, that's why I was asking you :)
No effect that I can see.
The only thing is that you will probably want to save, or display, their option button choice.
Re: Simple if statement problem
Cheers for the help so far
VB Code:
If Option1 = True And Option4 = True Then
totalpoints = 2
If Option1 = True And Option4 = True And user1.Text = real1.Text And user2.Text = real2.Text Then
totalpoints = 5
End If
End If
That works fine, is there a quick way to do it for the other games as well or will I have to write out those if statements each time?
Re: Simple if statement problem
Quote:
Originally Posted by dragonskin
Cheers for the help so far
VB Code:
If Option1 = True And Option4 = True Then
totalpoints = 2
If Option1 = True And Option4 = True And user1.Text = real1.Text And user2.Text = real2.Text Then
totalpoints = 5
End If
End If
That works fine, is there a quick way to do it for the other games as well or will I have to write out those if statements each time?
Store or display the name of the game along with these. You only have to have this one bit of code (at least from what I understand), so somewhere you would need to have a place (maybe a textbox) that provided the opportunity to log a name.
I re-read your original question. Are you planning on storing this data somewhere? If so where?
Re: Simple if statement problem
I can store it in an Access database.
Re: Simple if statement problem
Quote:
Originally Posted by dragonskin
I can store it in an Access database.
:) Yes, I know you can, but will you be?
This is your application, not mine. What do you want to do with it?
Re: Simple if statement problem
Re: Simple if statement problem
Quote:
Originally Posted by dragonskin
Yes, I will be ;)
Ok. It seems pretty simple. One table with a field for game name, scoreline and result.
You might want to add a fourth field for date played. If you want to get real fancy, you could add another field and put the name of the field or stadium it was played in.
What you store is really up to you.
Re: Simple if statement problem
New problem, trying to connect to my database and it's telling me there's a Syntax error in FROM clause
VB Code:
Public Sub loadrecordset(localrecordset As ADODB.Recordset, sql As String)
localrecordset.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & "\test -1.mdb;"
localrecordset.CursorType = adOpenKeyset
localrecordset.LockType = adLockOptimistic
localrecordset.Open sql, , adOpenForwardOnly, adLockOptimistic, adCmdText
End Sub
It's always worked in the past http://www.pesfan.com/bulletin/image...s/confused.gif
Re: Simple if statement problem
Where would your FROM clause be?
Re: Simple if statement problem
Ignore that, a simple rename of the table did the trick :p
Re: Simple if statement problem
Quote:
Originally Posted by dragonskin
Cheers for the help so far
VB Code:
If Option1 = True And Option4 = True Then
totalpoints = 2
If Option1 = True And Option4 = True And user1.Text = real1.Text And user2.Text = real2.Text Then
totalpoints = 5
End If
End If
That works fine, is there a quick way to do it for the other games as well or will I have to write out those if statements each time?
you cant have 2 option buttons true at the same time :confused:
Re: Simple if statement problem
Why not?
Option1 indicates a predicted home win
Option4 indicates an actual home win
Re: Simple if statement problem
Quote:
Originally Posted by dragonskin
Why not?
Option1 indicates a predicted home win
Option4 indicates an actual home win
Two option buttons can not both be True at the same time unless they are in different containers (like a frame or picturebox).
Re: Simple if statement problem
I'm having one of those 'blonde' days :blush:
Re: Simple if statement problem
Another point is that checkboxes are normally used when several things can be true at the same time.
BTW I have senior moment days :)