• 0

VB.NET 2005 Count Labels?


Question

2 answers to this question

Recommended Posts

  • 0

int count = 0;
			for (int i = 0; i < Controls.Count; i++)
				if (Controls[i] is Label && Controls[i].Name.IndexOf("lblLetter") == 0)
					count++;
			MessageBox.Show(count.ToString());

That is some C# code to get what you want. I'm not familar with the VB syntax, but it should be easy enough to convert it.

  • 0

Hope this helps:

VB.NET:

Dim labelCount As Integer

		For Each currentLabel As Control In Me.Controls
			If currentLabel.GetType() Is GetType(Label) Then
				labelCount += 1
			End If
		Next

		MessageBox.Show("Theer of labels within the current form is: " & labelCount, "Label Count Total", MessageBoxButtons.OK, MessageBoxIcon.Information)

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.