What's wrong with this

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mrcw
    New Member
    • Nov 2008
    • 82

    What's wrong with this

    [CODE=VB=]Private Sub NextButton_Clic k(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles NextButton.Clic k

    Dim PageSelected As String = "Page"
    Page = Page + 1

    Select Case PageSelected
    Case 1
    AllHide() 'subroutine that hides all things on the page
    VisibleOnPage01 () 'subroutine that shows things applicable to Page01
    Case 2
    AllHide()
    VisibleOnPage02 ()
    Case 3
    AllHide()
    VisibleOnPage03 ()
    Case 4
    AllHide()
    VisibleOnPage04 ()
    Case Else
    MsgBox("error")
    End Select
    End Sub
    [/CODE]
    Each time the button is pressed it should increment the variable page the run through the case statement untill the page is found then show the items on the page, but all that happens is a msgbox appears and says error. I don't know why.
    Last edited by Dököll; Dec 1 '08, 01:49 AM. Reason: code tags...
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by mrcw
    [CODE=VB]Private Sub NextButton_Clic k(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles NextButton.Clic k

    Dim PageSelected As String = "Page"
    Page = Page + 1

    ...

    End Sub


    [/CODE]
    Each time the button is pressed it should increment the variable page the run through the case statement untill the page is found then show the items on the page, but all that happens is a msgbox appears and says error. I don't know why.
    Perhaps in 'Dim PageSelected As String = "Page"
    ' "Page" is not needed. Looks like you defining page twice, at quick glance...
    Last edited by Dököll; Dec 1 '08, 01:50 AM. Reason: text delete...

    Comment

    • rpicilli
      New Member
      • Aug 2008
      • 77

      #3
      Originally posted by mrcw
      [CODE=VB=]Private Sub NextButton_Clic k(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles NextButton.Clic k

      Dim PageSelected As String = "Page"
      Page = Page + 1

      Select Case PageSelected
      Case 1
      AllHide() 'subroutine that hides all things on the page
      VisibleOnPage01 () 'subroutine that shows things applicable to Page01
      Case 2
      AllHide()
      VisibleOnPage02 ()
      Case 3
      AllHide()
      VisibleOnPage03 ()
      Case 4
      AllHide()
      VisibleOnPage04 ()
      Case Else
      MsgBox("error")
      End Select
      End Sub
      [/CODE]
      Each time the button is pressed it should increment the variable page the run through the case statement untill the page is found then show the items on the page, but all that happens is a msgbox appears and says error. I don't know why.

      Hi there.

      There some mistakes in your code.

      You declare PageSelected as string and give then "Page". OK
      After you Add 1 to the variable Page. I suppose this variable was declare elsewhere if not you need to declare and initialize this variable Page.

      In the Select Case you use PageSelected. This variable never will have the value 1. Remember its string and has "Page" as contents.

      I hope this help you

      Rpicilli

      Comment

      • mrcw
        New Member
        • Nov 2008
        • 82

        #4
        I don't understand

        Thanks for the reply, but I'm afraid it's still as clear as mud! Could you rearrange my code to give me a case statement that works please. I learn better by building on a somple example.
        Thanx
        mrcw

        Comment

        • rpicilli
          New Member
          • Aug 2008
          • 77

          #5
          Originally posted by mrcw
          Thanks for the reply, but I'm afraid it's still as clear as mud! Could you rearrange my code to give me a case statement that works please. I learn better by building on a somple example.
          Thanx
          mrcw
          You know, I can do that but you will learn nothing. The better way to learn is reading books or help files and try a lot. Excuse me by this kind of comments but that is the true.

          Code:
          'The line below must be off of your buttom click event or allways the Page 'will 'be 0 and you'll be able to select only the first page.
          Dim iPage as integer = 0
          
          Dim PageSelected As String = "Page" 
                  
                  iPage = iPage + 1 
            
                  Select Case iPage 
                      Case 1 
                          AllHide()  'subroutine that hides all things on the page 
                          VisibleOnPage01()  'subroutine that shows things applicable to Page01 
                      Case 2 
                          AllHide() 
                          VisibleOnPage02() 
                      Case 3 
                          AllHide() 
                          VisibleOnPage03() 
                      Case 4 
                          AllHide() 
                          VisibleOnPage04() 
                      Case Else 
                          MsgBox("error") 
           End Select

          That change in the code will make your select works, just the Select not the other Functions that you've created.

          Comment

          • mrcw
            New Member
            • Nov 2008
            • 82

            #6
            Thaks

            Thanks ripicili but I had allready worked it out - my code was similar but not exactly to yours
            mrcw

            Comment

            Working...