Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted
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.
  • Leaders
Posted

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.

[sIGPIC]e[/sIGPIC]
Posted
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).

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...