[VB] Dynamisch array als parameter

Pagina: 1
Acties:

  • PoweRoy
  • Registratie: April 2002
  • Laatst online: 01:39
zit hier met een probleempje in Visual Basic 6:

Ik heb een programma gemaakt dat met een handscanner werkt. Nu is het zo dat als je met de handscanner een containernr scanned, het programma de bij behorende orders op die containers laat zien op de handscanner.

def in beide projecten (app en dll driver:
Visual Basic:
1
2
3
4
5
Type typArtVor
  por As String 'por-nummer
  art As String 'Artikel-nummer
  per As String 'Verwacht percentage goedkeur
End Type


def in project van applicatie
Visual Basic:
1
2
3
4
5
6
7
Type typUitval
  con As String
  ArtPorLijst() As typArtVor
  ArtPorAantal As Integer
End Type

Static strUitval(MAX_PDT) As typUitval


programma roept de functie aan:
Visual Basic:
1
2
3
AddMessage Str(idc) + " : Container " + strUitval(pdt).con, False

lookupUitval strUitval(pdt).con, strUitval(pdt).ArtPorLijst, strUitval(pdt).ArtPorAantal


de functie:
Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Private Function lookupUitval(ByVal cnr As String, _
                        ByRef artVorLst() As typArtVor, _
                        ByRef artVorAantal As Integer)

    On Error GoTo Errorhandler
  
    Dim lTable2 As NavBiesPL.ContainerInhoud
    Set lTable2 = New NavBiesPL.ContainerInhoud
    
    If lTable2.lookupUitval(cnr, artVorLst, artVorAantal) Then
        lookupUitval = True
    Else
        lookupUitval = False
    End If
    
    Set lTable2 = Nothing
    Exit Function

Errorhandler:
    If Err.Number Then
        AddMessage "Bij lookupUitval fout " & Str(Err.Number) & " geconstateerd", True
        lookupUitval = False
    End If
    Resume Next
End Function


de functie hierboven roept de navbiespl dll aan waar lookupUitval functie inzit:
Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Public Function lookupUitval(ByVal conNr As String, _
                        ByRef artVorLst() As typArtVor, _
                        ByRef artVorAantal As Integer) As Boolean
                          
    On Error GoTo Error_Handler
          
    mRecordSet.SetSearchField "Container Nr.", conNr
    
    artVorAantal = 0
    If (mRecordSet.Query(ObjectName)) Then
        Do
            ReDim Preserve artVorLst(artVorAantal + 1)
            mRecordSet.GetFieldData artVorLst(artVorAantal).art, "Artikel Nr."
            mRecordSet.GetFieldData artVorLst(artVorAantal).por, "POR-Nummer."
            mRecordSet.GetFieldData artVorLst(artVorAantal).per, "Perc Goed"
            artVorAantal = artVorAantal + 1
        Loop Until mRecordSet.MoveNext = False
        lookupUitval = True
    
    Else
        'container niet gevonden
        lookupUitval = False
    End If
    
    Exit Function
    
Error_Handler:
    lookupUitval = False
    Err.Source = ERRORSOURCE & " (lookupUitval method)"
    Call WriteLogInfo(vbTechnischeFout, Err.Number, Err.Source, Err.Description)
End Function


Maar ik krijg een mismatch error: ByRef argument type mismatch
Maar de definitie van typArtVor zit zowel als in het programma als in de dll.

Zie ik iets over het hoofd waar het misgaat :?
(op msdn vond ik een document over deze error. Het ging over als je Dim <var> doet zonder een type te defineren. Maar in het project als in de dll is typArtVor gedeclareerd)

[ Voor 13% gewijzigd door PoweRoy op 29-05-2006 14:04 ]

[This space is for rent]


  • Daos
  • Registratie: Oktober 2004
  • Niet online
De foutmelding zegt dat het werkelijke argument die je meegeeft een ander type heeft dan het formele argument die je gebruikt in je subroutine/functie.

Voorbeeldje:
Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Sub Test()
    Dim x
    Dim y As Variant
    Dim z As String
   
    w = "test w"
    x = "test x"
    y = "test y"
    z = "test z"

    M w 'fout
    M x 'fout
    M y 'fout
    M z 'goed

End Sub

Sub M(msg As String)
    MsgBox msg
End Sub



Als je een foutmelding krijgt, dan kan je ook op "Help" klikken.

  • PoweRoy
  • Registratie: April 2002
  • Laatst online: 01:39
de fout komt op artVorLst bij deze zin
Visual Basic:
1
If lTable2.lookupUitval(cnr, artVorLst, artVorAantal) Then


artVorLst is strUitval(pdt).ArtPorLijst en dat is weer een typArtVor array

maar waarom komt de fout op artVorLst omdat hij beide gedefineerd is als typArtVor in zowel de dll:
Visual Basic:
1
2
3
Public Function lookupUitval(ByVal conNr As String, _
                        ByRef artVorLst() As typArtVor, _
                        ByRef artVorAantal As Integer) As Boolean

als in de applicatie
Visual Basic:
1
2
3
Private Function lookupUitval(ByVal cnr As String, _ 
                        ByRef artVorLst() As typArtVor, _ 
                        ByRef artVorAantal As Integer)

[This space is for rent]


  • farlane
  • Registratie: Maart 2000
  • Laatst online: 11:44
Ik denk dat vb niet vind dat als je die structuur op 2 plaatsen definieert dat het dezelfde typen zijn.

Probeer eens de gemeenschappelijke typen in een tweede dll te definieren en die vanuit je executable en dll te referencen.

[edit]
Hoeft niet perse een dll te zijn, je kunt em ook public maken vanuit de dll maar je moet het dan wel wrappen in een class want je mag niet een public type maken volgens mij.

[ Voor 29% gewijzigd door farlane op 29-05-2006 15:25 ]

Somniferous whisperings of scarlet fields. Sleep calling me and in my dreams i wander. My reality is abandoned (I traverse afar). Not a care if I never everwake.


  • PoweRoy
  • Registratie: April 2002
  • Laatst online: 01:39
Dus het zit er niet in dat het met een paar (kleine) wijzingen werkend krijg.
Omdat de array uit elementen bestaat van 3 strings: zou het mogelijk zijn om een Variant array aan de functie mee te geven die weer een variant terug geeft?

[This space is for rent]


  • Daos
  • Registratie: Oktober 2004
  • Niet online
PoweRoy schreef op maandag 29 mei 2006 @ 16:00:
Dus het zit er niet in dat het met een paar (kleine) wijzingen werkend krijg.
Zie bericht erboven:
Type typArtVor ... End Type uit je app
Public Type typArtVor ... End Type in je dll
Omdat de array uit elementen bestaat van 3 strings: zou het mogelijk zijn om een Variant array aan de functie mee te geven die weer een variant terug geeft?
Waarschijnlijk wel, maar het wordt er niet duidelijker op.

  • PoweRoy
  • Registratie: April 2002
  • Laatst online: 01:39
Daos schreef op maandag 29 mei 2006 @ 16:36:
[...]

Zie bericht erboven:
Type typArtVor ... End Type uit je app
Public Type typArtVor ... End Type in je dll


[...]

Waarschijnlijk wel, maar het wordt er niet duidelijker op.
Ik had het bericht gelezen maar ik dacht dat het veel werk was om het type te gebruiken in de hoofdapplicatie.
Maar na geprobeerd te hebben viel het reuze mee:

def
Visual Basic:
1
2
3
4
5
Type typUitval
  con As String
  ArtPorLijst() As NavBiesPL.typArtVor
  ArtPorAantal As Integer
End Type


functie aanpassing
Visual Basic:
1
2
3
Private Function lookupUitval(ByVal cnr As String, _
                        ByRef artVorLst() As NavBiesPL.typArtVor, _
                        ByRef artVorAantal As Integer)


bedankt voor de reacties :)

[This space is for rent]

Pagina: 1