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

Need some array help.

Is this possible? I want to pass an array into a function that contains
txtBox.Text properties... I was thinking something like this, but I
know it won't work

Dim vendorFields(9) As String

vendorFields(0) = "txtVendorName.Text"
vendorFields(1) = "txtVendorStreetAddress.Text"
vendorFields(2) = "txtVendorCity.Text"
....
vendorFields(2) = "111 Star Ave"

but really i want it to translate as

txtVendorStreetAddress.Text = "111 Star Ave"
I know my logic is messed up, is this possible, and if so how coud I do
it? Thanks

Oct 6 '06 #1
13 1457
James,

Why not an array of textboxes

dim myTextBoxes() as Textbox = {txtVendorName,txtVendorStreet,etc}
venodorfields(2).Text = "111StarAvenue"

I hope this helps,

Cor

"James" <ja**********@gmail.comschreef in bericht
news:11*********************@m73g2000cwd.googlegro ups.com...
Is this possible? I want to pass an array into a function that contains
txtBox.Text properties... I was thinking something like this, but I
know it won't work

Dim vendorFields(9) As String

vendorFields(0) = "txtVendorName.Text"
vendorFields(1) = "txtVendorStreetAddress.Text"
vendorFields(2) = "txtVendorCity.Text"
...
vendorFields(2) = "111 Star Ave"

but really i want it to translate as

txtVendorStreetAddress.Text = "111 Star Ave"
I know my logic is messed up, is this possible, and if so how coud I do
it? Thanks

Oct 6 '06 #2
hmmm sounds like a good solution, but i also have one combo box... and
ideas how i could incorporate that into the array?

thanks.
Cor Ligthert [MVP] wrote:
James,

Why not an array of textboxes

dim myTextBoxes() as Textbox = {txtVendorName,txtVendorStreet,etc}
venodorfields(2).Text = "111StarAvenue"

I hope this helps,

Cor

"James" <ja**********@gmail.comschreef in bericht
news:11*********************@m73g2000cwd.googlegro ups.com...
Is this possible? I want to pass an array into a function that contains
txtBox.Text properties... I was thinking something like this, but I
know it won't work

Dim vendorFields(9) As String

vendorFields(0) = "txtVendorName.Text"
vendorFields(1) = "txtVendorStreetAddress.Text"
vendorFields(2) = "txtVendorCity.Text"
...
vendorFields(2) = "111 Star Ave"

but really i want it to translate as

txtVendorStreetAddress.Text = "111 Star Ave"
I know my logic is messed up, is this possible, and if so how coud I do
it? Thanks
Oct 6 '06 #3
James,

That is so nice, you can use it with a combobox too.
However than you only need to change the array as

dim ctr() as controls = ...........................

Text is a property from controls and therefore as well in the textbox as in
the combobox. You don't have to do anything more, text is inherited.

I hope this helps,

Cor
"James" <ja**********@gmail.comschreef in bericht
news:11********************@c28g2000cwb.googlegrou ps.com...
hmmm sounds like a good solution, but i also have one combo box... and
ideas how i could incorporate that into the array?

thanks.
Cor Ligthert [MVP] wrote:
>James,

Why not an array of textboxes

dim myTextBoxes() as Textbox = {txtVendorName,txtVendorStreet,etc}
venodorfields(2).Text = "111StarAvenue"

I hope this helps,

Cor

"James" <ja**********@gmail.comschreef in bericht
news:11*********************@m73g2000cwd.googlegr oups.com...
Is this possible? I want to pass an array into a function that contains
txtBox.Text properties... I was thinking something like this, but I
know it won't work

Dim vendorFields(9) As String

vendorFields(0) = "txtVendorName.Text"
vendorFields(1) = "txtVendorStreetAddress.Text"
vendorFields(2) = "txtVendorCity.Text"
...
vendorFields(2) = "111 Star Ave"

but really i want it to translate as

txtVendorStreetAddress.Text = "111 Star Ave"
I know my logic is messed up, is this possible, and if so how coud I do
it? Thanks

Oct 6 '06 #4
Great, thanks for all your help. Much appreciated!
Cor Ligthert [MVP] wrote:
James,

That is so nice, you can use it with a combobox too.
However than you only need to change the array as

dim ctr() as controls = ...........................

Text is a property from controls and therefore as well in the textbox as in
the combobox. You don't have to do anything more, text is inherited.

I hope this helps,

