For...each...next statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kiteman - Canada

    For...each...next statement

    I have the following:

    a form called Form1
    an image called Image1
    twelve lines that have been drawn and superimposed on the image

    I wish to have a command button that will toggle the lines on and off. I
    am able to do this with a command for each of the twelve lines, but I
    thought that I could use a For...Each...Ne xt routine instead. For the
    life of me I can't seem to get the correct syntax and/or I don't have the
    twelve lines in (on top?) of a suitable container. A little assistance
    would be most appreciated.

    My idea is something along these lines......

    Dim c as Line
    For Each c in Image1
    If c.Visible = True then
    c.Visible = False
    Else
    c.Visible = True
    End if

    Next


    Regards,
    Tom White




  • Rick Rothstein

    #2
    Re: For...each...ne xt statement

    > I have the following:[color=blue]
    >
    > a form called Form1
    > an image called Image1
    > twelve lines that have been drawn and superimposed on the image
    >
    > I wish to have a command button that will toggle the lines on and off.[/color]
    I[color=blue]
    > am able to do this with a command for each of the twelve lines, but I
    > thought that I could use a For...Each...Ne xt routine instead. For[/color]
    the[color=blue]
    > life of me I can't seem to get the correct syntax and/or I don't have[/color]
    the[color=blue]
    > twelve lines in (on top?) of a suitable container. A little[/color]
    assistance[color=blue]
    > would be most appreciated.[/color]

    Before we can answer your question, you need to clarify some things for
    us. I presume the 12 lines that are "drawn" on the ImageBox are Line
    controls... are they in a control array (that is, do they all have the
    same Name, with different Index values... if so, what is that name) or
    does each Line control have its own name (such as Line1, Line2, etc.)?
    If they each have their own Name, are there any other Line controls in
    the project beside these 12? If yes, what are the names of the 12 Line
    controls that appear over the ImageBox?

    Rick - MVP

    Comment

    • Kiteman - Canada

      #3
      Re: For...each...ne xt statement

      The twelve lines are Line controls and were drawn over the Image1 at design
      time.
      They all have the same name, so they are in a control array.
      The name of the lines is "Line" - is that a problem?
      There are zero other Line controls on this form.

      Tom

      [color=blue][color=green]
      >> I have the following:
      >>
      >> a form called Form1
      >> an image called Image1
      >> twelve lines that have been drawn and superimposed on the image
      >>
      >> I wish to have a command button that will toggle the lines on and off.[/color]
      > I[color=green]
      >> am able to do this with a command for each of the twelve lines, but I
      >> thought that I could use a For...Each...Ne xt routine instead. For[/color]
      > the[color=green]
      >> life of me I can't seem to get the correct syntax and/or I don't have[/color]
      > the[color=green]
      >> twelve lines in (on top?) of a suitable container. A little[/color]
      > assistance[color=green]
      >> would be most appreciated.[/color]
      >
      > Before we can answer your question, you need to clarify some things for
      > us. I presume the 12 lines that are "drawn" on the ImageBox are Line
      > controls... are they in a control array (that is, do they all have the
      > same Name, with different Index values... if so, what is that name) or
      > does each Line control have its own name (such as Line1, Line2, etc.)?
      > If they each have their own Name, are there any other Line controls in
      > the project beside these 12? If yes, what are the names of the 12 Line
      > controls that appear over the ImageBox?
      >
      > Rick - MVP
      >[/color]


      Comment

      • Rick Rothstein

        #4
        Re: For...each...ne xt statement

        Yes, I think naming your Line Controls "Line" is a problem. Try naming
        them something else (like MyLine as I did in the code below). Here is
        the code to put in your CommandButton's click event to toggle the Line
        Control's visibility on and off.

        Private Sub Command1_Click( )
        Dim ln As line
        For Each ln In MyLine
        ln.Visible = Not ln.Visible
        Next
        End Sub

        Rick - MVP



        "Kiteman - Canada" <-delete-kiteman@shaw.ca > wrote in message
        news:Wv6_c.3139 19$gE.117876@pd 7tw3no...[color=blue]
        > The twelve lines are Line controls and were drawn over the Image1 at[/color]
        design[color=blue]
        > time.
        > They all have the same name, so they are in a control array.
        > The name of the lines is "Line" - is that a problem?
        > There are zero other Line controls on this form.
        >
        > Tom
        >
        >[color=green][color=darkred]
        > >> I have the following:
        > >>
        > >> a form called Form1
        > >> an image called Image1
        > >> twelve lines that have been drawn and superimposed on the image
        > >>
        > >> I wish to have a command button that will toggle the lines on and[/color][/color][/color]
        off.[color=blue][color=green]
        > > I[color=darkred]
        > >> am able to do this with a command for each of the twelve lines, but[/color][/color][/color]
        I[color=blue][color=green][color=darkred]
        > >> thought that I could use a For...Each...Ne xt routine instead.[/color][/color][/color]
        For[color=blue][color=green]
        > > the[color=darkred]
        > >> life of me I can't seem to get the correct syntax and/or I don't[/color][/color][/color]
        have[color=blue][color=green]
        > > the[color=darkred]
        > >> twelve lines in (on top?) of a suitable container. A little[/color]
        > > assistance[color=darkred]
        > >> would be most appreciated.[/color]
        > >
        > > Before we can answer your question, you need to clarify some things[/color][/color]
        for[color=blue][color=green]
        > > us. I presume the 12 lines that are "drawn" on the ImageBox are Line
        > > controls... are they in a control array (that is, do they all have[/color][/color]
        the[color=blue][color=green]
        > > same Name, with different Index values... if so, what is that name)[/color][/color]
        or[color=blue][color=green]
        > > does each Line control have its own name (such as Line1, Line2,[/color][/color]
        etc.)?[color=blue][color=green]
        > > If they each have their own Name, are there any other Line controls[/color][/color]
        in[color=blue][color=green]
        > > the project beside these 12? If yes, what are the names of the 12[/color][/color]
        Line[color=blue][color=green]
        > > controls that appear over the ImageBox?
        > >
        > > Rick - MVP
        > >[/color]
        >
        >[/color]

        Comment

        • Rick Rothstein

          #5
          Re: For...each...ne xt statement

          > For Each ln In MyLine

          Wow! Does the font in my newsreader make the above look confusing. That
          is a lower case "LN" immediately after the word "Each" and the word next
          to the "LN" is "in" with the first letter upper cased.

          Rick - MVP

          Comment

          • Kiteman - Canada

            #6
            Re: For...each...ne xt statement

            I renamed all of the lines to an array called Vector
            I used the following code and all works just excellent.
            I used a label_click event instead of a "real" command button because I
            needed a "button" whose colour I could customize.

            Private Sub ToggleRFLines()
            Dim RFLines As Line
            For Each RFLines In Vector
            RFLines.Visible = Not RFLines.Visible
            Next
            End Sub

            Private Sub lblDisplayRFLin es_Click()
            Call ToggleRFLines

            If Vector(0).Visib le Then
            lblDisplayRFLin es.Caption = "HIDE REINFORCEMENT LINE"
            Else
            lblDisplayRFLin es.Caption = "SHOW REINFORCEMENT LINE"
            End If

            End Sub

            Thank you very much for the assistance Rick. You truly are a MVP.
            I really like that NOT command to toggle the Visible state of the lines.
            That really saves on code!
            Is there an easier (cleaner) way for me to change the text of the click
            button than checking for see if one of the lines "Vector(0)" is visible?


            Tom



            "Rick Rothstein" <rickNOSPAMnews @NOSPAMcomcast. net> wrote in message
            news:GpOdneheK9 R3aqXcRVn-oA@comcast.com. ..[color=blue]
            > Yes, I think naming your Line Controls "Line" is a problem. Try naming
            > them something else (like MyLine as I did in the code below). Here is
            > the code to put in your CommandButton's click event to toggle the Line
            > Control's visibility on and off.
            >
            > Private Sub Command1_Click( )
            > Dim ln As line
            > For Each ln In MyLine
            > ln.Visible = Not ln.Visible
            > Next
            > End Sub
            >
            > Rick - MVP
            >
            >
            >[/color]


            Comment

            • mickey

              #7
              Re: For...each...ne xt statement

              On Sat, 04 Sep 2004 04:50:53 GMT, "Kiteman - Canada"
              <-delete-kiteman@shaw.ca > you typed some letters in random order:
              [color=blue]
              >I renamed all of the lines to an array called Vector
              >I used the following code and all works just excellent.
              >I used a label_click event instead of a "real" command button because I
              >needed a "button" whose colour I could customize.[/color]

              setting the 'style' property of a button to 'graphical' lets you
              control it's colors

              Groetjenz,

              Mickey
              --
              #### gewoan skrieve su ast ut seist ####

              Comment

              Working...