-
Oct 26th, 2009, 07:20 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Code Help
Ok, My game has a board in it and what the code does is load the save state from a database and on the board and on the board if there is a "0" it means the question is used, if it is a "1" it means the question is still there. Im having problems because it is not loadingin the save states.
Last edited by GDOG34; Nov 25th, 2009 at 09:31 PM.
-
Oct 26th, 2009, 07:20 PM
#2
Thread Starter
Fanatic Member
Re: Code Help
Here is my code for updating the states, changing the bitmap if it was already used:
Last edited by GDOG34; Nov 25th, 2009 at 09:31 PM.
-
Oct 27th, 2009, 08:44 AM
#3
Frenzied Member
Re: Code Help
Step through your code and identify where it is failing.
-
Oct 27th, 2009, 09:42 AM
#4
Re: Code Help
Indeed... and if you don't know how to do that, see the article Using VB6 debug [Tutorial] from our Classic VB FAQs
The first thing I noticed is that your code is ridiculously hard to read, because you have intentionally made it that way. As such, I refuse to waste my time trying to help with the issue you asked about, until you have removed that hindrance.
One reason for that is that you haven't bothered to indent your code - which is madness, because not doing it makes the code much harder to read.
You should use the style in the code boxes below. To make it easier, you can select multiple lines of code and press Tab to indent them all (or Shift-Tab to un-indent them).
The next reason is that you have got a huge amount of unnecessary code, because you have repeated the same thing over and over again when there is absolutely no need to. The "Change The Board" section is a good example, because this:
Code:
If LOAD.SSQUESTION.Caption = "1" Then
BOARD.Controls("CAT" & LOAD.SSCATEGORY.Caption & LOAD.SSQUESTION.Caption & "S").Caption = LOAD.TEMP.Caption
Else
If LOAD.SSQUESTION.Caption = "2" Then
BOARD.Controls("CAT" & LOAD.SSCATEGORY.Caption & LOAD.SSQUESTION.Caption & "S").Caption = LOAD.TEMP.Caption
Else
If LOAD.SSQUESTION.Caption = "3" Then
BOARD.Controls("CAT" & LOAD.SSCATEGORY.Caption & LOAD.SSQUESTION.Caption & "S").Caption = LOAD.TEMP.Caption
Else
If LOAD.SSQUESTION.Caption = "4" Then
BOARD.Controls("CAT" & LOAD.SSCATEGORY.Caption & LOAD.SSQUESTION.Caption & "S").Caption = LOAD.TEMP.Caption
Else
If LOAD.SSQUESTION.Caption = "5" Then
BOARD.Controls("CAT" & LOAD.SSCATEGORY.Caption & LOAD.SSQUESTION.Caption & "S").Caption = LOAD.TEMP.Caption
Else
'*****************************
'No Question Beyond This Point
'*****************************
End If
End If
End If
End If
End If
...does exactly the same as this:
Code:
If LOAD.SSQUESTION.Caption >= "1" And LOAD.SSQUESTION.Caption <= "5" Then
BOARD.Controls("CAT" & LOAD.SSCATEGORY.Caption & LOAD.SSQUESTION.Caption & "S").Caption = LOAD.TEMP.Caption
End If
..which is the same as this alternative:
Code:
Select Case LOAD.SSQUESTION.Caption
Case "1" To "5"
BOARD.Controls("CAT" & LOAD.SSCATEGORY.Caption & LOAD.SSQUESTION.Caption & "S").Caption = LOAD.TEMP.Caption
End Select
If you implement that fully (including the If's for SSCATEGORY), the 100 or so lines of code from "Change The Board" to "Change Question States" can be replaced by about 6 lines.
You should also do similar for the "Load A Category" section.
There is also no valid reason for you to have an Else which is not followed by any code... so for example, this part:
Code:
If Int(LOAD.SSCATEGORY.Caption) > 5 Then
UpdateSaveState.Enabled = False
Else
End If
Else
End If
..should be like this:
Code:
If Int(LOAD.SSCATEGORY.Caption) > 5 Then
UpdateSaveState.Enabled = False
End If
End If
-
Oct 27th, 2009, 11:22 AM
#5
Thread Starter
Fanatic Member
Re: Code Help
BrianS, I wasn't able to find the source of the error because of the fact that it doesn't give me what I want, and Si_the_geek thanks for the input and I will rework my code later on today.
-
Oct 27th, 2009, 12:27 PM
#6
Frenzied Member
Re: Code Help
Well then identify where "it doesn't give you what you want".
-
Oct 29th, 2009, 07:12 PM
#7
Thread Starter
Fanatic Member
Re: Code Help
Well it's not removing the categories from the board because I guess the logic is messed up. But I can't see to find out where the logic is going wrong.
Last edited by GDOG34; Nov 25th, 2009 at 09:31 PM.
-
Oct 30th, 2009, 07:24 PM
#8
Thread Starter
Fanatic Member
Re: Code Help
This is what it does, there are questions on the board and when the game loads it loads from a file and if the file returns a zero it means that the question was already picked and if the file returns a 1 it means that the question still exists. It seems like the game is not returning the values on the board.
-
Nov 2nd, 2009, 12:36 PM
#9
Thread Starter
Fanatic Member
-
Nov 2nd, 2009, 12:53 PM
#10
Fanatic Member
Re: Code Help
vb Code:
'*********************************************************************************** 'Update The Board's Save State '*********************************************************************************** '************************************** 'Enable & Disable Categories '************************************** If BOARD.Controls("CAT" & SSCATEGORY.Caption & SSQUESTION.Caption & "S").Caption = "0" Then '************************************** 'Hide The Question '************************************** BOARD.Controls("CAT" & SSCATEGORY.Caption & SSQUESTION.Caption).Picture = LoadPicture(App.Path & "\Data\Graphics\" & "Categories\0.bmp") BOARD.Controls("CAT" & SSCATEGORY.Caption & SSQUESTION.Caption).Enabled = False LOAD.SSQUESTION.Caption = CStr(val(LOAD.SSQUESTION.Caption) + val(1)) If Int(LOAD.SSQUESTION.Caption) > 5 Then LOAD.SSQUESTION.Caption = "1" LOAD.SSCATEGORY.Caption = CStr(val(LOAD.SSQUESTION.Caption) + val(1)) End If If Int(LOAD.SSCATEGORY.Caption) > 5 Then UpdateSaveState.Enabled = False End If Else If BOARD.Controls("CAT" & SSCATEGORY.Caption & SSQUESTION.Caption & "S").Caption = "1" Then '************************************** 'Show The Question '************************************** BOARD.Controls("CAT" & SSCATEGORY.Caption & SSQUESTION.Caption).Visible = True BOARD.Controls("CAT" & SSCATEGORY.Caption & SSQUESTION.Caption).Enabled = True LOAD.SSQUESTION.Caption = CStr(val(LOAD.SSQUESTION.Caption) + val(1)) If Int(LOAD.SSQUESTION.Caption) > 5 Then LOAD.SSQUESTION.Caption = "1" LOAD.SSCATEGORY.Caption = CStr(val(LOAD.SSQUESTION.Caption) + val(1)) End If If Int(LOAD.SSCATEGORY.Caption) > 5 Then UpdateSaveState.Enabled = False Else End If Else End If End If End Sub
Here, I formatted your code so it would make it easier to read for those trying to help.
Where I'm from we only have one bit of advice for new comers: "If you hear banjos, turn and run".
VS 2008 .NetFW 2.0
-
Nov 5th, 2009, 09:41 PM
#11
Thread Starter
Fanatic Member
Re: Code Help
Anyone figure this out yet?
-
Nov 7th, 2009, 07:37 PM
#12
Thread Starter
Fanatic Member
Re: Code Help
Ok, I have decied to explain this thing in much more detail. So there is a board on the screen and there are questions on it. So in a DAO database it simply loads the "state" into the caption. Afterwards it checks the state. If the value is "0" then the question is disbaled. If the state is "1" then the question is enabled. I have the orignal code attached that loaded and checked the state, and this way was long and I want to do a shorter way. I attached the code.
Last edited by GDOG34; Nov 25th, 2009 at 09:32 PM.
-
Nov 13th, 2009, 09:54 PM
#13
Thread Starter
Fanatic Member
Re: Code Help
It would be great to see help in this topic.
-
Nov 16th, 2009, 12:19 PM
#14
Thread Starter
Fanatic Member
Last edited by GDOG34; Nov 25th, 2009 at 09:33 PM.
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
|