Home All Groups Group Topic Archive Search About

Appending text to an array of textboxes

Author
1 Sep 2006 3:20 PM
Jacob.Bruxer
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.

Author
1 Sep 2006 3:40 PM
Andrew Backer
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

Jacob.Bru***@ec.gc.ca wrote:
Show quoteHide quote
> 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.
Author
1 Sep 2006 3:58 PM
guigui
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





<Jacob.Bru***@ec.gc.ca> a écrit dans le message de news:
1157124023.558689.38***@m79g2000cwm.googlegroups.com...
Show quoteHide quote
> 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.
>
Author
7 Sep 2006 12:28 PM
Jacob.Bruxer
Thanks a lot everyone, with your help I was able to figure it out.


guigui wrote:
Show quoteHide quote
> 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
>
>
>
>
>
> <Jacob.Bru***@ec.gc.ca> a écrit dans le message de news:
> 1157124023.558689.38***@m79g2000cwm.googlegroups.com...
> > 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.
> >