?
Solved

Not getting a value from a 1 dimentional array

Posted on 2006-06-27
6
Medium Priority
?
222 Views
Last Modified: 2010-04-16
Hello experts:

Can someone please tell me why the code snippet below does not work.
The loop works and it populates RecContent just fine
but LDAcctNo is not populated

for (intCounter = 0; intCounter <= intLastElement; intCounter++)
{
RecContent = LoanDetArray.GetValue (intCounter).ToString();
LDAcctNo = RecContent.ToCharArray(0,20).ToString();
}
                                          
Thanks
0
Comment
Question by:lancerxe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 5

Expert Comment

by:AdGroot
ID: 16994226

If I look at your code you are filling RecContent in a loop
you must assign LDAcctNo after you have finished de loop

for (intCounter = 0; intCounter <= intLastElement; intCounter++)
{
RecContent = LoanDetArray.GetValue (intCounter).ToString();
}

LDAcctNo = RecContent.ToCharArray(0,20).ToString();

Ad
0
 

Author Comment

by:lancerxe
ID: 16994455
Everytime the RecContent is populated I need to
get the LDAcctNo also
 
How can I make the LDAcctNo = RecContent.ToCharArray(0,20).ToString();
part of the loop?
0
 
LVL 5

Expert Comment

by:AdGroot
ID: 16994509
I think i mist the point,
I just tried your code,

do you get a exception ???

you do not check the length of RecCont.

change the code to

                LDAcctNo = RecContent.ToCharArray(0, Math.Min(20,RecContent.Length)).ToString();

I hope that this is your problem

what are the types of LDAcctNo and RecContent ??

Ad

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:lancerxe
ID: 16994616
I don't get an exception
but when I step thru the code
RecContent gets populated and the 1st record has accountnumber 00000000000000000001
but LDAcctNo does not.
When I put the cursor on top of it , it says "System.Char[]". I was expecting to see 00000000000000000001

I get this error with my original code or your code.  

Both are strings
 
0
 
LVL 5

Accepted Solution

by:
AdGroot earned 1000 total points
ID: 16994830
I get the same error

Why do you use  RecContent.ToCharArray(0,20).ToString();
The ToString is not implemeted to ToCharArray and gives back the type

if you try to copy a substring use

LDAcctNo = RecContent.Substring(0, 20);

Ad
0
 

Author Comment

by:lancerxe
ID: 16994917
That was it
Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question