Click here to Skip to main content
15,879,096 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
"Count cannot be less than zero."
i get this error and i can not resolve please if somebody can help me!

Dim encoding__1 As Encoding = Encoding.GetEncoding("windows-1251")
           If File.Exists(Me.TextFile) Then
               File.Delete(Me.TextFile)
           End If
           Dim streamWriter As New StreamWriter(Me.TextFile, False, encoding__1)
           streamWriter.Write(" 01" & vbTab & "1" & vbTab & vbTab & "0" & vbTab & vbCr & vbLf)
           Dim num1 As Integer = 0
           Dim enumerator As List(Of Article).Enumerator
           Try
               enumerator = Me.Stavki.GetEnumerator()
               While enumerator.MoveNext()
                   Dim current As Article = enumerator.Current
                   Strings.Chr(CInt(current.VAT))
                   Dim num2 As Short = CShort(1)
                   Select Case current.VAT
                       Case VATgroup.А
                           num2 = CShort(1)
                           Exit Select
                       Case VATgroup.Б
                           num2 = CShort(2)
                           Exit Select
                       Case VATgroup.В
                           num2 = CShort(3)
                           Exit Select
                       Case VATgroup.Г
                           num2 = CShort(4)
                           Exit Select
                   End Select
                   If num1 Mod 2 = 0 Then
                       streamWriter.Write(String.Format("#1{0}" & vbTab & "{3}" & vbTab & "{1}" & vbTab & "{2}" & vbTab & "0" & vbTab & vbTab & vbTab, DirectCast(current.Name.Remove(20, current.Name.Length - 20), Object), DirectCast(Me.FormatNumber(current.Price, 2), Object), DirectCast(Me.FormatNumber(current.Amount, 3), Object), DirectCast(num2, Object)) + vbCr & vbLf) ' ERROR IS HERE
                   Else
                       streamWriter.Write(String.Format(" 1{0}" & vbTab & "{3}" & vbTab & "{1}" & vbTab & "{2}" & vbTab & "0" & vbTab & vbTab & vbTab, DirectCast(current.Name.Remove(20, current.Name.Length - 20), Object), DirectCast(Me.FormatNumber(current.Price, 2), Object), DirectCast(Me.FormatNumber(current.Amount, 3), Object), DirectCast(num2, Object)) + vbCr & vbLf)
                   End If
                   num1 += 1

               End While
           Finally
               enumerator.Dispose()
           End Try
           streamWriter.Write(String.Format("&5{0}" & vbTab & vbTab, DirectCast(PaidMode, Object)) + vbCr & vbLf)
           streamWriter.Write("%8")
           streamWriter.Flush()
           streamWriter.Close()
Posted
Comments
ZurdoDev 3-Mar-15 8:58am    
Is there a reason you cannot debug it?
Atmir 3-Mar-15 9:00am    
Really i can not i am working for 12 hours now i dont hane idea please can you help me!
CHill60 3-Mar-15 9:15am    
On which line does the error occur?
Atmir 3-Mar-15 9:16am    
in this line:
streamWriter.Write(String.Format("#1{0}" & vbTab & "{3}" & vbTab & "{1}" & vbTab & "{2}" & vbTab & "0" & vbTab & vbTab & vbTab, DirectCast(current.Name.Remove(20, current.Name.Length - 20), Object), DirectCast(Me.FormatNumber(current.Price, 2), Object), DirectCast(Me.FormatNumber(current.Amount, 3), Object), DirectCast(num2, Object)) + vbCr & vbLf)
CHill60 3-Mar-15 9:41am    
current.Name has less than 20 characters in in perhaps???

1 solution

Obviously, (current.Name.Length - 20) yields a less then zero value!
See the possible errors of String.Remove[^] method...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900