Cor
"James" <ja**********@gmail.comschreef in bericht
news:11********************@c28g2000cwb.googlegrou ps.com...
hmmm sounds like a good solution, but i also have one combo box... and
ideas how i could incorporate that into the array?

thanks.
Cor Ligthert [MVP] wrote:
James,

Why not an array of textboxes

dim myTextBoxes() as Textbox = {txtVendorName,txtVendorStreet,etc}
venodorfields(2).Text = "111StarAvenue"

I hope this helps,

Cor

"James" <ja**********@gmail.comschreef in bericht
news:11*********************@m73g2000cwd.googlegro ups.com...
Is this possible? I want to pass an array into a function that contains
txtBox.Text properties... I was thinking something like this, but I
know it won't work

Dim vendorFields(9) As String

vendorFields(0) = "txtVendorName.Text"
vendorFields(1) = "txtVendorStreetAddress.Text"
vendorFields(2) = "txtVendorCity.Text"
...
vendorFields(2) = "111 Star Ave"

but really i want it to translate as

txtVendorStreetAddress.Text = "111 Star Ave"
I know my logic is messed up, is this possible, and if so how coud I do
it? Thanks
Oct 6 '06 #5
Cor,

Well, I thought I was done... but when my code gets to this line:

ctrTextFieldNames(intFieldsRead).Text =
Microsoft.VisualBasic.Left(strReadVendorFile, intFieldValue)

it triggers this error:
An unhandled exception of type 'System.NullReferenceException' occurred
in Appointment.exe

Additional information: Object reference not set to an instance of an
object.
Here's the code so you can get a feel of that line in context. Thanks
for your help.
Dim ctrvendorFields() As Control = {txtVendorName,
txtVendorStreetAddress, txtVendorCity, txtVendorState, txtVendorZip,
txtVendorPhone, txtVendorCOutstandingBill, txtVendorSalesRepName,
txtVendorComments, cboVendorPerferredPmtPeriod}
Private Sub fillTextFields(ByVal ctrTextFieldNames() As Control)
Dim intNumOfFields As Integer = 0
Dim intFieldsRead As Integer = 0
Dim intFieldValue As Integer
Dim strFieldValue As String
strReadVendorFile = VendorFile.ReadLine()
'Store the number of records as an integer value
intNumOfFields = ctrTextFieldNames.Length

'loop to fill all fields
Do Until intFieldsRead = intNumOfFields + 1
'this is a comma delimited text file we are reading from
'find the length to the first comma
intFieldValue = InStr(strReadVendorFile, ",")
'based on the position of the first commma, write the value
on the left
'side of the comma to the .Text property of the record in
the Control Array
ctrTextFieldNames(intFieldsRead).Text =
Microsoft.VisualBasic.Left(strReadVendorFile, intFieldValue)
'redefine the string so it only contains the remaining
comma delimited fields
'figure out a way to have a flexible value (ie the 100
needs to change)
strReadVendorFile =
Microsoft.VisualBasic.Right(strFieldValue, 100)
intFieldsRead += 1
Loop
End Sub

Oct 6 '06 #6

James wrote:
<snip>
ctrTextFieldNames(intFieldsRead).Text =
Microsoft.VisualBasic.Left(strReadVendorFile, intFieldValue)

it triggers this error:
An unhandled exception of type 'System.NullReferenceException' occurred
in Appointment.exe
<snip>
intNumOfFields = ctrTextFieldNames.Length

'loop to fill all fields
Do Until intFieldsRead = intNumOfFields + 1
<snip>

I guess the previous line shoud be

Do Until intFieldsRead = intNumOfFields

HTH.

Regards,

Branco.

Oct 6 '06 #7
yeah... but it's still erroring out at that outher spot, i figured what
you just told me needed to be changed, i just wasn't sure yet.
Branco Medeiros wrote:
James wrote:
<snip>
ctrTextFieldNames(intFieldsRead).Text =
Microsoft.VisualBasic.Left(strReadVendorFile, intFieldValue)

it triggers this error:
An unhandled exception of type 'System.NullReferenceException' occurred
in Appointment.exe

<snip>
intNumOfFields = ctrTextFieldNames.Length

'loop to fill all fields
Do Until intFieldsRead = intNumOfFields + 1
<snip>

I guess the previous line shoud be

Do Until intFieldsRead = intNumOfFields

HTH.

Regards,

Branco.
Oct 6 '06 #8
Sorry, no response here lately, I still am searching for an answer to
my error. Any ideas? Thanks

