473,378 Members | 1,527 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,378 software developers and data experts.

VB.NET: filling a sequence named textboxes using for next.

13
Hi, quick question.

I have numbered labels and i want to fill the text using for next.

txt1
txt2
.
.
.
.
.
txt15


i tried using

dim x as integer
for x=i to 15
txt(x).text = x and txt[x].text = x
next

Unfortunately it doesnt work.

Can somebody please tell me how to do it right. Thanks in advance.
Oct 18 '07 #1
9 1960
nev
251 100+
dim x as integer = 1

for each ctl as control in frmMain
if typeof ctl is textbox then
ctl.name = "textboxno" & x
x += 1
end if
next
Oct 18 '07 #2
thelner
13
Thanks nev ive edited t a bit and it works :D
Expand|Select|Wrap|Line Numbers
  1. Dim x As Integer
  2. For x = 1 To 15
  3.     For Each ctl As Control In Me.Controls
  4.         If TypeOf ctl Is TextBox Then
  5.             If ctl.Name = "txt" & x Then
  6.                 ctl.Text = x
  7.             End If
  8.         End If
  9.     Next
Now the problem is it doesnt work on textboxes inside a groupbox.

What's the work around for this?
Oct 18 '07 #3
QVeen72
1,445 Expert 1GB
Hi,

I think, you are using VB.net.. Check this Code :

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim i As Integer
  3. Dim ctl As System.Windows.Forms.TextBox
  4. For Each ctl In GroupBox1.Controls()
  5.    i = i+1
  6.    ctl.Text = i
  7. Next
  8.  
Regards
Veena
Oct 18 '07 #4
nev
251 100+
Hello thelner mah boy! Have you tried queen's code? The groupbox control is a type of container control so instead of reading the controls in the form container, read it in form.groupbox container :-)

The code reads like

For each control inside this container...
'do this
Next
Oct 18 '07 #5
thelner
13
Woot!!! Thanks qveen72! Everything works now.
Expand|Select|Wrap|Line Numbers
  1.         Dim x As Integer
  2.  
  3.         For x = 1 To 15
  4.             For Each grp As GroupBox In Me.Controls
  5.                 If grp.Name = "grp" & x Then
  6.                     For Each ctl As Control In grp.Controls
  7.                         If TypeOf ctl Is TextBox Then
  8.                             ctl.Text = x
  9.                         End If
  10.                         If TypeOf ctl Is RadioButton Then
  11.                             If ctl.Name = "rb" & x & "a" Then
  12.                                 ctl.Text = "a"
  13.                             ElseIf ctl.Name = "rb" & x & "b" Then
  14.                                 ctl.Text = "b"
  15.                             ElseIf ctl.Name = "rb" & x & "c" Then
  16.                                 ctl.Text = "c"
  17.                             ElseIf ctl.Name = "rb" & x & "d" Then
  18.                                 ctl.Text = "d"
  19.                             End If
  20.                         End If
  21.                     Next
  22.                 End If
  23.             Next
  24.         Next
Oct 18 '07 #6
thelner
13
Next question, what if i want to check if those radio buttons (see last post) is checked?

ctl.checked = True doesnt work.
Oct 19 '07 #7
QVeen72
1,445 Expert 1GB
Hi,

use this :

ctl.Value = True

or

ctl.Checked = True


Regards
Veena
Oct 19 '07 #8
thelner
13
Thanks for the reply but it still doesnt work. Value and checked doesnt show after ctl.
Oct 19 '07 #9
thelner
13
Figured it out. :)

DirectCast(ctl, RadioButton).Checked

Thanks all.
Oct 19 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Christopher D. Wiederspan | last post by:
I'm wondering if there's a way to use javascript to disable a ASP.NET web page before it starts to postback. Specifically, here's what I'm running into. I've got a webform that has an autopostback...
0
by: NS | last post by:
Hello, I have a XSD that looks like this: <xs:schema id="FlowInfo" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"...
0
by: shamirza | last post by:
· When was .NET announced? Bill Gates delivered a keynote at Forum 2000, held June 22, 2000, outlining the .NET 'vision'. The July 2000 PDC had a number of sessions on .NET technology, and...
0
by: shamirza | last post by:
· What is view state and use of it? The current property settings of an ASP.NET page and those of any ASP.NET server controls contained within the page. ASP.NET can detect when a form is requested...
1
by: slinky | last post by:
On My Webserver I have an Access Database called "Warehouse.mdb" I have a webform that has: 6 Textboxes named: txtAsset_Number.Text, txtDescription.Text, txtSerial_Number.Text, txtMfg.Text,...
5
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi everyone, I've just started using vb.net (vs.net 2005) after programming in VB6. I've noticed that control arrays are no longer used and need a little help. In VB6 I would have done this to...
4
Frinavale
by: Frinavale | last post by:
Introduction Sometimes, when developing web applications, we need to be able to dynamically load controls based on user selections. The following article describes a simple scenario where TextBox...
1
by: Wernerh | last post by:
Hi all, A little problem someone can help me with. Got Access db connected through Adodc connection populating datagrid etc. What I am trying to achieve is for the database records which are each...
20
by: soonerpgh | last post by:
Hello, all. I am building an ASP application where we have a table named Clients and I am wanting to display a specific client record on a form with textboxes. In other words, I want to have the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?

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.