Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET VB.NET Generics
hello
 
I am new with generic types.I have made a function which returns list of integers.
 
Private Function calculate(ByVal eid As String, ByVal fn As String, ByVal from As String) As List(Of Integer)
 
Dim Sol As New List(Of Integer)
 
        Sol.Add(CountNoOfInstallment)
        Sol.Add(NoOfInstallment)
        Sol.Add(InstallmentAmount)
        Sol.Add(FinalAmount)
 
  End Function
 
here all the 4 values i have calculated inside this function. I want to know is this the the right way to do it ??
 
now i am calling this function on pageload
 
Dim MyList As List(Of Integer) = calculate(Request.QueryString("eid").ToString(), Request.QueryString("fn").ToString(), Year)
 
 Dim CountNoOFInstallment As Int32 = MyList.Item(0)
                Dim NoOfInstallment As Int32 = MyList.Item(1)

 
when i used breakpoints MyList shows nothing in it also there is error saying object refrence not set to an instance of object. I know there are many things wrong with the code. please tell me what is wrong and how can it be corrected. I googled but wasn't able to understand then my friend suggested me this website to ask help for.
Posted 20-Jun-12 19:59pm
Edited 20-Jun-12 20:05pm
v4
Comments
Pankaj Nikam at 21-Jun-12 1:22am
   
Have you verified that are getting the values inside the QueryStrings you mentioned?
Aakash Sharma at 21-Jun-12 1:33am
   
yeah!! there are values inside query string.
Pankaj Nikam at 21-Jun-12 4:24am
   
Check out the answer I have mentioned below. Does it help? If it does, please mark it as answer.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I guess the
Return
statement is missing from the Function calculate.
 
Please include the following line before the
End Function
Return Sol

 
So the overall code will look like... :
 
Private Function calculate(ByVal eid As String, ByVal fn As String, ByVal from As String) As List(Of Integer)
'Your calculations here

Dim Sol As New List(Of Integer)
Sol.Add(CountNoOfInstallment)
Sol.Add(NoOfInstallment)
Sol.Add(InstallmentAmount)
Sol.Add(FinalAmount)
 
Return Sol
 
End Function
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Yes, many things are wrong, but major wrong thing is that nothing is clear. Next time, try to create a very short but complete code sample for the sole purpose of addressing a particular isolated problem and asking a question (but in many cases it will help you to find the solution by yourself).
 
Let's see:
The method calculate accepts two strings which are not used in its code. Why would you need those two parameters? Now, you don't show where CountNoOfInstallment, NoOfInstallment, InstallmentAmount, FinalAmount come from? Not from parameters. They must come from some external context; they could be the members of declaring class. Why showing this code if you don't show their declaration.
 
But the main problem is: you do not return anything (it should not compile). You see, you instantiate Sol (do yourself a big favor, never use abbreviations in variable names), add four elements and just return nothing. The result of this operation will be lost and eventually garbage-collected because you simply leave it unreachable (http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29#Reachability_of_an_object[^]). Return the instance of the list you create. That's it.
 
—SA
  Permalink  
Comments
Aakash Sharma at 21-Jun-12 1:40am
   
i didn't showed the working of the function because it's a very large function of about 5 pages. From this function these 4 values along with the 3 other values are to passed to a Sub to bind report.
BDW thanks for your reply. i will keep in mind these things while writing a program or posting here..
Sergey Alexandrovich Kryukov at 29-Jun-12 21:34pm
   
I understand it. That's why it's usually the best way to create some code sample, a highly simplified prototype (retrospectively), focusing on just one isolated problem. First, there is a good change that the simplified code used to reproduce problem also makes it more observable, so you can sort out the problem all by yourself. If not, you still can use this sample in your question.
--SA
Sergey Alexandrovich Kryukov at 29-Jun-12 21:35pm
   
Just take into account my notes, fix those things and try to reproduce the problem on a simplified sample, if the problem is still a problem...
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 21 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100