Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Not getting a value from a 1 dimentional array

Posted on 2006-06-27
6
Medium Priority
?
223 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

647 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