Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using an XML startup file instead of an ini file

XML

Using an XML startup file instead of an ini file

by  TomKane  Posted    (Edited  )
You should be able to add a reference to your vb project called Microsoft XML, v3.0 - (it might not be that exact version)

Once you do that you can do all kinds of xml parsing or whatever - We have code like this:

Public Sub ReadXMLStartupInfo(strLocalFileName As String)

Dim objXMLDoc As New MSXML2.DOMDocument
Dim objXMLDomNode As MSXML2.IXMLDOMNode
Dim i As Integer
Dim j As Integer
Dim a As String
Dim strErrMessage As String
Dim bRet As Boolean

On Error GoTo Err

i = InStr(strLocalFileName, "/XML=")
If i = 0 Then
strErrMessage = "No XML File Specified, Contact IT Support"
GoTo Err
End If

j = InStr(i + 1, strLocalFileName, "/")
If j > 0 Then
a = Mid$(strLocalFileName, i + 5, j - (i + 5))
Else
a = Mid$(strLocalFileName, i + 5, Len(strLocalFileName) - i)
End If

objXMLDoc.async = False
bRet = objXMLDoc.Load(App.Path & "\" & a)
If bRet <> True Then
strErrMessage = "XML File NOT Found" & vbCrLf & App.Path & "\" & strLocalFileName
GoTo Err
End If
If objXMLDoc.parseError.errorCode <> 0 Then
strErrMessage = "XML Settings not present or not valid."
GoTo Err
End If

Set objXMLDomNode = objXMLDoc.selectSingleNode("/Settings/Server")
If objXMLDomNode Is Nothing Then
strErrMessage = "SERVER Setting NOT Present in Startup file."
GoTo Err
Else
strServer = objXMLDomNode.Text
End If

Set objXMLDomNode = objXMLDoc.selectSingleNode("/Settings/Database")
If objXMLDomNode Is Nothing Then
strErrMessage = "DATABASE Setting NOT Present in Startup file."
GoTo Err
Else
strDatabase = objXMLDomNode.Text
End If

Set objXMLDomNode = objXMLDoc.selectSingleNode("/Settings/PaymentsServer")
If objXMLDomNode Is Nothing Then
strErrMessage = "PAYMENTS SERVER NOT Present in Startup file."
GoTo Err
Else
strPaymentsServer = objXMLDomNode.Text
End If
Exit Sub
Err:
Call MsgBox("Problem with ReadXMLStartupInfo" & vbNewLine & vbNewLine & vbNewLine _
& "Error Source = " & Err.Source & vbNewLine _
& "Error Description = " & Err.Description & vbNewLine _
& "Error Number = " & Err.Number & vbNewLine & vbNewLine _
& "SQL Text = " & strErrMessage)
Screen.MousePointer = vbDefault

End Sub
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top