if statements...please help :)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • willywonka
    New Member
    • Sep 2007
    • 18

    if statements...please help :)

    Hi! I am using vb.net and have some basic questions


    I was wondering if i have a very long line of code (a long if statement), can it extend onto two lines? If so how would I do that?

    I also wanted to know say I have 7 checkboxes and the condition on my if statement is to check if only one box has been checked, is the only way to do this by having all the different combinations listed?

    Thank you for any help, I am fairly new to vb.net and would appreciate any insight!!!
  • willywonka
    New Member
    • Sep 2007
    • 18

    #2
    Hi..it's me again.

    I tried using a loop to get the count of each checkbox that is check but i don't think that i can use checkboxi.check ed (where i is the number of the checkbox) do you always have to state the proper name for the checkbox like checkbox1 instead of checkboxi where i=1?

    Thanks again for any help!!!

    Comment

    • nateraaaa
      Recognized Expert Contributor
      • May 2007
      • 664

      #3
      Originally posted by willywonka
      Hi! I am using vb.net and have some basic questions


      I was wondering if i have a very long line of code (a long if statement), can it extend onto two lines? If so how would I do that?

      I also wanted to know say I have 7 checkboxes and the condition on my if statement is to check if only one box has been checked, is the only way to do this by having all the different combinations listed?

      Thank you for any help, I am fairly new to vb.net and would appreciate any insight!!!
      I believe the line continuation character in VB.NET is placing an _ at the end of your line to let the compiler know that the text on the next line needs to be combined with the text from the previous line.

      If you are only concerned with the checked status of one checkbox just check to see if that checkbox is checked.

      if(CheckBox1.Ch ecked)
      {
      //do something
      }

      Nathan

      Comment

      • nateraaaa
        Recognized Expert Contributor
        • May 2007
        • 664

        #4
        Originally posted by willywonka
        Hi..it's me again.

        I tried using a loop to get the count of each checkbox that is check but i don't think that i can use checkboxi.check ed (where i is the number of the checkbox) do you always have to state the proper name for the checkbox like checkbox1 instead of checkboxi where i=1?

        Thanks again for any help!!!
        I am not sure of the setup of your page but if your checkboxes are all in a vertical alignment you could instead use a CheckBoxList and then use a foreach loop to loop through the CheckBoxList to see which CheckBoxes are checked in the CheckBoxList.

        For examples on how to do this search Google for the following text:
        VB.NET foreach checkbox in checkboxlist

        Nathan

        Comment

        • balabaster
          Recognized Expert Contributor
          • Mar 2007
          • 798

          #5
          Originally posted by nateraaaa
          I am not sure of the setup of your page but if your checkboxes are all in a vertical alignment you could instead use a CheckBoxList and then use a foreach loop to loop through the CheckBoxList to see which CheckBoxes are checked in the CheckBoxList.

          For examples on how to do this search Google for the following text:
          VB.NET foreach checkbox in checkboxlist

          Nathan
          In answer to your first question...If statement spread over multiple lines (just in case you weren't able to translate from C# to VB)

          Code:
          If MyStatement1 = True _ 
          Or MyStatement2 = True _
          Or Mystatement3 = True Then
          'Do stuff
          End If
          In answer to your checkbox loop - validate the check the CheckState property instead of the Checked property.

          Comment

          • willywonka
            New Member
            • Sep 2007
            • 18

            #6
            Thanks for all the help...very much appreciated :) !!!!

            Comment

            Working...