Following this post: https://forum.powerbasic.com/forum/u...526#post815526
It appears that this has been discussed previously, I found a test application on my PC that I created in Jan 2013 called IIFSWITCH.BAS
The following code demonstrates the problem and offers one possible work around.
'
It appears that this has been discussed previously, I found a test application on my PC that I created in Jan 2013 called IIFSWITCH.BAS
The following code demonstrates the problem and offers one possible work around.
'
Code:
#COMPILE EXE #DIM ALL %TRUE = -1 %FALSE = 0 FUNCTION PBMAIN () AS LONG LOCAL str1,str2, str3,strResult,strASC AS STRING LOCAL x AS LONG str1 = "One" str2 = "Two" str3 = "Three" OPEN "test.txt" FOR OUTPUT AS #1 PRINT #1, IIF$(%TRUE,str1,str2) 'returns STRING PRINT #1, SWITCH$(%True,str1,%False,str2) 'returns STRING '==== Begin Problem ===== PRINT #1, SWITCH$(%True, IIF$(%True, str1, str2),%False,str3) 'returns WSTRING 'This DOES NOT resolve the issue! strResult = SWITCH$(%True, IIF$(%True, str1, str2),%False,str3) 'strResult still has embedded null PRINT #1, strResult 'This kludge works strResult = REMOVE$(SWITCH$(%True, IIF$(%True, str1, str2),%False,str3),CHR$(0)) PRINT #1, strResult '===== End of problem ==== PRINT #1, IIF$(%True,SWITCH$(%True,str1,%False,str2),str3) ' returns STRING CLOSE #1 OPEN "test.txt" FOR BINARY AS #1 GET$ #1, LOF(1),strResult CLOSE #1 FOR x = 1 TO LEN(strResult) strAsc += HEX$(ASC(strResult,x),2,1) NEXT ? strAsc ? strResult ' truncates at first CHR$(0) END FUNCTION '