Export all multi-value parameters to spreadsheet

Export all multi-value parameters to spreadsheet

ahmed.hagi
Enthusiast Enthusiast
3,632 Views
45 Replies
Message 1 of 46

Export all multi-value parameters to spreadsheet

ahmed.hagi
Enthusiast
Enthusiast

Hello,

 

I am trying to compare values which I import from a spreadsheet to the values in my user parameters, i need to compare all the possible values as opposed to the ones which are currently set, for example: If one parameter has imported from the spreadsheet as "Blue" (for a multi value parameter called colour), I want to check that blue is a value in the list for colour. 

Is there a way to do this?

0 Likes
Accepted solutions (2)
3,633 Views
45 Replies
Replies (45)
Message 41 of 46

j.haggenjos
Advocate
Advocate

I'm guessing that for some reason Excel is busy when you try to close it and throws this exception.

0 Likes
Message 42 of 46

ahmed.hagi
Enthusiast
Enthusiast

I'll try restarting my machine and hopefully that works

0 Likes
Message 43 of 46

j.haggenjos
Advocate
Advocate

If the error keeps coming you can try something like this to bypass it:

 

 

 

Dim xLIsClosed As Boolean = False
Dim failSafeCounter As Integer = 0
While Not xLIsClosed Or failSafeCounter < 50
    failSafeCounter += 1
    Try
        excelWorkbook.Close
        excelApp.Quit
        xLIsClosed = True
    Catch ex As Exception
        System.Threading.Thread.Sleep(100)
            If failSafeCounter = 50 Then
                MsgBox("Unable to close excel properly. Please close it manually.")
            End If
    End Try
End While

 

 

 

It will try to close excel. If it fails, it will try again after 0.1 second. It will try again up to 50 times.

After 50 failed tries, the code will go and asks the user to manually close excel. No error message will be given for each of the failed attempt as they are "handled" with the "try/catch" part of the code.

Message 44 of 46

ahmed.hagi
Enthusiast
Enthusiast

 restart has done the trick, but the try catch you sent is clashing with an on error resume I have at the beginning of the rule

0 Likes
Message 45 of 46

ahmed.hagi
Enthusiast
Enthusiast

Sorry to bother you again, is there a way to get it to avoid paramaters which are either empty or have "0" as the import value?

0 Likes
Message 46 of 46

j.haggenjos
Advocate
Advocate
Accepted solution

You can add the following check to bypass empty values. I assumed empty values to be "" (empty string).

 

'Check imported data is not empty
If importedValue = "0" Or importedValue ="" Then Continue For

 

"Continue For" will go to the next iteration of the for loop without running the rest of the loop. The complete code is then the following:

 

For index = 0 To ImportedParamArray.GetLength(0) -1
	Dim ParamName As String = ImportedParamArray(index, 0)
	Dim importedValue As String = ImportedParamArray(index, 1)
    'Check imported data is not empty
    If importedValue = "0" Or importedValue ="" Then Continue For
	'Check value validity against standard parameter range
	If Not MultiValue.List(ParamName).Contains(importedValue) Then
		MsgBox("Imported value " + importedValue + " is not in the standard range of Parameter " + ParamName + ".")
	End If
	'Import value in any case
	Parameter(ParamName)=importedValue
Next