3 Replies Latest reply on Dec 20, 2011 6:31 PM by Steve Welsh

    Type mismatch using Cattools API in VBScript

    Max.Caines

      Hi

      I'm trying to use VBScript to maintain our device database. I keep getting "Type mismatch" when calling "SaveDevice" for new or updated devices, and I can't see why. To test, I've taken the example code from your help file, made what I think are required changes for VBScript, and tried that. It also gets type mismatch errors. Clearly the change from VB to VBScript requires more than this. Can you tell me what I need to do? This is the sample code as converted:

       Dim DB, Device
       
       Set DB = CreateObject("CatToolsAPI.Database")
       If DB.OpenConnection Then 
         Set Device = DB.Devices.AddNew("Cisco.Router.General") 
         If Not Device Is Nothing Then 
           Device.Name = "My Device 01" 
           Device.HostAddress = "192.168.1.1" 
           Device.Group = "My Test Group" 
           Device.RequireVTYLogin = True 
           Device.ConnectionMethod = "Telnet" 
           If DB.Devices.SaveDevice(Device) Then 
             Wscript.Echo Device.Name & " saved to the database OK." 
           Else 
             Wscript.Echo "Adding " & Device.Name & " failed: " & DB.ErrDescription 
           End If 
         Else 
           Wscript.Echo "Creation of a new device failed: " & DB.ErrDescription 
         End If 
       Else 
         Wscript.Echo "DB connection failed: " & DB.ErrDescription 
       End If 
       Set Device = Nothing 
       Set DB = Nothing 

        • Re: Type mismatch using Cattools API in VBScript
          Steve Welsh

          Hi Max.Caines

          I've checked the API code and it would appear that the DeviceSave method requires Device to be strongly typed (as Device) in order to save.

          Unfortunately VBScript creates everything as a variant type which is why you are seeing the type mismatch error.

          Is there any particular reason as to why you are having to use VBScript over VB?

          If you can provide me a bit of further information as to what you mean by 'maintaining your database', then I may be able to suggest another alternative.

          Regards,

          Steve

          • Re: Type mismatch using Cattools API in VBScript
            Max.Caines

            I prefer using VBScript because the development environment required is a copy of Notepad, whereas for VB I need to install Visual Studio or similar. My question would be: why do you prefer VB? However, it's not really a problem - I've now installed VS on the box running Cattools and got my database maintenance program working. And admittedly having the built-in debugger is quite handy. Thanks for getting back to me

            Regards

            Max

              • Re: Type mismatch using Cattools API in VBScript
                Steve Welsh

                No worries Max.

                I believe the CatTools API was specifically designed with VB in mind because VB is the language that CatTools application code is written in, and that was the requirement for the customer use-case at the time.

                Probably a bit of an oversight that it doesn't fully work on VBScript.   From what I can tell, it would require changing the API code to accept variant data types and then perform conversion to the relevant data type within the API function calls.

                I can create a Customer Feature Request case for this if you like? 

                 

                Steve