News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Something weird with the MID$

Started by kcsl, Dec 01, 2022, 08:52 PM

Previous topic - Next topic

kcsl

I'm losing the plot with this, and I've probably been staring at it too long.
However, I cannot see what's wrong.

I've distilled my application code down to this to demonstrate the problem.

The following code will throw the error "For without Next" and I'll be darned if I can see what's wrong.

I'm running Positron8 4.0.2.9


    Device 18F25K22
    Xtal 64   
   
    Dim sDisplayBuffer                  As String * 20
    Dim bytLoop                         As Byte
    Dim bytJunk                         As Byte
   
   
    For bytLoop = 1 To 20
       
        If Mid$(sDisplayBuffer, 1, 1) = "1" Then
           
        End If
   
    Next bytLoop

I even deleted the lines and re-keyed them just in-case.

As an afterthought I changed the MID$ for LEFT$(sDisplayBuffer, 1) and that threw some weird error:
ASM ERROR: Error[128] C:\temp\A.S 2116:Missing argument(s)
ASM ERROR: ASSEMBLER ERRORS.HEX file not Created

Using RIGHT$ threw the same error.


Can anybody see what the problem is?

Regards,
Joe

There's no room for optimism in software or hardware engineering.

trastikata

The "If...Then" comparison is not accepting the Mid$ function, probably treating the result as byte instead of as string, something that Les can clarify. I'd guess something related to this:

QuoteMid$
...
Destination String can only be a String variable, and should be large enough to hold the correct amount of characters extracted from the Source String.


This way it will work:

    Device 18F25K22
    Xtal 64   
   
    Dim sDisplayBuffer                  As String * 20
    Dim bytLoop                         As Byte
    Dim bytJunk                         As Byte
    Dim tString                         As String * 1

   
    For bytLoop = 1 To 20
       
        tString = Mid$(sDisplayBuffer, 1, 1)
        If tString = "1" Then
           
        End If
   
    Next bytLoop


kcsl

Yep that workaround fixed it, thanks Trastikata
I don't know why I didn't think of that.

Joe

There's no room for optimism in software or hardware engineering.

tumbleweed

If you're only looking at single characters then you could drop using MID$ and just look at the string array directly...

If sDisplayBuffer[ix] = "1" Then

top204

Sorry.

I thought I had disabled the Mid$, Left$ and Right$ within comparisons, but I had not. :-)

To use these functions within comparisons, it needs a temporary String created in the background of the compiler, and I did do that in early versions of the compiler that first had the String variables in place, but the compiler had to create a "Worse Case" size temporary String for each function, and that is 255 characters!, so it used more RAM than some devices actually had, and used up a lot of RAM, even when it was re-absorbed into the program's use, because if more than one of the functions is used in an Or or And comparison, it can use a "lot" of RAM, while they are all being compared to each other!!!

So I removed them from the comparisons, or so I thought. LOL.

I am working on a new update and will upload it ASAP.