[vb6sp5] Probleempje met ENUM in functie

Pagina: 1
Acties:
  • 193 views sinds 30-01-2008
  • Reageer

  • DPLuS
  • Registratie: April 2000
  • Niet online
Ik heb de volgende code:

sub main:
Visual Basic 6:
1
2
3
4
5
6
7
8
Sub Main()

    Dim myobj As clsSettings
    Set myobj = New clsSettings
    MsgBox myobj.GetFromIniFile(MAILSERVICE_FACTUUR)
    Set myobj = Nothing
        
End Sub


in clsSettings:
Visual Basic 6:
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Option Explicit

Public Enum INI_OBJECT
    INI_ID = 1
    TMS_BEVESTIGING = 2
    INCIDENT_BEVESTIGING = 3
    TMS_FACTUUR = 4
    INCIDENT_FACTUUR = 5
    MAILSERVICE_FACTUUR = 6
End Enum

Private m_strIniFile As String

Private Sub Class_Initialize()

m_strIniFile = App.Path & "\FactuurTool.ini"

End Sub

Private Function ParseIniFile(LineNumber As Integer) As String

Dim intFp As Integer
Dim strContents As String
Dim arrContents() As String
Dim i As Integer

i = 1
intFp = FreeFile
Open m_strIniFile For Input As #intFp
Do While Not EOF(intFp)
    Line Input #intFp, strContents
    If LineNumber = i Then
        arrContents = Split(strContents, "=")
        ParseIniFile = arrContents(1)
    End If
i = i + 1
Loop
Close #intFp

End Function

Public Function GetFromIniFile(What As INI_OBJECT) As String

GetFromIniFile = ParseIniFile(What)

End Function


Als ik dit uitvoer krijg ik als foutmelding: ByRef Argument Type Mismatch.

En dan deze functie ge-hilite:

Public Function GetFromIniFile(What As INI_OBJECT) As String
GetFromIniFile = ParseIniFile(What)
End Function


Ik vermoed dat die ENUM niet als een INTEGER geïnterpreteerd wordt door de functie ParseIniFile.
Maar in de ENUM heb ik wel dit staan:
MAILSERVICE_FACTUUR = 6
Dus zou die functie toch Integer "6" moeten doorgeven??

[ Voor 2% gewijzigd door DPLuS op 01-09-2004 15:05 . Reden: typo ]


  • RayNbow
  • Registratie: Maart 2003
  • Laatst online: 19:56

RayNbow

Kirika <3

Visual Basic 6:
1
GetFromIniFile = ParseIniFile(CInt(What))
:)

Addendum:
Visual Basic 6:
1
Private Function ParseIniFile(LineNumber As Integer) As String

vervangen door

Visual Basic 6:
1
Private Function ParseIniFile(ByVal LineNumber As Integer) As String

werkt ook.

[ Voor 71% gewijzigd door RayNbow op 01-09-2004 15:22 ]

Ipsa Scientia Potestas Est
NNID: ShinNoNoir


  • Lorn
  • Registratie: Maart 2000
  • Laatst online: 13-01-2025

Lorn

I have a bad feeling...

Werk je met echte ini-files of alleen met een ini-file achtig iets? Als je een echte ini structuur gebruikt (dus met secties die weer values en data hebben) dan zou je toch beter de Windows API-calls kunnen gebruiken om de data te lezen uit je ini-file.

  • DPLuS
  • Registratie: April 2000
  • Niet online
Geen echte Ini-file, 't was maar een tijdelijke oplossing.
Het ging er mij meer om of die ENUM als INTEGER geïnterpreteerd werd...

Ik heb 't nu gewoon in 1 functie gepakt en nou doet 'ie het wel:

Visual Basic 6:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Public Function GetFromIniFile(What As INI_OBJECT) As String

Dim intFp As Integer
Dim strContents As String
Dim arrContents() As String
Dim i As Integer

i = 1
intFp = FreeFile
Open m_strIniFile For Input As #intFp
Do While Not EOF(intFp)
    Line Input #intFp, strContents
    If What = i Then
        arrContents = Split(strContents, "=")
        GetFromIniFile = arrContents(1)
    End If
i = i + 1
Loop
Close #intFp

End Function


[edit]

Ik heb ook even een watch toegevoegd, en het schijnt dat VB van die WHAT een LONG maakt ipv integer.
Kan ik in een ENUM aangeven welk type een constante moet zijn?

Dit gaat wel:

CONST blaat as INTEGER = 1

Dit gaat niet:

Public ENUM blaat
blaat1 as integer = 1


[edit 2]

Hmmm, uit de DOCS:


Providing Non-Numeric and Non-Integer Constants
The members of an Enum can have any value that fits in a Long. That is, they can assume any integer value from -2,147,483,648 to 2,147,483,647. When you declare a variable using the name of an Enum as the data type, you’re effectively declaring the variable As Long.

Occasionally you may need to provide a string constant, or a constant that isn’t an integer value. Visual Basic doesn’t provide a mechanism for adding such values to your type library as public constants, but you can get a similar effect using a global object with read-only properties.

[ Voor 47% gewijzigd door DPLuS op 01-09-2004 15:40 ]