10-13-2017 02:59 PM
I add a little helper example to aboid using non XML syntax.
Just add
CParamString
to your dataplugin and use like shown.
Option Explicit
dim filepath : filepath = "\\Server\Unit01\MW_PV.hst"
' emulate "ConnectParameter" variable of Dataplugin
dim ConnectParameter : ConnectParameter = "<filename readonly='yes'>" & replace(filepath, "&", "&") & "</filename>"
ConnectParameter = ConnectParameter & "<nWeekFromNow>10</nWeekFromNow>"
ConnectParameter = ConnectParameter & "<nWeekLoading>1</nWeekLoading>"
' create helper class
dim paramString : set paramString = new CParamString.Init(ConnectParameter)
' access your parameters
MsgBox paramString.Tag("nWeekFromNow") & VBCRLF & paramString.Tag("nWeekLoading") & VBCRLF & paramString.Tag("doesnotexist")
' Helper class
class CParamString
public function Tag(byref tagName)
Tag = ""
dim nodes : set nodes = doc_.getElementsByTagName(tagName)
dim node : For Each node In nodes
Tag = node.text
exit function
Next
end function
function Init(byRef paramString)
set Init = me
Set doc_ = CreateObject("MSXML2.DOMDocument")
doc_.loadXML("<?xml version='1.0'?><main>" & paramString & "</main>")
end function
private doc_
end class
10-16-2017 12:38 PM - edited 10-16-2017 12:45 PM
Hi AndreasK,
Thank you for your response.
I have updated the plugin with the class and the xml parser as you suggested. However following error happened:
Error in <HST_SelectiveLoading_HV.vbsd> (Line: 395):
Object doesn't support this property or method
The error happened at the following line of the class constructor:
doc_.loadXML("<?xml version='1.0'?><main>" & paramString & "</main>")
This line was called by the class constructor:
dim paramString : set paramString = new CParamString.Init(ConnectParameter)
class CParamString
public function Tag(byref tagName)
Tag = ""
dim nodes : set nodes = doc_.getElementsByTagName(tagName)
dim node : For Each node In nodes
Tag = node.text
exit function
Next
end function
function Init(byRef paramString)
set Init = me
Set doc_ = CreateObject("MSXML2.DOMDocument")
doc_.loadXML("<?xml version='1.0'?><main>" & paramString & "</main>")
end function
private doc_
end class
I tried with a simpler method. Instead of sending filepath and other parameters in the xml string format, I used a simple string with the symbol "|" separating parameters. Then in the plugin, i used split method to parse the received string argument. Same error happened at the split method. It seems like dataplugin does not allow method parsing argument of ReadStore sub.
Please help me to check this.
Thank you.
10-18-2017 01:26 AM
This script should work
DIAdem Script:
Option Explicit dim filePath : filePath = TmpDrv & "abc.paramString" call FileWriteln(filePath, 0, "Just not empty") ' Create a not empty file dim paramString : paramString = "<filename readonly='yes'>" & replace(filepath, "&", "&") & "</filename>" paramString = paramString & "<nWeekFromNow>10</nWeekFromNow>" paramString = paramString & "<nWeekLoading>1</nWeekLoading>" data.root.clear call DataFileLoad(paramString, "ParamString") ' Load it
Plugin Code:
Option Explicit
Sub ReadStore(File)
dim paramString : set paramString = new CParamString.Init(ConnectParameter)
Dim ChannelGroup : Set ChannelGroup = Root.ChannelGroups.Add("MyChannelGroup1")
call ChannelGroup.Properties.Add("nWeekFromNow", paramString.Tag("nWeekFromNow"))
call ChannelGroup.Properties.Add("nWeekLoading", paramString.Tag("nWeekLoading"))
call ChannelGroup.Properties.Add("doesNotExist", paramString.Tag("doesNotExist"))
End Sub
class CParamString
public function Tag(byref tagName)
Tag = ""
dim nodes : set nodes = doc_.getElementsByTagName(tagName)
dim node : For Each node In nodes
Tag = node.text
exit function
Next
end function
function Init(byRef paramString)
set Init = me
Set doc_ = CreateObject("MSXML2.DOMDocument")
doc_.loadXML("<?xml version='1.0'?><main>" & paramString & "</main>")
end function
private doc_
end class
Afterwards the Portal should contain a group that has three additonal properties.
I also attached the dataplugin.
10-18-2017 10:02 AM
Hi AndreasK,
Thank you. Your suggestion works fine. It is interesting that "ConnectParameter" is actually an exclusive variable name used to transfer the first argument of "DataFileLoad" to the plugin.
I also apply this method to my situation. It seems fine when the CParamString can parse the file name and other parameters. However, in my case the "File" argument in ReadStore(File) as an object and thus some properties of this object are used to parse the file structure such as: "File.Position", "File.Info.FileName", "File.GetCharacters", etc.
After CParamString parses the "ConnectParameter" and gets the filename, those information are lost as the error:
Object doesn't support this property or method: 'File.Position'
I tried to create File object, instead of just getting the filename (File = paramString.Tag("filename")), by:
Set oFS = CreateObject("Scripting.FileSystemObject")
Set File = oFS.GetFile(paramString.Tag("filename"))
but still does not work.
Do you have suggestion on this situation?
Thank you
10-18-2017 10:11 AM
Please just extract your additional parameters using the helper class.
Using the variable "ConnectParameter" does not change anything in your plugin.
It just has the parameterstring of the Load command.
10-18-2017 01:32 PM
Perfect! It works as desired.
I did some tests to figure out the mechanism of the argument transfer in this situation.
Here is the script I used to call the plugin "HST_SelectiveLoading_HV":
dim paramString : paramString = "<filename readonly='yes'>" & replace(filepath, "&", "&") & "</filename>" paramString = paramString & "<nWeekFromNow>10</nWeekFromNow>" paramString = paramString & "<nWeekLoading>1</nWeekLoading>" data.root.clear call DataFileLoad(paramString, "HST_SelectiveLoading_HV") ' Load it
The xml-format "paramString" argument of DataFileLoad is sent to "ConnectParameter" of plugin. It contains the "filename" tag and other parameter tags. The tag "filename" is transferred directly to the "File" argument of ReadStore(File). The other parameters can be read from the class.
Interesting! These infor cannot be found in DIAdem help.
Thank you very much for your support.