•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 396,971 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,897 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser:
Views: 914 | Replies: 3
![]() |
| |
•
•
Join Date: Mar 2008
Posts: 116
Reputation:
Rep Power: 1
Solved Threads: 0
ParamArray means to allow a subrotine to take a variable no. of arguments.
I m just sending the arguments suppose i send 1,2,3,4,5
I want just the addition of these numbers.
Sub main()
Dim i As Integer
i = Console.ReadLine()
average(i)
Console.ReadLine()
End Sub
Sub average(ByVal ParamArray b() As Integer)
Dim total As Integer = 0
For i As Integer = LBound(b) To UBound(b)
total = total + b(i)
Next
Console.WriteLine(total.ToString)
End Sub
I m not understanding what is wrong in the program,y the o/p is not coming which is intended.
plz go thru it & do reply back.
I m just sending the arguments suppose i send 1,2,3,4,5
I want just the addition of these numbers.
Sub main()
Dim i As Integer
i = Console.ReadLine()
average(i)
Console.ReadLine()
End Sub
Sub average(ByVal ParamArray b() As Integer)
Dim total As Integer = 0
For i As Integer = LBound(b) To UBound(b)
total = total + b(i)
Next
Console.WriteLine(total.ToString)
End Sub
I m not understanding what is wrong in the program,y the o/p is not coming which is intended.
plz go thru it & do reply back.
•
•
Join Date: Dec 2002
Location: West Virginia
Posts: 374
Reputation:
Rep Power: 6
Solved Threads: 37
I have never used a ParamArray but looking at your code your average is asking for an array of integers and you are passing it only an integer.
Dim i as Integer
If you are passing i then define it as:
Dim i() as integer
Dim i as Integer
If you are passing i then define it as:
Dim i() as integer
Wayne
It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
•
•
Join Date: Dec 2002
Location: West Virginia
Posts: 374
Reputation:
Rep Power: 6
Solved Threads: 37
Try this:
This is assuming your input is => 1,2,3
If your input is +> 1 2 3 then change the , in split to a space.
Sub main()
Dim i As String
i = Console.ReadLine()
Console.WriteLine(i)
Dim j() As String = Split(i, ",")
average(j)
Console.ReadLine()
End Sub
Sub average(ByVal ParamArray b() As String)
Dim total As Integer = 0
For i As Integer = LBound(b) To UBound(b)
total = total + CInt(b(i))
Next
Console.WriteLine(total.ToString / (UBound(b) + 1))
End SubThis is assuming your input is => 1,2,3
If your input is +> 1 2 3 then change the , in split to a space.
Last edited by waynespangler : May 10th, 2008 at 9:09 am.
Wayne
It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb VB.NET Marketplace
Similar Threads
- Why I can't see the result (Visual Basic 4 / 5 / 6)
- Working With Dataset (VB.NET)
- vb6 to vb.net conversion problems (VB.NET)
- assigning arrays in VB (Visual Basic 4 / 5 / 6)
Other Threads in the VB.NET Forum
- Previous Thread: Need Help
- Next Thread: RE: Changing the size of a file.


Hybrid Mode