-2

I am coding a basic program that allows users to calculate useful data on a shape (2d and 3d) based on information such as radius length, side length, height, etc.

I would like to create a settings MENU that allows users to set how many decimal places they would like the answer to go to, so what I did was

    Private Sub btnSettings_Click(sender As Object, e As EventArgs) Handles btnSettings.Click

    If btnSettings.Text = "Settings" Then
        btnSettings.Text = "Back"
    ElseIf btnSettings.Text = "Back" Then
        btnSettings.Text = "Settings"
    End If

    Do While btnSettings.Text = "Back"

        'makes IO elements invisible
        lblEnter.Visible = False
        lblEnter2.Visible = False
        lblData1.Visible = False
        lblData2.Visible = False
        lblData3.Visible = False
        lblAnswer1.Visible = False
        lblAnswer2.Visible = False
        lblAnswer3.Visible = False
        txtEnter.Visible = False
        txtEnter2.Visible = False
        btnClearTxt1.Visible = False
        lblEnter3.Visible = False
        txtEnter3.Visible = False
        chkBox.Visible = False
        btnCalculate.Visible = False
        btnClear.Visible = False

        'Makes shape selection elements invisible
        picCircle.Visible = False
        picSquare.Visible = False
        picTriangle.Visible = False
        rdoCircle.Visible = False
        rdoSquare.Visible = False
        rdoTriangle.Visible = False
        btn3D.Visible = False

        'Changes texts on necessary elements
        lblSelectShape.Text = "Settings"
    Loop

End Sub

As you can see, when "btnSettings" shows the text "Settings", the elements on the screen are VISIBLE to the user, however as soon as "btnSettings" changes text to "Back" (indicating the user is inside the settings menu) all the elements on the screen disappear, making room for the elements the settings menu will have. However, while debugging the program whenever I hit the settings button the program crashes.

Any help? Thanks

6
  • Why are you not using an If Statement here?
    – OneFineDay
    Sep 11, 2014 at 23:57
  • My program has a total of 6 shapes you can chose from. Upon chosing a shape, up to 3 text boxes and 3 labels can appear on the screen, but which ones depends on the shape the user selects. When the settings button is clicked, it would be easy enough to get rid of the elements but when the user clicks back the program wouldnt know which shape menu to land the user on again. Sep 12, 2014 at 0:01
  • 1
    Do while is a loop statement, and wouldn't work here, you have to put your statements into your If ... ElseIf together with the text changing for the button
    – ISAE
    Sep 12, 2014 at 0:03
  • I was afraid I would have to do that. Thanks! Sep 12, 2014 at 0:05
  • Not your only option!
    – OneFineDay
    Sep 12, 2014 at 0:06

1 Answer 1

2

Use a Select Case for this:

Select Case shapeType
 Case shapeType.Circle
   'logic for this
 '...
End Select
1
  • Interesting. I am new to VB so I will have to do some research but I think this will work! Sep 12, 2014 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.