none
System.ArgumentException: Argument 'Start' must be greater than zero.

    Question

  • Hi

     

    Any one pls help me

     Error: System.ArgumentException: Argument 'Start' must be greater than zero.

    Dim binData As Byte()
            Dim counter As Integer
            Dim postedData As Integer
            'Dim dat As String
            'Dim fs As StreamWriter

            Server.ScriptTimeout = 18000000
            binData = Request.BinaryRead(Request.TotalBytes)
            ' Convert the binary data to ASCII
            'For counter = 1 To binData.Length
                postedData = postedData & Chr(Asc(Mid(binData.ToString(), counter, 1)))--Error System.ArgumentException: Argument 'Start' must be greater than zero.
           ' Next
            Dim datetime1 As String = DateTime.Now.ToString.Replace(" ", "")
            datetime1 = DateTime.Now.ToString.Replace(":", "")
            datetime1 = datetime1.ToString.Replace("/", "")
            datetime1 = datetime1.ToString.Replace("-", "")
            Dim sw As StreamWriter = File.CreateText("c:\Temparory\" & datetime1 & ".txt")
            'dat = Replace(Now(), " ", "")
            'dat = Replace(dat, ":", "")
            'dat = Replace(dat, "/", "")
            'fs = File.CreateText("c:\temp\" & dat.Now & ".txt")
            sw.Write(postedData)
            'For counter = 1 To binData.Length

            '    sw.Write(Convert.ToChar(binData(counter)))
            'Next
            sw.Close()
            sw = Nothing

     

     

    Pls help,,,its very urgent

     

    thanks in advance

    Thursday, July 10, 2008 8:03 AM

Answers

  • binData.ToString() does not do what you expect it to do.  For example:

        Dim binData As Byte() = {1, 2, 3, 4}
        Console.WriteLine(binData.ToString())

    output: System.Byte[]

    You should do it this way:

        Dim postedData As String
        postedData = System.Text.Encoding.ASCII.GetString(binData)

    Note that postedData must be a string, not an integer.


    Tuesday, July 15, 2008 2:52 PM

All replies

  • Hi Suresh..,

    I am so sorry that your problem wasn’t solved immediately.

    As we all know that, the Function of Mid is to return a string containing a specified number of characters from a string. The declaration of Mid is as below:

    Code Snippet

    Mid is Public Shared Function Mid(

      ByVal str As String, _

      ByVal Start As Integer, _

       Optional ByVal Length As Integer _

    ) As String

     

     

    If Start<=0 or Length<0, ArgumentException will occur. The value of counter is zero when the program runs to "postData=postData&....." Statement for it wan't assigned a value manually. Obviously we can see where the problem is.

     

    Best Regards,

    Bruce Zhou

    Tuesday, July 15, 2008 11:39 AM
  • binData.ToString() does not do what you expect it to do.  For example:

        Dim binData As Byte() = {1, 2, 3, 4}
        Console.WriteLine(binData.ToString())

    output: System.Byte[]

    You should do it this way:

        Dim postedData As String
        postedData = System.Text.Encoding.ASCII.GetString(binData)

    Note that postedData must be a string, not an integer.


    Tuesday, July 15, 2008 2:52 PM