Purpose You want to call up a VB.NET function from JavaScript |
Solution Example Public Class myfileinfo ' return an object of this class Function create() As Object Return New myfileinfo End Function ' return length (in bytes) of a file Public Function length(filename As String) As Integer ' file exists? else return -1 If Not My.Computer.FileSystem.FileExists(filename) Then Return -1 End If ' return file length Return My.Computer.FileSystem.GetFileInfo(filename).Length End Function End Class In our GuiXT script (or InputScript) we create an object of class "myfileinfo" and pass it to JavaScript. Then we call up a JavaScript test function that shows the length of a file, determined via the VB.NET function. GuiXT Script // Create a "myfileinfo" object in VB and pass it to JavaScript CallVB vbFileinfo = utilities.myfileinfo.create CallJS setFileinfo "&V[vbFileinfo]" endif // Test with filelength function In Javascript we store the passed VB.NET object into a global variable. In all subsequent functions we can use its public VB.NET properties, methods and functions: JavaScript // VB object of class "fileinfo" var vbFileinfo; function setFileinfo(obj) { vbFileinfo = obj; } function test(filename) { // determine file length var leng = vbFileinfo.length(filename); // display test message alert(leng); };
Remark Public Class myfileinfo ' return this object Function create() As Object Return me End Function ... |
Components |