|
-
Apr 5th, 2008, 02:16 PM
#1
Thread Starter
Junior Member
If - Then - Else
I jst wanted to know if anybody could help me with this....
I'm making a sudoku program and I have a beginner button that when you push it it shows you 35 of the answers in the puzzle, but how do I do so that you can't push it again with out pushing the reset button first.. can anybody help?
-
Apr 5th, 2008, 02:51 PM
#2
PowerPoster
Re: If - Then - Else
 Originally Posted by SpitFire
I jst wanted to know if anybody could help me with this....
I'm making a sudoku program and I have a beginner button that when you push it it shows you 35 of the answers in the puzzle, but how do I do so that you can't push it again with out pushing the reset button first.. can anybody help?
you can use one array(with 2 dimensions) for see what button was selected, then with these when you play again you can test if the button was clicked or not...
i hope these help
-
Apr 5th, 2008, 02:53 PM
#3
Re: If - Then - Else
What is a beginner button? Is it a command button? Can you be more specific? The first time it is pushed it does something. The 2nd, 3rd, etc time it is pushed it does something else? Describe please.
-
Apr 5th, 2008, 02:53 PM
#4
Re: If - Then - Else
Code:
Option Explicit
Private bShown As Boolean
Private Sub cmdReset_Click()
bShown = False
End Sub
Private Sub cmdShow35_Click()
If bShown Then
Exit Sub
Else
MsgBox "show the 35 here"
bShown = True
End If
End Sub
-
Apr 5th, 2008, 03:49 PM
#5
Thread Starter
Junior Member
Re: If - Then - Else
okay thanks ! That helped ALOT !! now i wanted to know if anyone had an idea to how I could make a button check for errors in the puzzle, this is my array for the puzzles:
Private Sub puzzleload()
Dim j As Integer
Dim i As Integer
For j = 1 To 1
For i = 1 To 81
puzzle(j, 1) = 3
puzzle(j, 2) = 2
puzzle(j, 3) = 8
puzzle(j, 4) = 6
puzzle(j, 5) = 5
puzzle(j, 6) = 9
puzzle(j, 7) = 7
puzzle(j, 8) = 1
puzzle(j, 9) = 4
puzzle(j, 10) = 7
puzzle(j, 11) = 9
puzzle(j, 12) = 6
puzzle(j, 13) = 3
puzzle(j, 14) = 4
puzzle(j, 15) = 1
puzzle(j, 16) = 5
puzzle(j, 17) = 8
puzzle(j, 18) = 2
puzzle(j, 19) = 1
puzzle(j, 20) = 5
puzzle(j, 21) = 4
puzzle(j, 22) = 7
puzzle(j, 23) = 8
puzzle(j, 24) = 2
puzzle(j, 25) = 3
puzzle(j, 26) = 9
puzzle(j, 27) = 6
puzzle(j, 28) = 5
puzzle(j, 29) = 3
puzzle(j, 30) = 2
puzzle(j, 31) = 8
puzzle(j, 32) = 4
puzzle(j, 33) = 6
puzzle(j, 34) = 1
puzzle(j, 35) = 9
puzzle(j, 36) = 7
puzzle(j, 37) = 1
puzzle(j, 38) = 7
puzzle(j, 39) = 4
puzzle(j, 40) = 9
puzzle(j, 41) = 3
puzzle(j, 42) = 5
puzzle(j, 43) = 2
puzzle(j, 44) = 6
puzzle(j, 45) = 8
puzzle(j, 46) = 8
puzzle(j, 47) = 6
puzzle(j, 48) = 9
puzzle(j, 49) = 2
puzzle(j, 50) = 1
puzzle(j, 51) = 7
puzzle(j, 52) = 4
puzzle(j, 53) = 3
puzzle(j, 54) = 5
puzzle(j, 55) = 9
puzzle(j, 56) = 8
puzzle(j, 57) = 1
puzzle(j, 58) = 4
puzzle(j, 59) = 6
puzzle(j, 60) = 5
puzzle(j, 61) = 2
puzzle(j, 62) = 7
puzzle(j, 63) = 3
puzzle(j, 64) = 4
puzzle(j, 65) = 5
puzzle(j, 66) = 7
puzzle(j, 67) = 8
puzzle(j, 68) = 2
puzzle(j, 69) = 3
puzzle(j, 70) = 6
puzzle(j, 71) = 1
puzzle(j, 72) = 9
puzzle(j, 73) = 6
puzzle(j, 74) = 2
puzzle(j, 75) = 3
puzzle(j, 76) = 9
puzzle(j, 77) = 7
puzzle(j, 78) = 1
puzzle(j, 79) = 5
puzzle(j, 80) = 4
puzzle(j, 81) = 8
Next i
Next j
Right now I only got one puzzle that's why it's 1 to 1. hehe... I'm going to change this, but how do I make a button that chechs for the error, I have done so that when you choose a number from a combo list by a button the button's caption change name to the value the user have selected, I know want the program to check if the buttons captions is equal to the array at it's place
CmdKnap(1).caption = puzzle(j, 1)
-
Apr 5th, 2008, 11:59 PM
#6
Re: If - Then - Else
Firstly, the 'For i' loop is not needed.
I assume that CmsKnap is an array of CommandButtons, if the first element is Index 1 then
Code:
If CmdKnap(1).Caption = CStr(puzzle(j,1)) Then
'
' It's the same
'
Else
'
' It's not the same
'
End If
Will check if the first square is correct.
More generally, and assuming that you've also got an array of ComboBoxes
Code:
Private Sub Combo1_Click(Index As Integer)
CmdKnap(Index).Caption = Combo1(Index).Text
If CmdKnap(Index).Caption = Cstr(puzzle(j, Index)) Then
'
' It's correct
'
Else
'
' It's incorrect
'
End If
End Sub
-
Apr 6th, 2008, 07:29 AM
#7
Thread Starter
Junior Member
Re: If - Then - Else
 Originally Posted by Doogle
