User Name Password Register
DaniWeb IT Discussion Community
All
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 361,552 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,136 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: 520 | Replies: 3
Reply
Join Date: Mar 2008
Posts: 115
Reputation: sonia sardana is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
sonia sardana sonia sardana is offline Offline
Junior Poster

ParamArray Example

  #1  
May 8th, 2008
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2002
Location: West Virginia
Posts: 334
Reputation: waynespangler is on a distinguished road 
Rep Power: 6
Solved Threads: 26
waynespangler waynespangler is offline Offline
Posting Whiz

Re: ParamArray Example

  #2  
May 8th, 2008
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
Wayne

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
Reply With Quote  
Join Date: Mar 2008
Posts: 115
Reputation: sonia sardana is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
sonia sardana sonia sardana is offline Offline
Junior Poster

Re: ParamArray Example

  #3  
May 9th, 2008
Even when i m passing i() as integer,program is not working correctly...
Reply With Quote  
Join Date: Dec 2002
Location: West Virginia
Posts: 334
Reputation: waynespangler is on a distinguished road 
Rep Power: 6
Solved Threads: 26
waynespangler waynespangler is offline Offline
Posting Whiz

Re: ParamArray Example

  #4  
May 10th, 2008
Try this:
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 Sub

This 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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb VB.NET Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 2:09 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC