Every version and flavor of programming that I have used has had some version of MID$ so it must be some documented error somewhere (I can not find) but even PB posted somewhere (can not find at the moment, but think it had to do with "What Changed?" postings...maybe the Powerbase forum)
That a string is really not a string, but an array of characters
From that comment I have determined from my learning of arrays and bounds and declaring that in the case of PB if I declare and not give dimensions that LBOUND always exists, UBOUND will be less than 1 element (zero element that is)
That said...forgetting how strings are handled I tried the following
Code:
#COMPILE EXE #DEBUG ERROR OFF #DIM ALL #INCLUDE "Win32Api.inc" FUNCTION PBMAIN () AS LONG LOCAL sBuffer AS STRING LOCAL i AS LONG LOCAL LastErrorValue AS LONG LOCAL ErrorBuff AS ASCIIZ * %MAX_PATH LOCAL MsgString AS STRING LOCAL AscString AS STRING LOCAL BinString AS STRING LOCAL LenOfString AS STRING LOCAL PbErrorString AS STRING LOCAL ApiErrorString AS STRING LOCAL msg AS STRING MsgString = sBuffer AscString = STR$(ASC(MID$(sBuffer, 1, 1))) BinString = BIN$(ASC(MID$(sBuffer, 1, 1)), 8) LenOfString = STR$(LEN(sBuffer)) PbErrorString = ERROR$(ERR) LastErrorValue = GetLastError FormatMessage %FORMAT_MESSAGE_FROM_SYSTEM, BYVAL %NULL, LastErrorValue, %NULL, ErrorBuff, SIZEOF(ErrorBuff), BYVAL %NULL 'Format the message ApiErrorString = STR$(LastErrorValue) + SPACE$(5) + ErrorBuff msg = "Doing a MID$ starting at 1" + $CR msg = msg + "*****************************************" + $CR msg = msg + "String = " + MsgString + $CR msg = msg + "Asc Value of String = " + AscString + $CR msg = msg + "Bin value of String = " + BinString + $CR msg = msg + "Len of String = " + LenOfString + $CR msg = msg + $CR msg = msg + "Pb Error = " + PbErrorString + $CR msg = msg + "API Error = " + ApiErrorString + $CR MSGBOX msg MsgString = sBuffer AscString = STR$(ASC(MID$(sBuffer, 0, 1))) BinString = BIN$(ASC(MID$(sBuffer, 0, 1)), 8) LenOfString = STR$(LEN(sBuffer)) PbErrorString = ERROR$(ERR) LastErrorValue = GetLastError FormatMessage %FORMAT_MESSAGE_FROM_SYSTEM, BYVAL %NULL, LastErrorValue, %NULL, ErrorBuff, SIZEOF(ErrorBuff), BYVAL %NULL 'Format the message ApiErrorString = STR$(LastErrorValue) + SPACE$(5) + ErrorBuff msg = "Doing a MID$ starting at 0" + $CR msg = msg + "*****************************************" + $CR msg = msg + "String = " + MsgString + $CR msg = msg + "Asc Value of String = " + AscString + $CR msg = msg + "Bin value of String = " + BinString + $CR msg = msg + "Len of String = " + LenOfString + $CR msg = msg + $CR msg = msg + "Pb Error = " + PbErrorString + $CR msg = msg + "API Error = " + ApiErrorString + $CR MSGBOX msg MsgString = sBuffer AscString = STR$(ASC(MID$(sBuffer, -1, 1))) BinString = BIN$(ASC(MID$(sBuffer, -1, 1)), 8) LenOfString = STR$(LEN(sBuffer)) PbErrorString = ERROR$(ERR) LastErrorValue = GetLastError FormatMessage %FORMAT_MESSAGE_FROM_SYSTEM, BYVAL %NULL, LastErrorValue, %NULL, ErrorBuff, SIZEOF(ErrorBuff), BYVAL %NULL 'Format the message ApiErrorString = STR$(LastErrorValue) + SPACE$(5) + ErrorBuff msg = "Doing a MID$ starting at -1" + $CR msg = msg + "*****************************************" + $CR msg = msg + "String = " + MsgString + $CR msg = msg + "Asc Value of String = " + AscString + $CR msg = msg + "Bin value of String = " + BinString + $CR msg = msg + "Len of String = " + LenOfString + $CR msg = msg + $CR msg = msg + "Pb Error = " + PbErrorString + $CR msg = msg + "API Error = " + ApiErrorString + $CR MSGBOX msg END FUNCTION
Length of the string will always return 0 so I can not test there, and filling the string shows quite other results that I have to check, but all in all the problem has NOTHING to do with Serial Ports, nor PB, and maybe even lesser extent M$ Api...since all the docs are technically correct, but do not fully warn of the caveats.
(Either that or I found a bug report or a NFS)


Leave a comment: