Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 13th, 2005, 6:18 PM   #1
Intimidat0r
Hobbyist Programmer
 
Intimidat0r's Avatar
 
Join Date: May 2005
Location: Don't know, but the padded walls are a nice touch.
Posts: 126
Rep Power: 0 Intimidat0r is an unknown quantity at this point
Send a message via ICQ to Intimidat0r Send a message via AIM to Intimidat0r Send a message via MSN to Intimidat0r Send a message via Yahoo to Intimidat0r
array of form controls

apparently i can't do this:

Dim TextBoxArray() As TextBox

Vb.net says "cannot convert type of System.Windows.Forms.TextBox to one-dimensional array of system.windows.forms.textbox"

any idea how i can get something similar to this that would look basicallly the same?

thx
__________________
Children in the dark cause accidents, and accidents in the dark cause children.

http://www.ronincoders.org
Intimidat0r is offline   Reply With Quote
Old Sep 13th, 2005, 8:26 PM   #2
brokenhope
Hobbyist Programmer
 
Join Date: Apr 2005
Posts: 126
Rep Power: 4 brokenhope is on a distinguished road
I dont exactly know a lot about this, but from my experience, when it says that, its because it wants you to specify a max.

Dim TextBoxArray(0 To 4) As Textbox
in VB6 and

Dim TextBoxArray(4) As Textbox
in VB.NET

Im not completely sure but that might be the problem.

EDIT:

Actually I just tried what you had, and it worked for me, so I really dont know, thats strange.
brokenhope is offline   Reply With Quote
Old Sep 13th, 2005, 9:14 PM   #3
Intimidat0r
Hobbyist Programmer
 
Intimidat0r's Avatar
 
Join Date: May 2005
Location: Don't know, but the padded walls are a nice touch.
Posts: 126
Rep Power: 0 Intimidat0r is an unknown quantity at this point
Send a message via ICQ to Intimidat0r Send a message via AIM to Intimidat0r Send a message via MSN to Intimidat0r Send a message via Yahoo to Intimidat0r
oh i figured it out, you have to do

Dim TextBoxArray(4) As TextBox

For I as Integer = 0 To 4
  TextBoxArray(I) = New TextBox
Next

thanks for your help you set me off in the right direction
__________________
Children in the dark cause accidents, and accidents in the dark cause children.

http://www.ronincoders.org
Intimidat0r is offline   Reply With Quote
Old Sep 14th, 2005, 2:30 AM   #4
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
if you also make a bunch of controls (text-boxes) whatever, with the SAME NAME it'll ask you if you want to create a "command array". then you can be like:

text1.item(1).text = "hello world"

etc.
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Old Sep 14th, 2005, 10:15 AM   #5
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Quote:
Originally Posted by bl00dninja
if you also make a bunch of controls (text-boxes) whatever, with the SAME NAME it'll ask you if you want to create a "command array". then you can be like:

text1.item(1).text = "hello world"

etc.
Doesn't work like that in .NET mate. Crazy, I know.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Sep 21st, 2005, 5:24 PM   #6
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
Quote:
Originally Posted by Intimidat0r
oh i figured it out, you have to do

Dim TextBoxArray(4) As TextBox

For I as Integer = 0 To 4
  TextBoxArray(I) = New TextBox
Next

thanks for your help you set me off in the right direction
If you want the textbox to actually be useful you probably want to declare it withevents, and stick a handler on it. You actually can do the VB6 control array handling event (with an index-like parameter), you just need to set the handles dynamically (addhandler). I would suggest sticking this in the object instantatiator (Sub New()) and copying the windows forms designers syntax so as not to run into any garbage collection issues.
Rory is offline   Reply With Quote
Old Sep 22nd, 2005, 1:07 AM   #7
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
i should look into .net a little more then. today in class out teacher was explaining pass by value or reference and i was kind of freaked out about how vb handled it, where you can arbitralily decide whether to do one or the other in the function definition regardless of how the variables or objects are instantiated. my goal is to get through the rest of the vb portion of our class without it erasing any of my good habits from C/C++. shouldn't be hard though, i've only got one more homework project to do cuz i did all the other ones in the first week of class or so. hell, i don't have to do anything till late october.
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Old Oct 23rd, 2005, 5:56 AM   #8
Ithaqua
Newbie
 
Join Date: Oct 2005
Location: The othe side
Posts: 19
Rep Power: 0 Ithaqua is on a distinguished road
Before you can put anyting into your array
Dim TextBoxArray() As TextBox
you will have to give it a upper limit eg
 Dim TextBoxArray(5) As TextBox
__________________
Cheers
Ithaqua
Ithaqua is offline   Reply With Quote
Old Oct 23rd, 2005, 8:10 AM   #9
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
Not necessarily: you might want a variable amount of controls (dynamic array + redim or the arrays methods) for some strange reason. Plus it's more memory efficient (you're immediately allocating 6 empty ranges and pointers even without declaring it As New, whereas TextBoxArray() allocates next to nothing).
Rory is offline   Reply With Quote
Old Oct 23rd, 2005, 9:34 AM   #10
Ithaqua
Newbie
 
Join Date: Oct 2005
Location: The othe side
Posts: 19
Rep Power: 0 Ithaqua is on a distinguished road
Yes, when you decalre the array you dont have to dimension it, but before you can put anything in there then it will have to be a fixed length. Doing it that way will mean you have to redim the array to the approiate length before you can work in it.
__________________
Cheers
Ithaqua
Ithaqua is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:18 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC