Strange File Path

Thanks for your clearly understandable hints. This helped and works so far. Also, I did put following testing code into my script:
Window_StringInputDialog.input_text=FootControllerLoaderSU
Seams to read the file. However, “FootControllerLoaderSU.img” is a file which I need to send byte by byte to a device.
Original code to read the file from disk was:

[code] read_stream=BinaryStream.Open(LoaderFile1,false) // LoaderFile1 is the filepath
if read_stream=Nil then
MsgBox("Cannot open loader file: " + LoaderFile1.NativePath )
return False
end if

i = 0
while not read_stream.EOF
  //ReadFromFile.Position = i
  CodeArray1(i) = read_stream.ReadUint8
  i=i+1
wend
read_stream.close[/code]

Thus, how can I read the “FootControllerLoaderSU” file from resource folder to get it byte by byte into CodeArray1 ?

Also, does this work on PC as well?

“FootControllerLoaderSU.img” is a disk image, or a graphic image (picture), or your own file format…?

img file from C compiler; the firmware update sent to device

I’m pretty sure the solution will involve a memory block. Since your image file is just Uint8s, maybe you can treat it as a string. Converting a string to a memory block and thence loading it into an array is very simple. Not sure how to get Xojo to believe it’s a string in the first place, though - smarter people than me here can probably help.

Or never mind the memory block, if you can get it in as a string, you can just use string functions (MidB(), AscB(), etc) to put it into your array.

… I did only design the frontend of this app, data sending and receiving was made by other developer and I’m not familiar with this I/O stuff …

OK, thanks. Will try that

I think you can just do

Dim s As String s = FootControllerLoaderSU

and you have your string. Xojo doesn’t care that it’s a “.img” file, if it’s Uint8s. Use memoryBlock or String functions from there to load it byte by byte into your array.

Yes, I can load it as String or Memory block. I try to figure out now how to get string (or memory block) into the array. Do I need Left() and Len() for this, or is there an easier way? This one does not work:

[code] Dim test as MemoryBlock
test=FootControllerLoaderSU

for i = 0 to test.Size
  CodeArray1(i) = test.Byte(i)
  i=i+1
next[/code]

That loop should work, although I’d think you’d want to append each byte to your array rather than having to size the array ahead of time and assigning bytes. Have you examined the MemoryBlock’s contents (and its Size property) in the debugger to verify that it’s holding the expected data? Can you be more specific about what “does not work”?

It did not work because it must be test.Size-1 , not test.size
Now it Works!!

The array is a property with fixed size => CodeArray1(4096)

In the future, it will be easier for people to help you if you’re more specific about what’s happening. “It doesn’t work” usually means that it compiles and runs but it doesn’t do what you want, in which case people trying to help you will look at your algorithms. If you get a runtime (e.g. OutOfBounds) or compile error, that’s very different and people will look for other possible causes.

Yes, you are right.