473,385 Members | 1,343 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.

Appending text to an array of textboxes

Hi,
I want to be able to append text using a For loop to each textbox in an
array of textboxes that I've created, called tBoxes(). Basically I
want to add a number of spaces to each textbox in the array. ie. If
spaces(0) = 3, I'd want to add 3 spaces (" ") to tBoxes(0), if
spaces(1) = 4, I'd want to add 4 spaces (" ") to tBoxes(1), and so
on. My code looks something like this...

Dim i as integer
Dim j as integer
Dim m as integer

' I determine value j, which is the length of each of my arrays
j = some integer

Dim tBoxes(j-1) as textbox
Dim spaces(j-1) as integer

' I determine the number of spaces and assign integer values to the
array spaces(i)

' For each textbox, I try to append a space for each integer in
spaces(i), but it doesn't work.
For i = 0 To j - 1
For m = 1 To spaces(i)
tBoxes(i).AppendText(" ")
Next
Next

When I run the code I get an error: "NullReferenceException was
unhandled" and "Object reference not set to an instance of an object."

I hope this is all clear. I'm new to programming so any suggestions or
ideas on what I'm doing wrong would be most appreciated. Thanks.

Sep 1 '06 #1
3 1832
Are you actually creating the textboxes anywhere? It just look like
you are initializing an array that is of type textbox. Try something
like this

Dim x(12) As TextBox
For i As Integer = 1 To 12
x(i) = New TextBox()
Next

HTH,
Andrew

Ja**********@ec.gc.ca wrote:
Hi,
I want to be able to append text using a For loop to each textbox in an
array of textboxes that I've created, called tBoxes(). Basically I
want to add a number of spaces to each textbox in the array. ie. If
spaces(0) = 3, I'd want to add 3 spaces (" ") to tBoxes(0), if
spaces(1) = 4, I'd want to add 4 spaces (" ") to tBoxes(1), and so
on. My code looks something like this...

Dim i as integer
Dim j as integer
Dim m as integer

' I determine value j, which is the length of each of my arrays
j = some integer

Dim tBoxes(j-1) as textbox
Dim spaces(j-1) as integer

' I determine the number of spaces and assign integer values to the
array spaces(i)

' For each textbox, I try to append a space for each integer in
spaces(i), but it doesn't work.
For i = 0 To j - 1
For m = 1 To spaces(i)
tBoxes(i).AppendText(" ")
Next
Next

When I run the code I get an error: "NullReferenceException was
unhandled" and "Object reference not set to an instance of an object."

I hope this is all clear. I'm new to programming so any suggestions or
ideas on what I'm doing wrong would be most appreciated. Thanks.
Sep 1 '06 #2
When I run the code I get an error: "NullReferenceException was
unhandled" and "Object reference not set to an instance of an object."
i'm not sure using array is a good way prefer collections

try

Sub ess()

Dim j As Integer

Dim i As Integer

Dim tbx As TextBox

Dim tbcols As New Collection

'filling the collection

For i = 1 To j

tbx = New TextBox

tbcols.Add(tbx, i.ToString)

Next

'look into the collection

For Each tbx In tbcols

Next

End Sub

<Ja**********@ec.gc.caa écrit dans le message de news:
11*********************@m79g2000cwm.googlegroups.c om...
Hi,
I want to be able to append text using a For loop to each textbox in an
array of textboxes that I've created, called tBoxes(). Basically I
want to add a number of spaces to each textbox in the array. ie. If
spaces(0) = 3, I'd want to add 3 spaces (" ") to tBoxes(0), if
spaces(1) = 4, I'd want to add 4 spaces (" ") to tBoxes(1), and so
on. My code looks something like this...

Dim i as integer
Dim j as integer
Dim m as integer

' I determine value j, which is the length of each of my arrays
j = some integer

Dim tBoxes(j-1) as textbox
Dim spaces(j-1) as integer

' I determine the number of spaces and assign integer values to the
array spaces(i)

' For each textbox, I try to append a space for each integer in
spaces(i), but it doesn't work.
For i = 0 To j - 1
For m = 1 To spaces(i)
tBoxes(i).AppendText(" ")
Next
Next

When I run the code I get an error: "NullReferenceException was
unhandled" and "Object reference not set to an instance of an object."

I hope this is all clear. I'm new to programming so any suggestions or
ideas on what I'm doing wrong would be most appreciated. Thanks.

Sep 1 '06 #3
Thanks a lot everyone, with your help I was able to figure it out.
guigui wrote:
When I run the code I get an error: "NullReferenceException was
unhandled" and "Object reference not set to an instance of an object."
i'm not sure using array is a good way prefer collections

try

Sub ess()

Dim j As Integer

Dim i As Integer

Dim tbx As TextBox

Dim tbcols As New Collection

'filling the collection

For i = 1 To j

tbx = New TextBox

tbcols.Add(tbx, i.ToString)

Next

'look into the collection

For Each tbx In tbcols

Next

End Sub

<Ja**********@ec.gc.caa écrit dans le message de news:
11*********************@m79g2000cwm.googlegroups.c om...
Hi,
I want to be able to append text using a For loop to each textbox in an
array of textboxes that I've created, called tBoxes(). Basically I
want to add a number of spaces to each textbox in the array. ie. If
spaces(0) = 3, I'd want to add 3 spaces (" ") to tBoxes(0), if
spaces(1) = 4, I'd want to add 4 spaces (" ") to tBoxes(1), and so
on. My code looks something like this...

Dim i as integer
Dim j as integer
Dim m as integer

' I determine value j, which is the length of each of my arrays
j = some integer

Dim tBoxes(j-1) as textbox
Dim spaces(j-1) as integer

' I determine the number of spaces and assign integer values to the
array spaces(i)

' For each textbox, I try to append a space for each integer in
spaces(i), but it doesn't work.
For i = 0 To j - 1
For m = 1 To spaces(i)
tBoxes(i).AppendText(" ")
Next
Next

When I run the code I get an error: "NullReferenceException was
unhandled" and "Object reference not set to an instance of an object."

I hope this is all clear. I'm new to programming so any suggestions or
ideas on what I'm doing wrong would be most appreciated. Thanks.
Sep 7 '06 #4

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

Similar topics

0
by: GujuBoy | last post by:
i have an array in C++ (array) and i want to append that to the list can i just say list1.append(array) without actually traversing through the entire array and appending... how can i do...
1
by: dmiller23462 | last post by:
Hey guys.... I put an error-handling in my page and have it posted at the complete end of the code, see below(when people were putting in 's I was getting the delimiter errors). Great, I...
2
by: Tom Fitzgibbon | last post by:
Stupid question: How do I loop through many text boxes on a page and get values for each box and put into an array? For example document.CreateEvent.test1.value will not take an array value...
6
by: Bhavin | last post by:
Anybody quickly replies it, would be a great help! I try to create dynamic array of textboxes control in ASP.NET(C#). I got the following error while I tried to assign value to ID property of...
3
by: Charles E. Vopicka | last post by:
i think i already know the answer to the first question but it took me 2 months of searching to find it. i am writing a program that collects user input then stores the data in arrays then when...
0
by: HydroPnik | last post by:
Hi all! What a great community you have here. Being an Access newbie I have already used much information gleaned from the other posters for my current project. I have been tasked with creating a...
16
by: mj.redfox.mj | last post by:
Can anyone help? I have a textbox which I'm programatically adding by using the following code: txtTest = New TextBox txtTest.ID = "txtLeft" + cntCount.ToString...
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
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: 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:
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...
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.