Firstly, the 'For i' loop is not needed.
I assume that CmsKnap is an array of CommandButtons, if the first element is Index 1 then
Code:
If CmdKnap(1).Caption = CStr(puzzle(j,1)) Then
'
' It's the same
'
Else
'
' It's not the same
'
End If
Will check if the first square is correct.
More generally, and assuming that you've also got an array of ComboBoxes
Code:
Private Sub Combo1_Click(Index As Integer)
CmdKnap(Index).Caption = Combo1(Index).Text
If CmdKnap(Index).Caption = Cstr(puzzle(j, Index)) Then
'
' It's correct
'
Else
'
' It's incorrect
'
End If
End Sub
It doesn't seem to work as i had hooped, and I can replace the 1 with i right?
when i push the button it only checks if the first array is correct and then change the buttons caption to 0.
this is my form load code:
Private Sub Form_Load()
Dim i As Integer
For i = 1 To 81
CmdKnap(i).Caption = "Tryk Her"
Label2(i).Caption = "indsæt et tal"
Combo1(i).Visible = False
Combo1(i).AddItem (1)
Combo1(i).AddItem (2)
Combo1(i).AddItem (3)
Combo1(i).AddItem (4)
Combo1(i).AddItem (5)
Combo1(i).AddItem (6)
Combo1(i).AddItem (7)
Combo1(i).AddItem (8)
Combo1(i).AddItem (9)
Next i
End Sub
this is my combo1 code:
Private Sub Combo1_Click(index As Integer)
CmdKnap(index).Caption = Combo1(index).ListIndex + 1
Combo1(index).Visible = False
CmdKnap(index).Visible = True
CmdKnap(index).Font.Size = 24
cShown = False
End Sub
this is my code for the checking button:
Private Sub CmdCheck_Click()
Dim j As Integer
Dim i As Integer
Dim værdi As Integer
For j = 1 To 1
For i = 1 To 81 Step 81
CmdKnap(i).Caption = værdi
If cShown Then
MsgBox ("Du er jo ikke begyndt endnu!")
Else
If dshown Then
MsgBox ("Du har jo ikke selv løst denne puzzle men brugt giv op funktionen")
Else
If værdi = CStr(puzzle(j, i)) Then
MsgBox ("Der er ingen fejl i denne puzzle")
Else
MsgBox ("Der er stadig fejl i denne puzzle")
End If
End If
End If
Next i
Next j
End Sub
-
Apr 7th, 2008, 01:33 AM
#8
Re: If - Then - Else
You haven't set a value for værdi before you do this
Code:
CmdKnap(i).Caption = værdi
so it will change the caption to 0
-
Apr 7th, 2008, 01:36 AM
#9
Thread Starter
Junior Member
Re: If - Then - Else
 Originally Posted by Doogle
