A
aaapaul
Hello !
I have some values stored in a xml-file. When starting my application,
I read this file and store the values in a collection object.
My problem is the error-handling, if the fieldname does not exist. I
dont want to use try and catch.
The indexof-function to check would be better, but it is not
available.
This is my class:
Public Class clsFestwerte
Public isError As Boolean
Public errMessage As String
Private strDateipfad As String
Private colFestwerte As Collection
Sub New(ByVal pstrPfad As String)
strDateipfad = pstrPfad
colFestwerte = New Collection
XMLDatei_einlesen()
End Sub
Private Sub XMLDatei_einlesen()
Dim strFeldname As String
Dim strFeldwert As String
If File.Exists(strDateipfad) = False Then
Me.errMessage = "Konfigurationsfile " & strDateipfad & "
nicht vorhanden !"
Me.isError = True
Exit Sub
End If
'XML Datei auslesen - Achtung auf Gross- und Kleinschreibung
achten !!
Dim ds As New DataSet
Dim dr As DataRow
Try
ds.ReadXml(strDateipfad)
For Each dr In ds.Tables(0).Rows
strFeldname = dr.Item("feldname")
strFeldwert = dr.Item("feldwert")
colFestwerte.Add(strFeldwert, strFeldname)
Next
Catch objE As Exception
Me.isError = True
Me.errMessage = objE.Message
End Try
End Sub
Public Function getFestwert(ByVal strFeldname As String)
' Here I need: if strfeldname in collection ?? indexof ??
Return colFestwerte.Item(strFeldname)
End Function
End Class
The problem is the getFestwert-Function:
getFestwert("value1") is ok because value1 is in the xml-file.
getFestwert("value2") causes an error, because value2 is not in the
xml-file.
How can I check, if value2 is in the collection ?
There is no indexof-function available.
thanks
aaapaul
I have some values stored in a xml-file. When starting my application,
I read this file and store the values in a collection object.
My problem is the error-handling, if the fieldname does not exist. I
dont want to use try and catch.
The indexof-function to check would be better, but it is not
available.
This is my class:
Public Class clsFestwerte
Public isError As Boolean
Public errMessage As String
Private strDateipfad As String
Private colFestwerte As Collection
Sub New(ByVal pstrPfad As String)
strDateipfad = pstrPfad
colFestwerte = New Collection
XMLDatei_einlesen()
End Sub
Private Sub XMLDatei_einlesen()
Dim strFeldname As String
Dim strFeldwert As String
If File.Exists(strDateipfad) = False Then
Me.errMessage = "Konfigurationsfile " & strDateipfad & "
nicht vorhanden !"
Me.isError = True
Exit Sub
End If
'XML Datei auslesen - Achtung auf Gross- und Kleinschreibung
achten !!
Dim ds As New DataSet
Dim dr As DataRow
Try
ds.ReadXml(strDateipfad)
For Each dr In ds.Tables(0).Rows
strFeldname = dr.Item("feldname")
strFeldwert = dr.Item("feldwert")
colFestwerte.Add(strFeldwert, strFeldname)
Next
Catch objE As Exception
Me.isError = True
Me.errMessage = objE.Message
End Try
End Sub
Public Function getFestwert(ByVal strFeldname As String)
' Here I need: if strfeldname in collection ?? indexof ??
Return colFestwerte.Item(strFeldname)
End Function
End Class
The problem is the getFestwert-Function:
getFestwert("value1") is ok because value1 is in the xml-file.
getFestwert("value2") causes an error, because value2 is not in the
xml-file.
How can I check, if value2 is in the collection ?
There is no indexof-function available.
thanks
aaapaul