James wrote:
yeah... but it's still erroring out at that outher spot, i figured what
you just told me needed to be changed, i just wasn't sure yet.
Branco Medeiros wrote:
James wrote:
<snip>
ctrTextFieldNames(intFieldsRead).Text =
Microsoft.VisualBasic.Left(strReadVendorFile, intFieldValue)
>
it triggers this error:
An unhandled exception of type 'System.NullReferenceException' occurred
in Appointment.exe
<snip>
intNumOfFields = ctrTextFieldNames.Length
>
'loop to fill all fields
Do Until intFieldsRead = intNumOfFields + 1
<snip>

I guess the previous line shoud be

Do Until intFieldsRead = intNumOfFields

HTH.

Regards,

Branco.
Oct 8 '06 #9
James wrote:
Sorry, no response here lately, I still am searching for an answer to
my error. Any ideas? Thanks
Well, I guess your code need some fixes... ;-)

The internal loop can be much simpler:

Private Sub fillTextFields(ByVal TextControls() As Control)
'Populates the controls in TextControls with the fields read from the
'curretn line of the vendor file

'Splits the comma separated items from the line read
'from VendorFile
Dim Texts() As String = VendorFile.ReadLine().Split(","c)

'iterates by each field and saves it on the corresponding control
For Field As Integer = 0 To _
System.Math.Min(Texts.Length, TextControls.Length) - 1
TextControls(Field).Text = Texts(Field).Trim
Next
End Sub
>From a previous post:
<snip>
Private Sub fillTextFields(ByVal ctrTextFieldNames() As Control)
Dim intNumOfFields As Integer = 0
Dim intFieldsRead As Integer = 0
Dim intFieldValue As Integer
Dim strFieldValue As String
strReadVendorFile = VendorFile.ReadLine()
strReadVendorFile is a local string, why isn't it declared inside the
sub? Can it be you're not using "Option Explicit"? If so, you probably
mistyped a control name in your control array. Go activate Option
Explicit first, and *then* come back here... =)))
'Store the number of records as an integer value
intNumOfFields = ctrTextFieldNames.Length
'loop to fill all fields
Do Until intFieldsRead = intNumOfFields + 1
As I told you, this line must be

Do Until intFieldsRead = intNumOfFields
'this is a comma delimited text file we are reading from
'find the length to the first comma
intFieldValue = InStr(strReadVendorFile, ",")
I personally preffer the intrinsic methods unless a library one
provides anything extra. In this case, *IMHO*, you should use

intFiledValue = strReadVendorFile.IndexOf(","c)

instead of InStr... besides, intFieldValue should be named Pos,
Separator, Split, Comma etc...
'based on the position of the first commma, write the value
on the left
'side of the comma to the .Text property of the record in
the Control Array
ctrTextFieldNames(intFieldsRead).Text =
Microsoft.VisualBasic.Left(strReadVendorFile, intFieldValue)
The same goes for the previous line: you should use (IMHO):

ctrTextFieldNames(intFieldsRead).Text = _
strReadVendorFile.Substring(0, intFielValue - 1 ).Trim
'redefine the string so it only contains the remaining
comma delimited fields
'figure out a way to have a flexible value (ie the 100
needs to change)
strReadVendorFile =
Microsoft.VisualBasic.Right(strFieldValue, 100)
Oooops, what was that? You are trying to get the rightmost 100 chars
from strFieldValue, but this string was never initialized. Therefore,
you're assigning an empty string to strReadVendorFile.

If what you want is to discard the slice you just processed, there are
a number of approches:

strReadVendorFile = Right(strReadVendorFile, _
strReadVendorFile.Length - intFielValue)

Or

strReadVendorFile = Mid(strReadVendorFile, intFielValue + 1)

Or

strReadVendorFile = strReadVendorFile.Substring(intFielValue + 1)

Or

strReadVendorFile = strReadVendorFile.Remove(0, intFielValue + 1)

Etc, etc.

intFieldsRead += 1
Loop
Hmmm if you're just incrementing the intFieldsRead var (which controls
the loop) why not use a For...Next loop, instead?
<snip>

HTH.

Regards and good luck.

Branco.

Oct 8 '06 #10
Ok, well I have some bad news... Option Explicit is on, and all of my
control names are correct.... I replaced my code with yours:

Private Sub fillTextFields(ByVal TextControls() As Control)
'Populates the controls in TextControls with the fields read from the
'curretn line of the vendor file

