James said:
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
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.
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.