Controls.Find: how to use?
Controls.Find: how to use?
Controls.Find: how to use?
Controls.Find: how to use?
Controls.Find: how to use?
Controls.Find: how to use? Controls.Find: how to use? Controls.Find: how to use? Controls.Find: how to use? Controls.Find: how to use? Controls.Find: how to use? Controls.Find: how to use? Controls.Find: how to use?
Controls.Find: how to use? Controls.Find: how to use?
Controls.Find: how to use?
Go Back  Xtreme Visual Basic Talk > > > Controls.Find: how to use?


Reply
 
Thread Tools Display Modes
  #1  
Old 04-26-2013, 11:01 AM
ecka333 ecka333 is offline
Newcomer
 
Join Date: Apr 2013
Posts: 1
Default Controls.Find: how to use?


I am doing my four channel timer for aquarium project. I am using Visual basic.Net Express 2010. Today i faced one ugly problem in this line:

Code:
Me.Controls.Find("TextBox" & Address, True)(0).Text = "0"
Compiler shows error:
"IndexOutOfRangeException was unhandled." and
"Index was outside the bounds of the array."
As i suspect "TextBox" & Address in the parentheses causes the problem. Address variable is byte type and it can be from 1 to 48 and from 53 to 55.
Tried to use
Code:
Me.Controls.Find("TextBox" + Cstr(Address), True)(0).Text = "0"
but result is the same. Then changed text to:
Code:
Me.Controls.Find("TextBox1", True)(0).Text = "0"
and it worked. But this is not a way out to me.
Maybe somebody faced with similar problem?
Reply With Quote
  #2  
Old 04-26-2013, 12:43 PM
AtmaWeapon's Avatar
AtmaWeaponControls.Find: how to use? AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

First, don't ever use "+" to combine strings. Use "&". Depending on circumstances, "+" will sometimes interpret the strings as numbers and perform addition. (I doubt this is the problem.)

Second, how sure are you that Address contains "1", with no spaces or other characters? Have you verified this in a debugger?

Third, have you considered using a control array? It's easier to debug and more elegant, in my opinion.

If I were forced to write this code, it would look like this:
Code:
Dim textBoxId As String = String.Format("TextBox{0}", Address)
Dim candidates() As Control = Me.Controls.Find(textBoxId, True)
candidates(0).Text = "0"
Using more variables makes things easier to debug. It's rarely a bad idea.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 05-27-2013, 03:08 AM
katrina katrina is offline
Newcomer
 
Join Date: May 2013
Posts: 1
Default

I have faced with such problems before and couldn't find solutions. I'll try to use advice mentioned above. I think it'll be helpful.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Controls.Find: how to use?
Controls.Find: how to use?
Controls.Find: how to use? Controls.Find: how to use?
Controls.Find: how to use?
Controls.Find: how to use?
Controls.Find: how to use? Controls.Find: how to use? Controls.Find: how to use? Controls.Find: how to use? Controls.Find: how to use? Controls.Find: how to use? Controls.Find: how to use?
Controls.Find: how to use?
Controls.Find: how to use?
 
Controls.Find: how to use?
Controls.Find: how to use?
 
-->