Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2010 > Visual Basic 2010 General Discussion
|
Visual Basic 2010 General Discussion For any discussions about Visual Basic 2010 topics which aren't related to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2010 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 19th, 2011, 03:57 AM
Registered User
 
Join Date: Dec 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to hmclark Send a message via Yahoo to hmclark
Default Using text strings to reference controls

Hi
I am a new user to vb 2010. I want to be able to use a loop and reference controls using a string. The following code works for textboxes.

Code:
dim myControl as Control
dim ControlName as string
dim LoopCount as Integer
For LoopCount = 1 to 3
     ControlName = "TextBox" & cStr(LoopCount)
     myControl = Me.Controls.Item(ControlName)
     myControl.text = "some string here"
Next
However, If I try the same thing with a checkBox control it generates the Following error;
'Checked' is not a member of 'System.Windows.Forms.Control'.

on the line ,"IF myControl.checked = True then"
Code:
dim myControl as Control
dim ControlName as string
dim LoopCount as Integer
For LoopCount = 1 to 3
     ControlName = "CheckBox" & cStr(LoopCount)
     myControl = Me.Controls.Item(ControlName)
     IF myControl.Checked = True Then
         execute some code here 
     End IF
Next
Any help would be greatly apreciated





Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading Strings from Text File problem gian.sobhani C# 2005 1 August 31st, 2009 08:17 AM
Text Strings need help! julz127 Visual Basic 2005 Basics 2 January 26th, 2008 09:49 PM
Place text strings in a text box error_help Excel VBA 1 October 6th, 2005 05:26 AM
Deleting text strings automatically from Database palvin SQL Server 2000 15 October 3rd, 2005 12:52 PM
Custom Controls in Reference bmains VS.NET 2002/2003 0 February 11th, 2004 10:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.