locked
Boolean If Statement Question RRS feed

  • Question

  • User-1269234728 posted

    Hi Guys,

               I have some code that I'm trying to get to work correctly...        

               I 'm not sure if the boolean if statement is the right choice for what I'm trying to accomplish???  I need to be able to assign "True" (doSomething) And Also to "False" (doSomething) 

               My Code is listed below can you please take a look... Thank You...

    ________________________________________________________________________

                          Session("LittleHelper") = lblMessage1.Text

                             Dim Freeone As String = "True"  ' This sets the condition - (True or False)

                             Dim b As Boolean

                             If b = "True" Then
                                                 ' Want this to fire if ((True)) 
                             Session("LittleHelper") = AutoTitle.text.Trim().Replace(" ", string.Empty) + lblMessage4.Text

                             else

                              b = "False"
                                                ' Want this to  fire if ((False)) 
                             Session("LittleHelper") = AutoTitle.text.Trim().Replace(" ", string.Empty) + "45"

                             End If

    Saturday, May 8, 2010 1:48 PM

Answers

  • User-1440976047 posted

    Hi,

    I could understand your query in two ways.

    First way:

    Session("LittleHelper") = lblMessage1.Text
    Dim Freeone As String = "True"  ' This sets the condition - (True or False)
    Dim b As Boolean
    If b = True Then 'since b is declared as boolean,  directly use b=true instead of b="true"
       ' Want this to fire if ((True))
        Session("LittleHelper") = AutoTitle.text.Trim().Replace(" ", string.Empty) + lblMessage4.Text
    else
        b = False
        ' Want this to  fire if ((False))
        Session("LittleHelper") = AutoTitle.text.Trim().Replace(" ", string.Empty) + "45"
    End If


    Second way:

    Session("LittleHelper") = lblMessage1.Text
    Dim Freeone As String = "True"  ' This sets the condition - (True or False)

    Dim b As Boolean

    If b = Convert.ToBoolean(Freeone) Then 'since freeone is declared as string, you need to convert to boolean
        ' Want this to fire if ((True))
         Session("LittleHelper") = AutoTitle.text.Trim().Replace(" ", string.Empty) + lblMessage4.Text
    else
         b = "False"
         ' Want this to  fire if ((False))
         Session("LittleHelper") = AutoTitle.text.Trim().Replace(" ", string.Empty) + "45"
    End If

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, May 8, 2010 2:18 PM