rbulph Posted October 2, 2006 Posted October 2, 2006 Is there any way that you can create an array to pass directly as a parameter? i.e. avoiding the need for the variable f in the following code and just putting the array elements in the call to the procedure: Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim f() As String = {"ioj", "OIJ"} hioh(f) End Sub Private Sub hioh(ByVal f() As String) End Sub End Class It seems to me that there ought to be, but I can't figure out what it is. Quote
Administrators PlausiblyDamp Posted October 2, 2006 Administrators Posted October 2, 2006 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load hioh("ioj", "OIJ") End Sub Private Sub hioh(ByVal ParamArray f() As String) End Sub should be what you are looking for. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
rbulph Posted October 2, 2006 Author Posted October 2, 2006 Oh yes, of course. However it would still be useful if I could do as I was originally anticipating for the case where the procedure wants to take two string arrays, for example. You can't have two ParamArrays as parameters, because there's no way of specifying where one array ends and the next begins. Quote
Leaders snarfblam Posted October 2, 2006 Leaders Posted October 2, 2006 Maybe... Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Call hioh with a newly created array... hioh(New String() {"ioj", "OIJ"}) 'Call that other method with arrays mnkxsjmksdx(New String() {"fe", "htr", "fdsa"}, New String() {"hgt", "htr"} ) End Sub 'Method that accepts an array Private Sub hioh(ByVal f() As String) MessageBox.Show("Recieved array with " & f.Length.ToString() & " elements.") End Sub Private Sub mnkxsjmksdx(ByVal a() As String, ByVal b() As String) End Sub End Class By the way, I like the mash-your-face-into-the-keyboard naming convention. Quote [sIGPIC]e[/sIGPIC]
rbulph Posted October 3, 2006 Author Posted October 3, 2006 Maybe... Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Call hioh with a newly created array... hioh(New String() {"ioj", "OIJ"}) 'Call that other method with arrays mnkxsjmksdx(New String() {"fe", "htr", "fdsa"}, New String() {"hgt", "htr"} ) End Sub 'Method that accepts an array Private Sub hioh(ByVal f() As String) MessageBox.Show("Recieved array with " & f.Length.ToString() & " elements.") End Sub Private Sub mnkxsjmksdx(ByVal a() As String, ByVal b() As String) End Sub End Class By the way, I like the mash-your-face-into-the-keyboard naming convention. Ah yes, that does it, thanks. Contrary to appearances I do use my fingers to select the names - and I find I can do this remarkably quickly. I've also found in earlier professional experience that people who produce absolute rubbish can do it very quickly and it can be hard to criticise because nobody knows what on earth they really intended and it's far too rude to say that it's rubbish. If you're more conscientious then you have to worry about a host of details such as "'i' before 'e' except after 'c'" (!), otherwise it shows. So I use the random technique of name selection (sometimes). Quote
Gill Bates Posted October 3, 2006 Posted October 3, 2006 I've also found in earlier professional experience that people who produce absolute rubbish can do it very quickly and it can be hard to criticise because nobody knows what on earth they really intended...http://mindprod.com/jgloss/unmain.html Quote
rbulph Posted October 4, 2006 Author Posted October 4, 2006 http://mindprod.com/jgloss/unmain.html The sad thing is, there are some people who really do carry on like that. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.