Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please Hellp

Status
Not open for further replies.

barne77

Technical User
Jan 16, 2015
2
GB
I have the below code but getting Error: 1 : Execute of Activity codeActivity1 threw System.ArgumentException: Argument 'Length' must be greater or equal to zero.

Private Sub codeActivity1_ExecuteCode(sender As System.Object, e As System.EventArgs)

HistoryDescription1 = "STARTING CODE ACTIVITY1"

Dim obj As Object

Dim sSite As String = ""

Dim sList As String = ""

Dim file As SPFile = workflowProperties.Item.File

obj = workflowProperties.Item
Dim areader As StringReader = New System.IO.StringReader(file.ToString)

Dim breader As StreamReader = New StreamReader(Me.workflowProperties.Item.File.OpenBinaryStream)

Dim str As String = breader.ReadToEnd

Dim tempstr As String = ""

Dim listid As String = ""

Dim taskid As String = ""

Dim sEmailBody As String = ""

Dim pos As Integer = 0

Dim aitem As SPListItem

HistoryDescription1 = "STARTING TRY1"

Try

Dim msgObj As New System.Net.Mail.MailMessage

Catch ex As Microsoft.SharePoint.SPException

End Try

Dim testString As String = str

pos = InStr(str, vbCrLf & vbCrLf)

HistoryDescription1 = "STARTING TRY2"

Try

sEmailBody = Mid(str, pos, 100)

Catch ex As Microsoft.SharePoint.SPException

End Try

pos = InStr(str, "Subject: ")

If pos = 0 Then Exit Sub

tempstr = Mid(str, pos + 9, 120)

Dim firstdash = InStr(tempstr, "+")

Dim UserAction = Left(tempstr, firstdash - 1)

tempstr = Right(tempstr, Len(tempstr) - firstdash)

firstdash = InStr(tempstr, "+")

Dim thisTask = Mid(tempstr, 3, firstdash - 3)

tempstr = Right(tempstr, Len(tempstr) - firstdash)

firstdash = InStr(tempstr, "+")


sSite = GetSite(tempstr)

sList = GetList(tempstr)

Dim gList As New Guid(sList)

sList = Replace(sList, " ", "%20")

Dim site As New SPSite(sSite)

Using web As SPWeb = site.OpenWeb()

HistoryDescription1 = "STARTING TRY3"

Try

Dim alist As SPList = web.Lists(gList)

aitem = alist.GetItemById(CInt(thisTask))

If UserAction = "APPROVE" Then

Dim ht As New Hashtable()

ht("Completed") = "TRUE"

ht("PercentComplete") = 1

ht("Status") = "Completed"

ht(SPBuiltInFieldId.WorkflowOutcome) = "Approved"

ht("Outcome") = "Approved"

ht("TaskStatus") = "Approved"

ht(SPBuiltInFieldId.Description) = "Approved by email. User comment: " & sEmailBody

web.AllowUnsafeUpdates = True

SPWorkflowTask.AlterTask(TryCast(aitem, SPListItem), ht, True)

ElseIf UserAction = "REJECT" Then

Dim ht As New Hashtable()

ht("Completed") = "TRUE"

ht("PercentComplete") = 0

ht("Status") = "Completed"

ht("Outcome") = "Rejected"

ht("TaskStatus") = "Rejected"

ht(SPBuiltInFieldId.Description) = "Rejected by email. User comment: " & sEmailBody

ht("FormData") = SPWorkflowStatus.Completed

web.AllowUnsafeUpdates = True

SPWorkflowTask.AlterTask(TryCast(aitem, SPListItem), ht, True)

End If

HistoryDescription1 = "END WORKFLOW. id=" & thisTask & ": list=" & gList.ToString & ": site=" & sSite & ": action=" & UserAction

Catch ex As Microsoft.SharePoint.SPException

HistoryDescription1 = ex.Message

Dim ht As New Hashtable()

ht("Completed") = "FALSE"

ht("PercentComplete") = 0

ht("Status") = "Error"

ht("Outcome") = "Error"

ht("TaskStatus") = "Error"

ht(SPBuiltInFieldId.Description) = "Error: " & ex.Message

ht("FormData") = SPWorkflowStatus.ErrorOccurred

SPWorkflowTask.AlterTask(TryCast(aitem, SPListItem), ht, True)

HistoryDescription1 = sSite & sList

End Try

End Using

End Sub

Private Function GetSite(fullString As String) As String

Dim pos As Integer = InStr(fullString, "SITE")

Dim dsh As Integer = InStr(pos, fullString, "+")

Dim s As String = Mid(fullString, pos + 4, dsh - 5)

HistoryDescription1 = s

Return s

End Function

Private Function GetList(fullString As String) As String

Dim pos As Integer = InStr(fullString, "+LIST")

Dim tmp As String = Mid(fullString, pos + 5, 36)

HistoryDescription1 = tmp

Return tmp

End Function
 
And we should be able to guess which line of your code errors?

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
I don't know this is all the error says

DateTime=2015-01-16T20:21:10.4110326Z
System.Workflow.Runtime Error: 1 : Execute of Activity codeActivity1 threw System.ArgumentException: Argument 'Length' must be greater or equal to zero.
at Microsoft.VisualBasic.Strings.Left(String str, Int32 Length)
at WorkflowProject4.Workflow1.codeActivity1_ExecuteCode(Object sender, EventArgs e)
at System.Workflow.ComponentModel.Activity.RaiseEvent(DependencyProperty dependencyEvent, Object sender, EventArgs e)
at System.Workflow.Activities.CodeActivity.Execute(ActivityExecutionContext executionContext)
at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(T activity, ActivityExecutionContext executionContext)
at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(Activity activity, ActivityExecutionContext executionContext)
at System.Workflow.ComponentModel.ActivityExecutorOperation.Run(IWorkflowCoreRuntime workflowCoreRuntime)
 
I don't know this is all the error says

Knowing what the error says is one thing.

Knowing WHERE (on what code line) the error message appears is another IMPORTANT piece of the puzzle.

Also - when you post a Question to the forum your Subject line should be more specific about your issue.

Good Luck,
JRB-Bldr



 

Any time there is an error indicating "Argument 'Length' must be greater or equal to zero" I'd start looking at any string function like Mid, substring, etc. that attempts to parse a zero length string.


Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
Well the error says that the problem occurs with a "Left" function.
The only Left(...) in your code seems to be this one:
Code:
Dim firstdash = InStr(tempstr, "+")

Dim UserAction = Left(tempstr, firstdash - 1)

So my guess would be that there is no "+" sign in your tempstring, hence firstdash will result in 0, hence your length argument in Left will result in -1 which is less than 0 and therefore forbidden.


ôKnowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family.ö (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top