Click here to Skip to main content
15,888,148 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hello

I am new with generic types.I have made a function which returns list of integers.

VB
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
Updated 20-Jun-12 19:05pm
v4
Comments
Pankaj Nikam 21-Jun-12 1:22am    
Have you verified that are getting the values inside the QueryStrings you mentioned?
Aakash Sharma 21-Jun-12 1:33am    
yeah!! there are values inside query string.
Pankaj Nikam 21-Jun-12 4:24am    
Check out the answer I have mentioned below. Does it help? If it does, please mark it as answer.

I guess the
VB
Return
statement is missing from the Function calculate.

Please include the following line before the
VB
End Function

VB
Return Sol


So the overall code will look like... :

VB
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
 
Share this answer
 
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
 
Share this answer
 
Comments
Aakash Sharma 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 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900