-
Jun 25th, 2016, 06:59 PM
#1
Thread Starter
New Member
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
-
Jun 25th, 2016, 10:02 PM
#2
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
-
Jun 26th, 2016, 12:05 AM
#3
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?
-
Jun 26th, 2016, 09:05 AM
#4
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
-
Jun 26th, 2016, 09:11 AM
#5
Re: Help Length of argument 'String' must be greater than zero.
The code does not really look like VB.Net.
-
Jun 26th, 2016, 10:17 AM
#6
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
-
Jun 26th, 2016, 10:42 AM
#7
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.
-
Jun 26th, 2016, 11:36 AM
#8
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.
-
Jun 26th, 2016, 12:08 PM
#9
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
-
Jun 26th, 2016, 04:23 PM
#10
Thread Starter
New Member
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
-
Jun 26th, 2016, 04:32 PM
#11
Thread Starter
New Member
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
-
Jun 26th, 2016, 06:24 PM
#12
Re: Help Length of argument 'String' must be greater than zero.
I think it's equivalent to:
VB.NET Code:
Private Sub readBMP() 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.txt" Dim byteWidth As Integer = 24 Dim bytes() As Byte = IO.File.ReadAllBytes(File) Dim bytesCount As Integer = bytes.Length Using writer As New IO.StreamWriter(IO.File.Create(outFile)) Debug.WriteLine("'------------------------ 256 color BMP Image Data below ---------------------------") writer.WriteLine("'------------------------ 256 color BMP Image Data below ---------------------------") For offset As Integer = 0 To bytesCount - 1 Step byteWidth Dim bytesRemaining As Integer = bytesCount - offset Dim line As String = "byte $" & BitConverter.ToString(bytes, offset, Math.Min(ByteWidth, bytesRemaining)).Replace("-", ", $") If bytesRemaining > byteWidth Then Debug.WriteLine(line) writer.WriteLine(line) Else Debug.WriteLine(line & ", " & bytesCount.ToString & " ") writer.WriteLine(line & ", " & bytesCount.ToString & " ") End If Next End Using End Sub
Last edited by Inferrd; Jun 26th, 2016 at 06:47 PM.
-
Jun 27th, 2016, 07:05 PM
#13
Thread Starter
New Member
Re: Help Length of argument 'String' must be greater than zero.
You ALL rock especially you Inferrd! It is working. Thanks all!
-
Jun 27th, 2016, 07:06 PM
#14
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|