View Issue Details

IDProjectCategoryView StatusLast Update
0007173MMW v4Framework: Scripts/Extensionspublic2011-02-16 23:33
Reporterzvezdan Assigned To 
PriorityurgentSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version4.0 
Target Version4.0Fixed in Version4.0 
Summary0007173: Error because VarType(SDBSongData.FileLength) = 20 while it should be = 3 as before
DescriptionBecause of this I am getting VBScript error #458 in some of my scripts: "Variable uses an Automation type not supported in VBScript".

By the way, if you take a look at MSDN description of VarType's arguments, you cannot find value = 20 for any variable type: http://msdn.microsoft.com/en-us/library/3kfz157h%28v=vs.85%29.aspx

Tested 1342 & 1343 builds.
Steps To ReproduceOption Explicit

Sub OnStartup()
    Dim oMenuItem

    Set oMenuItem = SDB.UI.AddMenuItem(SDB.UI.Menu_Edit, 0, 0)
    oMenuItem.Caption = "File size VarType"
    oMenuItem.UseScript = Script.ScriptPath
    oMenuItem.OnClickFunc = "FileSizeVarType"

    Set oMenuItem = SDB.UI.AddMenuItem(SDB.UI.Menu_Edit, 0, 0)
    oMenuItem.Caption = "If you want to get error"
    oMenuItem.UseScript = Script.ScriptPath
    oMenuItem.OnClickFunc = "VarTypeError"
End Sub

Sub FileSizeVarType(oItem)
    If SDB.SelectedSongList.Count Then
        SDB.MessageBox VarType(SDB.SelectedSongList.Item(0).FileLength), _
                mtInformation, Array(mbOk)
    End If
End Sub

Sub VarTypeError(oItem)
    If SDB.SelectedSongList.Count Then
        SDB.MessageBox SDB.SelectedSongList.Item(0).FileLength & " Bytes", _
                mtInformation, Array(mbOk)
    End If
End Sub
TagsNo tags attached.
Fixed in build1345

Relationships

related to 0006277 closedLudek Data type of the File Size field should be int64 
parent of 0008493 closedLudek Bottom left corner shows 10.000 x too much iPod space 

Activities

jiri

2011-01-17 10:04

administrator   ~0022368

This is caused by 0006277. In order to properly support OLE Automation, we probably should have two properties, one using only 32-bits (and thus OLE compatible) and another for full 64-bits. I'd prefer leaving the old name 'FileLength' as 32-bit and add some 'FileLength64' for other purposes.

zvezdan

2011-01-17 15:25

updater   ~0022376

Well, if you ask me, this is wrong. Many scripts would get the mentioned error because of your current implementation. However, the suggestion with two properties for the same thing is also wrong. You should keep just one FileLength property and you should use variable types already existing in the VBScript, not to invent some new unsupported which leads to errors. You could use vbCurrency as variable type (8 bytes, –922,337,203,477.5808 to 922,337,203,685,477.5807), vbDecimal (14 bytes, +/-79,228,162,514,264,337,593,543,950,335 with no decimal point) or even vbDouble. I suppose the variable type of some database field doesn't need to be same as the variable type of the corresponding API property and you could do the type conversion on-the-fly.

jiri

2011-01-17 17:47

administrator   ~0022382

Changing property type from integer to floating point (or other) is not safe either and could break some other code (be it VBS or anything else). So the suggested solution is on the safe side, without any significant drawback.

zvezdan

2011-01-17 18:39

updater   ~0022385

Could you give me some example when changing property type from integer to floating point could break some code? Your solution with VarType = 20 for sure breaks code, not because it use different numeric variable type then before, but because it is not supported by Microsoft. Your suggestion for sure would break code if we need to use two properties for same thing instead of one. I bet that your suggestion with two properties would require more updates to the existing scripts, then my suggestion with vbCurrency.

Ludek

2011-01-19 13:50

developer   ~0022433

Last edited: 2011-01-19 14:08

According to this http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.varianttype.aspx it seems that vbLong should be enough (-9,223,372,036,854,775,808 through 9,223,372,036,854,775,807.)
But according to this http://delphi.about.com/library/weekly/aa121404b.htm it really seems that there isn't an 8-byte signed integer in OLE automation.

Note that this problem also occurs for properties
ISDBSongData:TotalSamples
ISDBSongData:GaplessBytes
ISDBSongData:Bookmark
ISDBTreeNodeEvents:FreeSpace
ISDBDevice:TotalSpace
ISDBDevice:FreeSpace

jiri

2011-01-19 14:27

administrator   ~0022436

Problem is that this vbLong is VB.Net only, the scripting types are different (see e.g. http://www.csidata.com/custserv/onlinehelp/vbsdocs/vbs6.htm and http://www.csidata.com/custserv/onlinehelp/vbsdocs/vbs218.htm)

I haven't realized that VBS doesn't have any 64-bit integer type, so we have to use something different anyway. So let's try to use that vbCurrency type (it's 64-bit integer with fixed 4 digits reserved for fractional part), I suppose that it won't break anything (or much) in VBS code and in case it does in other languages, it will have to be fixed there.

zvezdan

2011-01-19 14:53

updater   ~0022437

Last edited: 2011-01-19 14:57

Yeah, even Visual Basic 6.0 vbLong is 4-bytes only, i.e. between -2147483648 and 2147483647. I tried this part of script as an experiment:
    Dim i
    i = 2147483647
    MsgBox VarType(i) ' displays 3 = vbLong
    i = 2147483648
    MsgBox VarType(i) ' displays 5 = vbDouble

also this:
    Dim i
    i = 2147483647
    MsgBox CLng(i) ' OK
    i = 2147483648
    MsgBox CCur(i) ' OK
    MsgBox CLng(i) ' generates error

Ludek

2011-01-19 14:56

developer   ~0022438

Last edited: 2011-01-19 15:09

vbCurrency seems to work fine for this purposes

Fixed in build 1345

peke

2011-02-16 23:33

developer   ~0023196

Verified 1349