473,385 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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...Next 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


Jul 17 '05 #1
6 4519
> 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...Next 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.


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

Jul 17 '05 #2
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

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...Next 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.


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

Jul 17 '05 #3
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" <-d*************@shaw.ca> wrote in message
news:Wv6_c.313919$gE.117876@pd7tw3no...
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

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...Next 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.


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



Jul 17 '05 #4
> 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

Jul 17 '05 #5
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 lblDisplayRFLines_Click()
Call ToggleRFLines

If Vector(0).Visible Then
lblDisplayRFLines.Caption = "HIDE REINFORCEMENT LINE"
Else
lblDisplayRFLines.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" <ri************@NOSPAMcomcast.net> wrote in message
news:Gp********************@comcast.com...
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

Jul 17 '05 #6
On Sat, 04 Sep 2004 04:50:53 GMT, "Kiteman - Canada"
<-d*************@shaw.ca> you typed some letters in random order:
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.


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

Groetjenz,

Mickey
--
#### gewoan skrieve su ast ut seist ####
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: jenny | last post by:
Hi, I am trying to find a VB way that would create a folder on all existing drives - the folder name would be the same on each drive. ie c:\backup, d:\backup, etc. But the folders would only be...
3
by: deko | last post by:
Problem: why doesn't this With block work? is it possible to have a For Each loop within a With block? With objWord .Documents.Add Template:=strTemplate, NewTemplate:=False, DocumentType:=0...
2
by: crjunk | last post by:
I'm trying to write a piece of code that will programatically save a record automatically without me having to add a new ' Row.Item("ADD1") = txtAdd1.Text.Trim.ToUpper ' type command each time I...
7
by: Nitromuse | last post by:
What is the proper way to refer to a dataset as the collection in a For Each, Next Statement? I want to loop through a particular column in the dataset, I've tried the following with no sucess. ...
9
by: Geoff Jones | last post by:
Hi Suppose I have a For Each loop, for example, For Each x As DataRow In drMyData ' Do stuff - calculation 1 ' Do more stuff - calculation 2 ' and even more stuff - calculation 3 Next
8
by: Belee | last post by:
I have the following code and it is not passing through the Next statement: Private Function IsItemAlreadyAdded() As Boolean Dim drMyRow As DataRow With Me For Each drMyRow In...
1
by: Martin Widmer | last post by:
Hi Folks. When I iterate through my custom designed collection, I always get the error: "Unable to cast object of type 'System.Collections.DictionaryEntry' to type...
14
by: Drew | last post by:
I need to iterate through a submitted form, inserting data on each pass. In the past, I have always used form elements that were named with numbers at the end, like this, name1 relationship1...
1
by: ll | last post by:
Hi all, I've inherited a site and am currently looking to redesign a page that displays a table of course curriculum, with each row representing a "Topic" of the curriculum. There is a courseID...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.