You haven't set a value for værdi before you do this
Code:
CmdKnap(i).Caption = værdi
so it will change the caption to 0
Didn't I do that with
Dim værdi as integer
??? or what do you mean?
-
Apr 7th, 2008, 02:03 AM
#10
Re: If - Then - Else
Dim just defines it and sets it's initial value to zero. You need to assign a value to it, perhaps from the puzzle array ?
-
Apr 7th, 2008, 02:14 AM
#11
Thread Starter
Junior Member
Re: If - Then - Else
 Originally Posted by Doogle
Dim just defines it and sets it's initial value to zero. You need to assign a value to it, perhaps from the puzzle array ?
sorry I might ask dumb, but what will this code look like?
Last edited by SpitFire; Apr 7th, 2008 at 02:19 AM.
-
Apr 7th, 2008, 02:51 AM
#12
Re: If - Then - Else
Code:
Private Sub CmdCheck_Click()
Dim j As Integer
Dim i As Integer
Dim værdi As Integer
For j = 1 To 1
For i = 1 To 81 Step 81
CmdKnap(i).Caption = værdi
If cShown Then
MsgBox ("Du er jo ikke begyndt endnu!")
Else
If dshown Then
MsgBox ("Du har jo ikke selv løst denne puzzle men brugt giv op funktionen")
Else
If værdi = CStr(puzzle(j, i)) Then
MsgBox ("Der er ingen fejl i denne puzzle")
Else
MsgBox ("Der er stadig fejl i denne puzzle")
End If
End If
End If
Next i
Next j
End Sub
It helps readability if you indent your code, and use the code tags [ code] and [ /code] around your code (remove the space after the [) when you post it here.
Now, you have a better comand of my language than I have of your's, could you please translate the messages so I can see what you think you're doing. Thanks
-
Apr 7th, 2008, 03:00 AM
#13
Thread Starter
Junior Member
Re: If - Then - Else
Okay I'll try. Hehe.
First i define I and J, 1 puzzle with 81 spaces.
then I define værdi as integer (værdi is danish for Value)
then i set CmdKnap = værdi (CmdButton = Value)
Then I have som If - then - else code the code needs to have the run through two functions that I have defindes Boolean, The reason why I have thess is so that you can push the button before you have started a new game or something like that.
the text in the cShown code in english:
("You haven't started yet!")
the text in the dshown code in english:
("You haven't solved this puzzle by your self, but have used the "give up" button")
Now we get to the code that should check if the right numbers are in the rightfull places.
Else
If værdi = CStr(puzzle(j, i)) Then
MsgBox ("It is correct")
Else
MsgBox ("There are still som errors in the puzzle")
End If
I hope this helped
-
Apr 7th, 2008, 03:41 AM
#14
Re: If - Then - Else
OK, when the user clicks cmdCheck you want to look at the captions of cmdKnap to see if they match the corresponding array value, if they do then they have finished the puzzle correctly otherwise they still have some errors. So you don't want to change the captions, just look at them and make the comparisson. Also you don't want the messages in the loop - otherwise the user will get 81 of them.
Code:
Private Sub CmdCheck_Click()
Dim j As Integer
Dim i As Integer
Dim boSolved As Boolean
If cShown = True Then
MsgBox ("Du er jo ikke begyndt endnu!")
Else
If dShown = True Then
MsgBox ("Du har jo ikke selv løst denne puzzle men brugt giv op funktionen")
End If
'
' Now we can see if the puzzle is solved
'
boSolved = True
j = 1
i = 1
'
' Check each Caption against the corresponding
' value in the puzzle. As soon as one doesn't match
' Exit the loop (because that means that there's a mistake
' or there are some numbers still to be put in
'
Do
If CmdKnap(i).Caption <> CStr(puzzle(j,i)) Then
boSolved = False
Else
i = i + 1
End If
Loop Until boSolved = False Or i > 81
If boSolved = False then
MsgBox "You haven't solved it yet"
Else
MsgBox "You have solved it"
End If
End If
End Sub
-
Apr 7th, 2008, 06:19 AM
#15
Thread Starter
Junior Member
Re: If - Then - Else
THANKS ALOT ! That did it :P,
I was wondering, now since I also have a button that will show where the errors are by coloring the letters red, can't I then use this code and just change the last if - then - else code or what?
-
May 25th, 2008, 10:02 AM
#16
PowerPoster
Re: If - Then - Else
 Originally Posted by SpitFire
THANKS ALOT ! That did it :P,
I was wondering, now since I also have a button that will show where the errors are by coloring the letters red, can't I then use this code and just change the last if - then - else code or what?
you can't change the msgbox forecolor... instead you can use an form/label and change their forecolor...
i hope these helps
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|