none
Use the array RRS feed

  • Domanda

  • Hi,

    The Sub Tombmuvelet() I want to use the elements of the tomb() array.
    I would like to specify the value of the elements of the array Function Tombfeltolt() in the procedure.

    Sub Tombmuvelet()
     Dim tomb(7)
     Dim sz As Integer
     Call Tombfeltolt
     sz = tomb(1)
    sz1=tomb(2)
    sz2=tomb(3)
     Range("A1").Select
    End Sub
    Function Tombfeltolt()
    Dim i As Integer
    For i = 0 To 6
    tomb(i) = i + 2
    Next i

    End Function

    Thank  for Your helps,

    Best regards,

    Józsi

    sabato 7 dicembre 2019 05:42

Risposte

  • Instead of using a function, you can pass the array to Tombfeltolt:

    Sub Tombmuvelet()
        Dim tomb(6)
        Dim sz As Integer, sz1 As Integer, sz2 As Integer
        Call Tombfeltolt(tomb)
        sz = tomb(1)
        sz1 = tomb(2)
        sz2 = tomb(3)
    End Sub
    
    Sub Tombfeltolt(tomb)
        Dim i As Integer
        For i = 0 To 6
            tomb(i) = i + 2
        Next i
    End Sub


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Contrassegnato come risposta kuljoz sabato 7 dicembre 2019 11:20
    sabato 7 dicembre 2019 10:25
  • Hi,

    I suppose you need to define tomb in Function Tombfeltolt, otherwise you need to
      1) pass over tomb as an argument of Function Tombfeltolt or
      2) define tomb(7) outside of Sub Tombmuvelet

    1) argument or parameter

    Option Explicit

    Sub Tombmuvelet() Dim tomb(7) As Integer Dim sz As Integer Call Tombfeltolt(tomb) sz = tomb(1) sz1 = tomb(2) sz2 = tomb(3) Range("A1").Select End Sub Function Tombfeltolt(ByRef tomb() As Integer) Dim i As Integer For i = 0 To 6 tomb(i) = i + 2 Next i End Function

    2) variable outside of sub
    Option Explicit
    
    Dim tomb(7) As Integer    ' --<< outside of sub
    
    Sub Tombmuvelet()
        Dim sz As Integer
        Call Tombfeltolt(tomb)
        sz = tomb(1)
        sz1 = tomb(2)
        sz2 = tomb(3)
        Range("A1").Select
    End Sub
    
    Function Tombfeltolt()
        Dim i As Integer
        For i = 0 To 6
            tomb(i) = i + 2
        Next i
    End Function
    Regards,

    Ashidacchi -- http://hokusosha.com


    • Modificato Ashidacchi sabato 7 dicembre 2019 10:31
    • Contrassegnato come risposta kuljoz sabato 7 dicembre 2019 11:20
    sabato 7 dicembre 2019 10:30

Tutte le risposte

  • Instead of using a function, you can pass the array to Tombfeltolt:

    Sub Tombmuvelet()
        Dim tomb(6)
        Dim sz As Integer, sz1 As Integer, sz2 As Integer
        Call Tombfeltolt(tomb)
        sz = tomb(1)
        sz1 = tomb(2)
        sz2 = tomb(3)
    End Sub
    
    Sub Tombfeltolt(tomb)
        Dim i As Integer
        For i = 0 To 6
            tomb(i) = i + 2
        Next i
    End Sub


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Contrassegnato come risposta kuljoz sabato 7 dicembre 2019 11:20
    sabato 7 dicembre 2019 10:25
  • Hi,

    I suppose you need to define tomb in Function Tombfeltolt, otherwise you need to
      1) pass over tomb as an argument of Function Tombfeltolt or
      2) define tomb(7) outside of Sub Tombmuvelet

    1) argument or parameter

    Option Explicit

    Sub Tombmuvelet() Dim tomb(7) As Integer Dim sz As Integer Call Tombfeltolt(tomb) sz = tomb(1) sz1 = tomb(2) sz2 = tomb(3) Range("A1").Select End Sub Function Tombfeltolt(ByRef tomb() As Integer) Dim i As Integer For i = 0 To 6 tomb(i) = i + 2 Next i End Function

    2) variable outside of sub
    Option Explicit
    
    Dim tomb(7) As Integer    ' --<< outside of sub
    
    Sub Tombmuvelet()
        Dim sz As Integer
        Call Tombfeltolt(tomb)
        sz = tomb(1)
        sz1 = tomb(2)
        sz2 = tomb(3)
        Range("A1").Select
    End Sub
    
    Function Tombfeltolt()
        Dim i As Integer
        For i = 0 To 6
            tomb(i) = i + 2
        Next i
    End Function
    Regards,

    Ashidacchi -- http://hokusosha.com


    • Modificato Ashidacchi sabato 7 dicembre 2019 10:31
    • Contrassegnato come risposta kuljoz sabato 7 dicembre 2019 11:20
    sabato 7 dicembre 2019 10:30
  • Hi,

    The second varieble prints an error message.

    Best regards,

    Józsi

    sabato 7 dicembre 2019 11:29
  • Hi Józsi,

    Sorry, I provide both code without executing it (only an idea on paper).
    How about the first code? Did it work with no errors?

    Regards,

    Ashidacchi -- http://hokusosha.com

    sabato 7 dicembre 2019 11:35