'Splits the comma separated items from the line read
'from VendorFile
Dim Texts() As String = VendorFile.ReadLine().Split(","c)

'iterates by each field and saves it on the corresponding control
For Field As Integer = 0 To _
System.Math.Min(Texts.Length, TextControls.Length) - 1
TextControls(Field).Text = Texts(Field).Trim
Next
End Sub
and it errors out at:

TextControls(Field).Text = Texts(Field).Trim

When I put the cursor over ____ it says:

TextControls : "TextControls = {Length = 10}"
(Field): "Field = 0"
..Text: "Public Overridable property Text() As String"
Texts: "Text = {Length = 10}"
(Field): "Field = 0"
..Trim: = "Public Function Trim() As String"

The error message it displays is:

"An unhandled exception of type 'System.NullReferenceException'
occurred in Appointment.exe

Additional information: Object reference not set to an instance of an
object."
If there is anything else that I could give you that you think would
help, let me know. Thanks.
Branco Medeiros wrote:
James wrote:
Sorry, no response here lately, I still am searching for an answer to
my error. Any ideas? Thanks

Well, I guess your code need some fixes... ;-)

The internal loop can be much simpler:

Private Sub fillTextFields(ByVal TextControls() As Control)
'Populates the controls in TextControls with the fields read from the
'curretn line of the vendor file

'Splits the comma separated items from the line read
'from VendorFile
Dim Texts() As String = VendorFile.ReadLine().Split(","c)

'iterates by each field and saves it on the corresponding control
For Field As Integer = 0 To _
System.Math.Min(Texts.Length, TextControls.Length) - 1
TextControls(Field).Text = Texts(Field).Trim
Next
End Sub
From a previous post:

<snip>
Private Sub fillTextFields(ByVal ctrTextFieldNames() As Control)
Dim intNumOfFields As Integer = 0
Dim intFieldsRead As Integer = 0
Dim intFieldValue As Integer
Dim strFieldValue As String
strReadVendorFile = VendorFile.ReadLine()

strReadVendorFile is a local string, why isn't it declared inside the
sub? Can it be you're not using "Option Explicit"? If so, you probably
mistyped a control name in your control array. Go activate Option
Explicit first, and *then* come back here... =)))
'Store the number of records as an integer value
intNumOfFields = ctrTextFieldNames.Length
'loop to fill all fields
Do Until intFieldsRead = intNumOfFields + 1

As I told you, this line must be

Do Until intFieldsRead = intNumOfFields
'this is a comma delimited text file we are reading from
'find the length to the first comma
intFieldValue = InStr(strReadVendorFile, ",")

I personally preffer the intrinsic methods unless a library one
provides anything extra. In this case, *IMHO*, you should use

intFiledValue = strReadVendorFile.IndexOf(","c)

instead of InStr... besides, intFieldValue should be named Pos,
Separator, Split, Comma etc...
'based on the position of the first commma, write the value
on the left
'side of the comma to the .Text property of the record in
the Control Array
ctrTextFieldNames(intFieldsRead).Text =
Microsoft.VisualBasic.Left(strReadVendorFile, intFieldValue)

The same goes for the previous line: you should use (IMHO):

ctrTextFieldNames(intFieldsRead).Text = _
strReadVendorFile.Substring(0, intFielValue - 1 ).Trim
'redefine the string so it only contains the remaining
comma delimited fields
'figure out a way to have a flexible value (ie the 100
needs to change)
strReadVendorFile =
Microsoft.VisualBasic.Right(strFieldValue, 100)

Oooops, what was that? You are trying to get the rightmost 100 chars
from strFieldValue, but this string was never initialized. Therefore,
you're assigning an empty string to strReadVendorFile.

If what you want is to discard the slice you just processed, there are
a number of approches:

strReadVendorFile = Right(strReadVendorFile, _
strReadVendorFile.Length - intFielValue)

Or

strReadVendorFile = Mid(strReadVendorFile, intFielValue + 1)

Or

strReadVendorFile = strReadVendorFile.Substring(intFielValue + 1)

Or

strReadVendorFile = strReadVendorFile.Remove(0, intFielValue + 1)

Etc, etc.

intFieldsRead += 1
Loop

Hmmm if you're just incrementing the intFieldsRead var (which controls
the loop) why not use a For...Next loop, instead?
<snip>

HTH.

Regards and good luck.

Branco.
Oct 8 '06 #11

James wrote:
Ok, well I have some bad news... Option Explicit is on, and all of my
control names are correct.... I replaced my code with yours:
<snip>
and it errors out at:

