0

I'm trying to save into a variable the parameters list that I receive in a Function. For example:

Function fTest(xVal1 as Integer, xVal2 as Integer) as String

   wListParams = "xVal1:" & xVal 1 & "#" & "xVal2:" & xVal2

End Function

I want to use this list if an error occurs and send a mail.

What I'm looking it's a way for to build this String without writing every case in every function (more than 1000).

Please help!

Thanks!!!

5
  • can you please explain what you want to do with this code? what will be your expected output Commented Jul 24, 2014 at 16:54
  • The parameters only exist between the line that starts with Function and the line that says End Function, so you can't access them from anywhere else. If you want to use them, you have to use them there. What exactly are you attempting to do? Commented Jul 24, 2014 at 17:06
  • Thanks Sujith, if I can build a string with all parameters recived, if error occurs I can write Log or send mail with details of error like err.description and with le list of parameters that use the function that fails... And then, test in my systems with that parameters for to reproduce the error... Thanks! Commented Jul 24, 2014 at 17:30
  • Thanks Ken, I don´t want the list of parameters outside, I want inside! I need the collection, List o Class that can tell me what parametres is in this call... Thanks! Commented Jul 24, 2014 at 17:32
  • Please provide at least 3 different cases for this without writing every case in every function, so we can get the pattern. Commented Jul 24, 2014 at 18:51

1 Answer 1

1

Do you want to concatenate all the parameters together into one string? If so, try this.

Imports System.Text

Public Function BuildParametersString(ByVal ParamArray parameters() As Integer) As String
    Dim sb As New StringBuilder()
    For i As Integer = 0 To parameters.Count() - 1
        sb.Append(String.Format("xVal{0}:{1}#", i + 1, parameters(i)))
    Next
    Return sb.ToString()
End Function

Private Sub test()
    Dim param1 As Integer = 1, param2 As Integer = 2
    ' passing individual parameters
    Dim s1 As String = BuildParametersString(param1, param2)
    ' passing paramaters in an array
    Dim s2 As String = BuildParametersString({param1, param2})
End Sub
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks! But it's not what I need beacouse the parameters of every function are not an Array...
See the method called test on how to use it. You can (but don't need to) pass an array. You can also send individual parameters. Not sure how you want to use it. Maybe clarify your question?
Hi Dan, It's dificult to explain... I'll try: I have hundred of functions... Each with too many different parameters... I want to insert a code line/subroutine, that put all the values of each param in a string. After this, i call same SubRoutine in all functions... I hope i explain well... Thanks!!!
Why doesn't BuildParametersString work for you? You can call it with any number of parameters and it will build the string for you.
Hi Dan, because this Function needs that i Write the name of each paramentre in every function... What I want is to use a Class, List, or whatelse that can return me the list of the current parameters, for to build a public function and use it in all modeles... Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.