Solved

Not getting a value from a 1 dimentional array

Posted on 2006-06-27
6
221 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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 250 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

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…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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