CreateFromXML Method
Description
Creates a dialog from an XML resource file.
Syntax
Public Function CreateFromXML( _
ByVal XMLString As String, _
ByVal Section As String, _
Optional ByVal Parameters As Variant _
) As Boolean
Parameters
- XMLString: The contents of an XML file. This string must contain the entire contents of the XML file.
- Section: Name of the XML resource to load. This should be the section that contains the dialog you want to load.
- Parameters: Values to use in the text descriptions of the dialog. More than one parameter can be passed in and can be stored in a string array. These values will be inserted into any text portion of the dialog that contains a
%followed by a number. The number corresponds to a parameter in the array and starts with 1.
For example, 3 parameters are used in the content section of this dialog:
File Download
Do you want to open %3 or save this file?
Name: %1
Type: %2
From: %3
The code to set up the parameters would look like this:
Dim Params(3) As String
Params(0) = "SampleFileName.txt"
Params(1) = "Text Document"
Params(2) = "http://www.Codejock.com"
taskDialog.CreateFromXML LoadDialogs, "Dialogs/Dialog[@Name='Dialog007']", Params
Or you can do it like this:
taskDialog.CreateFromXML LoadDialogs, "Dialogs/Dialog[@Name='Dialog007']", Array("SampleFileName.txt", "Text Document", "http://www.Codejock.com")
Remarks
You can use a utility such as TDPad (TDPad) to design and create task dialogs that are stored in an XML file that can be loaded at any time. For example, the dialog below was created using TDPad:

Example
Example XML Dialog
Below is the XML to create a dialog that will accept 3 parameters.
<FileDownload>
<Title>File Download</Title>
<Message>Do you want to open %3 or save this file?</Message>
<Content>
<Name>%1</Name>
<Type>%2</Type>
<From>%3</From>
</Content>
<Button>
<Open>&Open</Open>
<Save>&Save</Save>
</Button>
<Checkbox>&Always ask before open</Checkbox>
<Warning>While files from the Internet can be useful, some files can potentially harm your computer. If you do not trust the source, do not open or save this file. What's the risk?</Warning>
</FileDownload>
Load From XML File (Visual Basic)
This code will load and display the task dialog in the XML code above.
taskDialog.Reset
taskDialog.CommonButtons = 0
Dim Params(3) As String
Params(0) = "SampleFileName.txt"
Params(1) = "Text Document"
Params(2) = "http://www.Codejock.com"
taskDialog.CreateFromXML LoadDialogs, "Dialogs/Dialog[@Name='Dialog007']", Params
'taskDialog.CreateFromXML LoadDialogs, "Dialogs/Dialog[@Name='Dialog007']", Array("SampleFileName.txt", "Text Document", "http://www.Codejock.com")
taskDialog.ShowDialog
Function LoadDialogs() As String
On Error Resume Next
Dim Dialogs As String
Dim FreeF As Integer, sFile As String
' XML string will be loaded from the file.
sFile = App.Path & "\Dialogs.xml"
FreeF = FreeFile
Dialogs = Space(FileLen(sFile))
Open sFile For Binary As #FreeF
Get #FreeF, , Dialogs
Close #FreeF
On Error Goto 0
LoadDialogs = Dialogs
End Function
See Also
Copyright (c) 1998-2024 Codejock Technologies. All rights reserved.