Dim ExtensionArr
ExtensionArr = array("jpg", "gif", "tif")
Jag försöker jämföra en viss fils extension (t.ex. .jpg) med en lista/array på godkända typer. Tyvärr lyser mina kunskaper i detta språk endast med sin frånvaro (om jag är i fel forum ber jag om ursäkt). Hur jag än försöker få till det blir det syntaxfel... Nuvarande försök:
Public Sub Main()
Dim extensionDotPlace, i As Int32
Dim Ext As String
extensionDotPlace = Dts.Variables("ImageFileName").Value.ToString().LastIndexOf(".")
Ext = Dts.Variables("ImageFileName").Value.ToString().Substring(extensionDotPlace + 1)
i = 0
Dts.Variables("OKIMageFile").Value = False
' Här börjar problemet Om det utesluts tom *** så kör programmet snällt.
Dim ExtensionArr As String() = {"jpg", "gif", "tif"}
While Dts.Variables("OKIMageFile").Value = False And i < Len(ExtensionArr) - 1
If Ext = ExtensionArr(i).ToString() Then
Dts.Variables("OKIMageFile").Value = True
End If
i = i + 1
End While
' ***
'test
MessageBox.Show(Dts.Variables("ImageFileName").Value.ToString() + ", Ext = " + Dts.Variables("ImageFileName").Value.ToString().Substring(extensionDotPlace + 1))
Dts.TaskResult = ScriptResults.Success
End Sub
ger felet skrev:
SSIS package "Pip.dtsx" starting.
Error: 0x1 at ST - Check Extension: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Microsoft.SqlServer.Dts.Runtime.DtsRuntimeException: The element cannot be found in a collection. This error happens when you try to retrieve an element from a collection on a container during execution of the package and the element is not there.
---> System.Runtime.InteropServices.COMException (0xC0010009): The element cannot be found in a collection. This error happens when you try to retrieve an element from a collection on a container during execution of the package and the element is not there.at Microsoft.SqlServer.Dts.Runtime.Wrapper.IDTSVariables100.get_Item(Object Index)
at Microsoft.SqlServer.Dts.Runtime.Variables.get_Item(Object index)
--- End of inner exception stack trace ---
at Microsoft.SqlServer.Dts.Runtime.Variables.get_Item(Object index)
at ST_571c3e0e294e4c9792b1fd8f2b568f0f.vbproj.ScriptMain.Main()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
Task failed: ...SSIS package "Pip.dtsx" finished: Failure.
The program '[2200] Pip.dtsx: DTS' has exited with code 0 (0x0).
Idéer om vad som är fel?
