Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. problem with passing array parameter to the procedure

problem with passing array parameter to the procedure

Scheduled Pinned Locked Moved Visual Basic
helpdata-structuresquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi I have some procedure: Sub SomeSub(ByRef somearray() As Double) 'some code, it doesn't matter End Sub I'm trying to call it in this way: Dim somearray(10) As Double SomeSub (somearray) And I get such error message(it's my translation from polish, so it might be different on your computers): Compilation error: Argument of type Array must be passed by reference (ByRef) I don't know what is wrong. I almost forgot to add, all the code is runned as a macro in Word97 Greetings

    N V 2 Replies Last reply
    0
    • L Lost User

      Hi I have some procedure: Sub SomeSub(ByRef somearray() As Double) 'some code, it doesn't matter End Sub I'm trying to call it in this way: Dim somearray(10) As Double SomeSub (somearray) And I get such error message(it's my translation from polish, so it might be different on your computers): Compilation error: Argument of type Array must be passed by reference (ByRef) I don't know what is wrong. I almost forgot to add, all the code is runned as a macro in Word97 Greetings

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      Try adding the word Call in front of your routine call, this should do the trick, it works on my computer.

      Private Sub Form_Load()

      Dim MyArray(10) As Double
      Call Some(MyArray)

      End Sub

      Sub Some(ByRef SomeArray() As Double)
      MsgBox "Hello"
      End Sub

      Nick Parker


      L 1 Reply Last reply
      0
      • N Nick Parker

        Try adding the word Call in front of your routine call, this should do the trick, it works on my computer.

        Private Sub Form_Load()

        Dim MyArray(10) As Double
        Call Some(MyArray)

        End Sub

        Sub Some(ByRef SomeArray() As Double)
        MsgBox "Hello"
        End Sub

        Nick Parker


        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Great thanks. It works, somehow, VB is very strange.

        N 1 Reply Last reply
        0
        • L Lost User

          Great thanks. It works, somehow, VB is very strange.

          N Offline
          N Offline
          Nick Parker
          wrote on last edited by
          #4

          No problem. :) Nick Parker


          1 Reply Last reply
          0
          • L Lost User

            Hi I have some procedure: Sub SomeSub(ByRef somearray() As Double) 'some code, it doesn't matter End Sub I'm trying to call it in this way: Dim somearray(10) As Double SomeSub (somearray) And I get such error message(it's my translation from polish, so it might be different on your computers): Compilation error: Argument of type Array must be passed by reference (ByRef) I don't know what is wrong. I almost forgot to add, all the code is runned as a macro in Word97 Greetings

            V Offline
            V Offline
            Vi2
            wrote on last edited by
            #5

            This small example will help to understand the role of "()" around the argument Sub Func(ByRef i As Long) i = 12 End Sub Private Sub Form_Load() Dim j As Long j = 33 Call Func(j) ' **ByRef** Debug.Print "j="; j ' the output will be: j= **12** j = 33 Call Func((j)) ' **ByVal** Debug.Print "j="; j ' the output will be: j= **33** j = 33 Func (j) ' **ByVal**. Note that there is the space between function name and argument Debug.Print "j="; j ' the output will be: j= **33** Unload Me End Sub With best wishes, Vita

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups