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

Stringbuilder question

Hi experts,

I am using stringbuilder in a funtion for a fix length text
delimited file for banking stuff.
I received an error on strResult.Insert(141, "".PadLeft(21, " "))

Error: System.ArgumentOutOfRangeException
Message: "Index was out of range. Must be non-negative and less than
the size of the collection.
StackTrace: "at System.Text.StringBuilder.Insert(Int32 index, String
value, Int32 count)
at System.Text.StringBuilder.Insert(Int32 index, String value)
at EPay_Enroller.JenniferFunct.GenerateA(String& strEmpID,
String& strClientAcct, String& strAcctStatus, String&
strAddressFlag, String& strNameFlag)

Any help?
-------------------------------------------------------------------------------------------
Public Function GenerateA(ByRef strEmpID As String, ByRef
strClientAcct As String, ByRef strAcctStatus As String, ByRef
strAddressFlag As String, ByRef strNameFlag As String)

Dim strResult As New System.Text.StringBuilder

Dim GPConnection As SqlConnection

Dim dr As SqlDataReader

Dim GPDataset As New DataSet

GPConnection = New
SqlConnection("................................... ................")
Dim selectCMD As SqlCommand = New SqlCommand("SELECT DDACTNUM,
LASTNAME,FRSTNAME,BRTHDATE FROM UPR00102 where EmployID=' " +
strEmpID + "'", GPConnection)

Dim GPDataAdapter As SqlDataAdapter = New SqlDataAdapter

GPDataAdapter.SelectCommand = selectCMD

Dim EfundAcct As String

Dim LName As String

Dim FName As String

Dim MName As String

Dim DOB As String

Dim Loc As String

Try

GPConnection.Open()

Dim DS As DataSet = New DataSet

GPDataAdapter.Fill(DS, "AcctInfoTble")

EfundAcct = DS.Tables("AcctInfoTble").Rows(0)("DDACTNUM")

LName = DS.Tables("AcctInfoTble").Rows(0)("LASTNAME")

FName = DS.Tables("AcctInfoTble").Rows(0)("FASTNAME")

'Position 1 2A A

strResult.Insert(0, "A ")

'Position 3 10A Employee Number

strResult.Insert(2, strEmpyID.ToString.PadRight(10, " "))

..........codes

'Position 142 21A Filler

strResult.Insert(141, "".PadLeft(21, " "))

.......more codes

--------------------------------------------------------------------------------------------

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Nov 21 '05 #1
1 1065
"JenHu" <je**********@hotmail-dot-com.no-spam.invalid> schrieb:
I am using stringbuilder in a funtion for a fix length text
delimited file for banking stuff.
I received an error on strResult.Insert(141, "".PadLeft(21, " "))

Error: System.ArgumentOutOfRangeException
Message: "Index was out of range. Must be non-negative and less than
the size of the collection.
StackTrace: "at System.Text.StringBuilder.Insert(Int32 index, String
value, Int32 count)


Make sure the buffer is long enough. To do this, check the 'StringBuilder'
object's 'Capacity' property and make the buffer larger in order to use
'Insert' on a certain position.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #2

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

Similar topics

37
by: Kevin C | last post by:
Quick Question: StringBuilder is obviously more efficient dealing with string concatenations than the old '+=' method... however, in dealing with relatively large string concatenations (ie,...
14
by: Bob | last post by:
I have a function that takes in a list of IDs (hundreds) as input parameter and needs to pass the data to another step as a comma delimited string. The source can easily create this list of IDs in...
2
by: Peter | last post by:
Hi, A newbie question .. I want to use an array of length 4 while each array element is a string of 40 chars. I typed .. StringBuilder title = new StringBuilder(40);
5
by: Christof Nordiek | last post by:
Hi, in my Application i have to make a Copy of a StringBuilder, so that, if the new old instance is changed, the you instance will not be affected. I could do something like new...
9
by: Peter Row | last post by:
Hi, I know this has been asked before, but reading the threads it is still not entirely clear. Deciding which .Replace( ) to use when. Typically if I create a string in a loop I always use a...
15
by: DV | last post by:
I have a StringBuilder that has a string with 12,000,000 characters. When I do a ToString(), I expect to have ~25,000,000 bytes worth of memory, yet, I end up with ~43,000,000 bytes. That's...
7
by: KH | last post by:
API question... Why doesn't StringBuilder have IndexOf and other similar methods like String? I can't think of a good reason off the top of my head. Easy to write helper functions to do the...
12
by: Richard Lewis Haggard | last post by:
I thought that the whole point of StringBuilder was that it was supposed to be a faster way of building strings than string. However, I just put together a simple little application to do a...
26
by: Hardy Wang | last post by:
Hi all, I know it is better to handle large string with a StringBuilder, but how does StringBuilder class improve the performance in the background? Thanks! -- WWW:...
3
by: Morgan Cheng | last post by:
In P/Invoke situation, If some *out* parameter is LPWSTR, I can use string or StringBuilder. However, there is one problem about StringBuilder. By default, its Capacity is 16. If the returned...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.