Results 1 to 14 of 14

Thread: [RESOLVED] Code Help

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Resolved [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.

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    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.

  3. #3
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564

    Re: Code Help

    Step through your code and identify where it is failing.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    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

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    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.

  6. #6
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564

    Re: Code Help

    Well then identify where "it doesn't give you what you want".

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    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.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    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.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Re: Code Help

    Anyone?

  10. #10
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    Re: Code Help

    vb Code:
    1. '***********************************************************************************
    2.         'Update The Board's Save State
    3.         '***********************************************************************************
    4.         '**************************************
    5.         'Enable & Disable Categories
    6.         '**************************************
    7.         If BOARD.Controls("CAT" & SSCATEGORY.Caption & SSQUESTION.Caption & "S").Caption = "0" Then
    8.             '**************************************
    9.             'Hide The Question
    10.             '**************************************
    11.             BOARD.Controls("CAT" & SSCATEGORY.Caption & SSQUESTION.Caption).Picture = LoadPicture(App.Path & "\Data\Graphics\" & "Categories\0.bmp")
    12.             BOARD.Controls("CAT" & SSCATEGORY.Caption & SSQUESTION.Caption).Enabled = False
    13.             LOAD.SSQUESTION.Caption = CStr(val(LOAD.SSQUESTION.Caption) + val(1))
    14.             If Int(LOAD.SSQUESTION.Caption) > 5 Then
    15.                 LOAD.SSQUESTION.Caption = "1"
    16.                 LOAD.SSCATEGORY.Caption = CStr(val(LOAD.SSQUESTION.Caption) + val(1))
    17.             End If
    18.             If Int(LOAD.SSCATEGORY.Caption) > 5 Then
    19.                 UpdateSaveState.Enabled = False
    20.             End If
    21.         Else
    22.             If BOARD.Controls("CAT" & SSCATEGORY.Caption & SSQUESTION.Caption & "S").Caption = "1" Then
    23.                 '**************************************
    24.                 'Show The Question
    25.                 '**************************************
    26.                 BOARD.Controls("CAT" & SSCATEGORY.Caption & SSQUESTION.Caption).Visible = True
    27.                 BOARD.Controls("CAT" & SSCATEGORY.Caption & SSQUESTION.Caption).Enabled = True
    28.                 LOAD.SSQUESTION.Caption = CStr(val(LOAD.SSQUESTION.Caption) + val(1))
    29.                 If Int(LOAD.SSQUESTION.Caption) > 5 Then
    30.                     LOAD.SSQUESTION.Caption = "1"
    31.                     LOAD.SSCATEGORY.Caption = CStr(val(LOAD.SSQUESTION.Caption) + val(1))
    32.                 End If
    33.                 If Int(LOAD.SSCATEGORY.Caption) > 5 Then
    34.                     UpdateSaveState.Enabled = False
    35.                 Else
    36.                 End If
    37.             Else
    38.             End If
    39.         End If
    40.     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

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Re: Code Help

    Anyone figure this out yet?

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    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.

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Re: Code Help

    It would be great to see help in this topic.

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Location
    Merced
    Posts
    868

    Re: Code Help

    Well i figured it out!
    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
  •  



Click Here to Expand Forum to Full Width