Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
676to680
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
676to680
676to680
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

in Funktion Array übergeben

in Funktion Array übergeben
10.10.2005 15:58:23
Marco
Hallo,
ich möchte einer Funktion einen Array übergeben, leider funktioniert das nicht. Ich habe folgendes gemacht:

Private Function ArrayErstellen(ByRef arrZellenzuordnung() As String) As String
arrZellenzuordnung(1, 1) = "Hallo11"
arrZellenzuordnung(1, 2) = "Hallo12"
arrZellenzuordnung(2, 1) = "Hallo21"
arrZellenzuordnung(2, 2) = "Hallo22"
arrZellenzuordnung(3, 1) = "Hallo31"
arrZellenzuordnung(3, 2) = "Hallo32"
arrZellenzuordnung(4, 1) = "Hallo41"
arrZellenzuordnung(2, 1) = "Hallo42"
ArrayErstellen = arrZellenzuordnung
End Function

Der Aufruf lautet folgendermaßen:
Dim arrZellenzuordnung(1 To 99, 1 To 99) As String

arrZellenzuordnung() = ArrayErstellen(arrZellenzuordnung)
Was mache ich falsch? Vielen Dank für eure Hilfe!
Gruß, Marco

4
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: in Funktion Array übergeben
10.10.2005 16:27:32
MichaV
Hallo,
Diese Zuweisung geht nur, wenn das linke Array dynamisch deklariert ist.
Außerdem kannst Du nur Funktionen erstellen, die ein Variant- Array zurückgeben.

Private Function ArrayErstellen(ByRef arrZellenzuordnung() As String) As Variant
ReDim arrZellenzuordnung(1 To 4, 1 To 2)
arrZellenzuordnung(1, 1) = "Hallo11"
arrZellenzuordnung(1, 2) = "Hallo12"
arrZellenzuordnung(2, 1) = "Hallo21"
arrZellenzuordnung(2, 2) = "Hallo22"
arrZellenzuordnung(3, 1) = "Hallo31"
arrZellenzuordnung(3, 2) = "Hallo32"
arrZellenzuordnung(4, 1) = "Hallo41"
arrZellenzuordnung(2, 1) = "Hallo42"
ArrayErstellen = arrZellenzuordnung
End Function
Sub Test()
Dim arrZellenzuordnung() As String
arrZellenzuordnung = ArrayErstellen(arrZellenzuordnung)
End Sub

Gruss- Micha
PS: Rückmeldung wäre nett.
Anzeige
AW: in Funktion Array übergeben
10.10.2005 17:04:35
Thomas
Hallo Marco,
versuch's mal in etwa so ...


Option Explicit
Private Sub ArrayErstellen(ByRef myArray() As String)
    myArray(1, 1) = "Hallo11"
    myArray(1, 2) = "Hallo12"
    myArray(2, 1) = "Hallo21"
    myArray(2, 2) = "Hallo22"
    myArray(3, 1) = "Hallo31"
    myArray(3, 2) = "Hallo32"
    myArray(4, 1) = "Hallo41"
    myArray(4, 2) = "Hallo42"
End Sub
Sub Test()
    Dim arrZellenzuordnung(1 To 4, 1 To 2) As String
    Call ArrayErstellen(arrZellenzuordnung)
    MsgBox arrZellenzuordnung(4, 1)
End Sub


Gruss
Thomas
Risi Thomas Softwareentwicklung
Addins - Datenbanklösungen - Komponenten - RTDServer

Anzeige
AW: in Funktion Array übergeben
10.10.2005 17:54:06
Marco
Hallo MichaV und Thomas
vielen Dank für eure Hilfe, hat so funktioniert.
Gruß, Marco
Danke für die Rückmeldung und auch Danke an Thomas
10.10.2005 18:51:18
MichaV

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige