Solved

Not getting a value from a 1 dimentional array

Posted on 2006-06-27
6
214 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
  • 3
  • 3
6 Comments
 
LVL 5

Expert Comment

by:AdGroot
Comment Utility

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
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:lancerxe
Comment Utility
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 250 total points
Comment Utility
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
Comment Utility
That was it
Thanks
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now