Results 1 to 14 of 14

Thread: Help Length of argument 'String' must be greater than zero.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2016
    Posts
    5

    Help Length of argument 'String' must be greater than zero.

    I get the error .......
    (Length of argument 'String' must be greater than zero.)
    for the instruction............
    BMPdata = Asc(InputString(1, 1))
    If anyone knows why I'd like the help. The bmp file exists.

    Code:
    Module Module1
        Dim File As String
        Dim outFile As String
        Dim msg As String
        Dim pixel As String
        Dim W1DTH As Integer
        Dim HE1GHT As Integer
        Dim BMPdata As Integer
        Dim Cnt As Integer
        Dim Index As Integer
        Dim ddata As Integer
        Dim ByteWidth As Byte
    
    
        Sub Main()
    
            File = "c:/Users/Celticlord/Desktop/LghtOff.bmp"               'File must not exceed uOLED display dimensions
            'and must be a 256 color BMP.  To conserve space
            'the image should not exceed 64x64 and use a Mode
            'value of "1" when calling the 'image' function
            'from Spin.
    
            outFile = "c:/Users/Celticlord/Desktop/LghtOff.spin"
    
            ByteWidth = 24
            FileOpen(2, outFile, OpenMode.Output)
            FileOpen(1, File, OpenMode.Binary)
            Seek(1, &H12 + 1)
            W1DTH = Asc(InputString(1, 1))
            Seek(1, &H16 + 1)
            HE1GHT = Asc(InputString(1, 1))
    
            Seek(1, &HD + 1)
            BMPdata = Asc(InputString(1, 1))
            Seek(1, &HC + 1)
            BMPdata = BMPdata * 256 + Asc(InputString(1, 1))
            Seek(1, &HB + 1)
            BMPdata = BMPdata * 256 + Asc(InputString(1, 1))
            Seek(1, &HA + 1)
            BMPdata = BMPdata * 256 + Asc(InputString(1, 1))
    
            Debug.Print("'------------------------ 256 color BMP Image Data below ---------------------------")
            Print(2, "'------------------------ 256 color BMP Image Data below ---------------------------")
    
            Seek(1, 1)
    
            Index = 0
            Cnt = 0
            For dd = 0 To BMPdata - 1
                Cnt = Cnt + 1
                ddata = Asc(InputString(1, 1))
                If Index = 0 Then
                    Debug.Print("byte ")
                    Print(2, "byte ")
                End If
    
                msg = Hex$(ddata)
                If Len(msg) = 1 Then msg = "0" + msg
                Debug.Print("$", msg)
                Print(2, "$", msg)
    
                Index = Index + 1
                If Index = ByteWidth Then
                    Index = 0
                    Debug.Print("")
                    Print(2, "")
                Else
                    Debug.Print(", ")
                    Print(2, ", ")
                End If
    
            Next dd
    
    
            For yy = 0 To HE1GHT - 1
                For xx = 0 To W1DTH - 1
                    Cnt = Cnt + 1
                    pixel = Asc(InputString(1, 1))
    
                    If Index = 0 Then
                        Debug.Print("byte ")
                        Print(2, "byte ")
                    End If
    
                    msg = Hex$(pixel)
                    If Len(msg) = 1 Then msg = "0" + msg
                    Debug.Print("$", msg)
                    Print(2, "$", msg)
    
                    Index = Index + 1
                    If Index = ByteWidth Then
                        Index = 0
                        Debug.Print("")
                        Print(2, "")
                    Else
                        Debug.Print(", ")
                        Print(2, ", ")
                    End If
    
                Next xx
            Next yy
            Debug.Print(Cnt)
            Print(2, Cnt)
            FileClose(1)
            FileClose(2)
            End
    
        End Sub
    
    End Module

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Help Length of argument 'String' must be greater than zero.

    Thread moved to Classic VB forum, since that appears to be the language in question.
    My usual boring signature: Nothing

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Help Length of argument 'String' must be greater than zero.

    What is this?
    Code:
    BMPdata = Asc(InputString(1, 1))
    Is that InputString some function in your program if so where is it getting its value from and what is it doing with it

    The code you have posted seems to seek to a position but then there is no Get # to read from the file and apparently you are calling some function with 1,1 as parameters. Is there code n that function to read data from the file at that position and return 1 byte of that data as a string?

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Help Length of argument 'String' must be greater than zero.

    Look at the code, it is one of the many versions of VB.Net so we won't be a lot of help here.

    InputString Function

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Help Length of argument 'String' must be greater than zero.

    The code does not really look like VB.Net.

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Help Length of argument 'String' must be greater than zero.

    I think we're going to need more information from the OP on this one. InputString does, indeed, appear to be a .NET function, however, most of the code is VB6 in nature. Hex$, Len, and others are VB6. They still work in .NET, so maybe this is something that was auto-converted. After all, InputString is a legacy method even for .NET and has been deprecated since 2008...which is getting more that a little long in the tooth.

    Perhaps it should be moved, but I'm reluctant to do so until the OP clears up what language they are trying to write for.
    My usual boring signature: Nothing

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Help Length of argument 'String' must be greater than zero.

    Well you also have those "Module/End Module" brackets as well as FileOpen(), FileClose(), etc. and a lot of other extraneous parenthesis usage in general that screams ".Net!" to me.

    But it can't hurt to see what the OP says when he comes back.

  8. #8
    Frenzied Member
    Join Date
    Dec 2014
    Location
    VB6 dinosaur land
    Posts
    1,191

    Re: Help Length of argument 'String' must be greater than zero.

    I can't say why but InputString function is returning an empty string on some of those seeks, which then causes the Asc function to give you that error. Have no idea what is supposed to be in your bmp file. I just picked the windows movie maker 32x32 bmp to test with and reproduced the error you see using 2013.

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Help Length of argument 'String' must be greater than zero.

    Ok, I'm convinced. It's .NET, and topshot tells me that it will still compile in a modern version of .NET, so that InputString method isn't quite as deprecated as I thought it was. Therefore, I moved it here. This is a well traveled thread.
    My usual boring signature: Nothing

  10. #10

    Thread Starter
    New Member
    Join Date
    Jun 2016
    Posts
    5

    Re: Help Length of argument 'String' must be greater than zero.

    Microsoft Visual Basic Express 2010
    Version 10.0.40219.1 SP1Rel

    Microsoft Net Framework
    Version 4.5.51209 SP1Rel

  11. #11

    Thread Starter
    New Member
    Join Date
    Jun 2016
    Posts
    5

    Re: Help Length of argument 'String' must be greater than zero.

    I was converting THIS CODE IN THIS POST http://forums.parallax.com/discussio...u-to-propeller to my VB version.


    Beau Schwabe Posts: 6,210
    March 2014 edited March 2014 Flag0
    Here is the Visual Basic code that I used to convert the images. It's basically just a raw data dump of the entire file with output formatting that works with SPIN so that the output file can be directly copied and pasted into SPIN. The "pub image" routine within Spin is able to read the raw BMP file. Although the information is contained within the raw BMP file, you do however need to specify the Length and Width as well as the starting X,Y location when calling the "pub image" routine.


    Note: The very last value printed in the output file indicates the size of the image file in BYTES and can be removed, it's just there for debug and should match the original file size.
    Code:
    Sub readBMP()
    
    file = "c:/Parallax Inc LOGO.bmp"               'File must not exceed uOLED display dimensions
                                                    'and must be a 256 color BMP.  To conserve space
                                                    'the image should not exceed 64x64 and use a Mode
                                                    'value of "1" when calling the 'image' function
                                                    'from Spin.
    
    outfile = "c:/Parallax Inc LOGO.spin"
    
    ByteWidth = 24
    
    Open outfile For Output As 2
    Open file For Binary As 1
        Seek #1, &H12 + 1
        W1DTH = Asc(Input$(1, 1#))
        Seek #1, &H16 + 1
        HE1GHT = Asc(Input$(1, 1#))
    
        Seek #1, &HD + 1
        BMPdata = Asc(Input$(1, 1#))
        Seek #1, &HC + 1
        BMPdata = BMPdata * 256 + Asc(Input$(1, 1#))
        Seek #1, &HB + 1
        BMPdata = BMPdata * 256 + Asc(Input$(1, 1#))
        Seek #1, &HA + 1
        BMPdata = BMPdata * 256 + Asc(Input$(1, 1#))
      
    Debug.Print "'------------------------ 256 color BMP Image Data below ---------------------------"
    Print #2, "'------------------------ 256 color BMP Image Data below ---------------------------"
    
    Seek #1, 1
    
        Index = 0
        Cnt = 0
        For dd = 0 To BMPdata - 1
            Cnt = Cnt + 1
            ddata = Asc(Input$(1, 1#))
            If Index = 0 Then
               Debug.Print "byte ";
               Print #2, "byte ";
            End If
                
            msg = Hex$(ddata)
            If Len(msg) = 1 Then msg = "0" + msg
            Debug.Print "$"; msg;
            Print #2, "$"; msg;
            
            Index = Index + 1
            If Index = ByteWidth Then
               Index = 0
               Debug.Print ""
               Print #2, ""
            Else
               Debug.Print ", ";
               Print #2, ", ";
            End If
        
        Next dd
        
        
        For yy = 0 To HE1GHT - 1
            For xx = 0 To W1DTH - 1
                Cnt = Cnt + 1
                pixel = Asc(Input$(1, 1#))
                    
                If Index = 0 Then
                   Debug.Print "byte ";
                   Print #2, "byte ";
                End If
                    
                msg = Hex$(pixel)
                If Len(msg) = 1 Then msg = "0" + msg
                Debug.Print "$"; msg;
                Print #2, "$"; msg;
                    
                Index = Index + 1
                If Index = ByteWidth Then
                    Index = 0
                    Debug.Print ""
                    Print #2, ""
                Else
                    Debug.Print ", ";
                    Print #2, ", ";
                End If
                
            Next xx
        Next yy
        Debug.Print Cnt
        Print #2, Cnt
        Close #1
        Close #2
        End
        
    End Sub

  12. #12
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: Help Length of argument 'String' must be greater than zero.

    I think it's equivalent to:
    VB.NET Code:
    1. Private Sub readBMP()
    2.  
    3.     File = "c:\Users\Celticlord\Desktop\LghtOff.bmp"               'File must not exceed uOLED display dimensions
    4.     '                                                              'and must be a 256 color BMP.  To conserve space
    5.     '                                                              'the image should not exceed 64x64 and use a Mode
    6.     '                                                              'value of "1" when calling the 'image' function
    7.     '                                                              'from Spin.
    8.  
    9.     outFile = "c:\Users\Celticlord\Desktop\LghtOff.txt"
    10.  
    11.     Dim byteWidth As Integer = 24
    12.  
    13.     Dim bytes() As Byte = IO.File.ReadAllBytes(File)
    14.     Dim bytesCount As Integer = bytes.Length
    15.  
    16.     Using writer As New IO.StreamWriter(IO.File.Create(outFile))
    17.         Debug.WriteLine("'------------------------ 256 color BMP Image Data below ---------------------------")
    18.         writer.WriteLine("'------------------------ 256 color BMP Image Data below ---------------------------")
    19.  
    20.         For offset As Integer = 0 To bytesCount - 1 Step byteWidth
    21.             Dim bytesRemaining As Integer = bytesCount - offset
    22.  
    23.             Dim line As String = "byte $" & BitConverter.ToString(bytes, offset, Math.Min(ByteWidth, bytesRemaining)).Replace("-", ", $")
    24.  
    25.             If bytesRemaining > byteWidth Then
    26.                 Debug.WriteLine(line)
    27.                 writer.WriteLine(line)
    28.             Else
    29.                 Debug.WriteLine(line & ",  " & bytesCount.ToString & " ")
    30.                 writer.WriteLine(line & ",  " & bytesCount.ToString & " ")
    31.             End If
    32.         Next
    33.     End Using
    34.  
    35. End Sub
    Last edited by Inferrd; Jun 26th, 2016 at 06:47 PM.

  13. #13

    Thread Starter
    New Member
    Join Date
    Jun 2016
    Posts
    5

    Re: Help Length of argument 'String' must be greater than zero.

    You ALL rock especially you Inferrd! It is working. Thanks all!

  14. #14

    Thread Starter
    New Member
    Join Date
    Jun 2016
    Posts
    5

    Re: Help Length of argument 'String' must be greater than zero.

    Thought I needed to use stream but it was a passing thought when finding a way to do it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width