TextControls(Field).Text = Texts(Field).Trim
<split>
The error message it displays is:

"An unhandled exception of type 'System.NullReferenceException'
occurred in Appointment.exe

Additional information: Object reference not set to an instance of an
object."
If there is anything else that I could give you that you think would
help, let me know. Thanks.
Glad to know Option Explicit is on.

Now, the error is coming from the string or it's coming from the
control. One way to know would be to split the offending line in two:

Dim Value As string = Texts(Field).Trim
TextControls(Field).Text = Value

Of course, you might as well check in the immediate window:

? TextControls(Field) Is Nothing
? Texts(Field) Is Nothing

Regards,

Branco.

Oct 9 '06 #12
Ok, I split the line into two, like so:
For Field As Integer = 0 To System.Math.Min(Texts.Length,
TextControls.Length) - 1
Dim Value As String = Texts(Field).Trim
TextControls(Field).Text = Value
Next

It errors out on the TextControls(Field).Text = Value line

After first line:
? TextControls(Field) Is Nothing
True

? Texts(Field) Is Nothing
False

I couldn't test it after the second line b/c it errors out.

I'm pretty sure I had it narrowed down to this issue earlier, do you
have any ideas why the control array isnt working? Thanks for all of
your help.
Branco Medeiros wrote:
James wrote:
Ok, well I have some bad news... Option Explicit is on, and all of my
control names are correct.... I replaced my code with yours:
<snip>
and it errors out at:

TextControls(Field).Text = Texts(Field).Trim
<split>
The error message it displays is:

"An unhandled exception of type 'System.NullReferenceException'
occurred in Appointment.exe

Additional information: Object reference not set to an instance of an
object."
If there is anything else that I could give you that you think would
help, let me know. Thanks.

Glad to know Option Explicit is on.

Now, the error is coming from the string or it's coming from the
control. One way to know would be to split the offending line in two:

Dim Value As string = Texts(Field).Trim
TextControls(Field).Text = Value

Of course, you might as well check in the immediate window:

? TextControls(Field) Is Nothing
? Texts(Field) Is Nothing

Regards,

Branco.
Oct 9 '06 #13
James wrote:
Ok, I split the line into two, like so:
For Field As Integer = 0 To System.Math.Min(Texts.Length,
TextControls.Length) - 1
Dim Value As String = Texts(Field).Trim
TextControls(Field).Text = Value
Next

It errors out on the TextControls(Field).Text = Value line
<snip>

Put a breakpoint in the line where the control array is initialized and
doublecheck its contents, trying to locate the control name that
doesn't turn into an actual control reference.

Is the array declaration and initialization at form scope? If not, post
here the code block where it is initialized, parameters and all.

Post also the snippet from where your sub (the one we're working on) is
beng called...

HTH.

Regards,

Branco.

Oct 9 '06 #14

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

Similar topics

9
by: Nathan Rose | last post by:
Here's my problem. I am reading from a text file using this: if (!file_exists($file)) { echo "Don't exist\n"; return false; } $fd = @fopen($file, 'r'); if (!is_resource($fd))
4
by: KellyH | last post by:
Hi, I hope someone can point me in the right direction. I'll get it out of the way: Yes, I am a college student. No, I am not looking for anyone to do my homework, just looking for help. I have...
3
by: Tommy Lang | last post by:
I am working on this project and I need some help/pointers/comments to get me started, I am stuck. The program will be used to store information in an array while it is running. I need to store...
3
by: ash | last post by:
Hey I am new, but I don't have time to intruduce myself yet. I am intro to C++ and this is a programme I have to write. all the direction are here, It will be very nice of someone to figure this...
23
by: vinod.bhavnani | last post by:
Hello all, I need desperate help Here is the problem: My problem today is with multidimensional arrays. Lets say i have an array A this is a 4 dimensional static array.
8
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only...
12
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that...
5
by: SpreadTooThin | last post by:
If you are deriving a new class from another class, that you must (I assume) know the initializer of the other class. So in myClass import array class myClass(arrary.array): def...
1
by: javabeginner123 | last post by:
i have a java prob, and i have to solve it fast, but i'm just getting to know it, so plz help me solve it with full code completed, thanks so much. the prob is to create a monter fight and there is...
3
by: jac130 | last post by:
the program runs, and user is prompted via inputbox to enter an integer-this is the size of the array, then the user fills the array with that many values...but as the user enters the values, i need...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.