INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Please Hellp

Please Hellp

(OP)
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

RE: Please Hellp

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.

RE: Please Hellp

(OP)
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)

RE: Please Hellp

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



RE: Please Hellp


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

RE: Please Hellp

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close