Greetings! I wrote a little subroutine to print a string of type IString
But the compiler output (at bottom of this post) said that no appropriate conversion exists
How can I modify this sub to perform the appropriate conversion? Thanks!
SUB HELLOISTR()
DEF InsiderJrSr[3]:ISTRING
InsiderJrSr = "ABC"
HelloWindowSTR("InsiderJrSr = ", InsiderJrSr)
ENDSUB
Export HelloWindowSTR
DEF w1 as WINDOW
SUB HelloWindowSTR(WMsge: STRING, WAmt: IString)
OPENWINDOW w1,0,0,350,350,@MINBOX|@MAXBOX|@SIZE,NULL,"Simple Window",&main
PRINT w1, WMsge,WAmt
REM when w1 = 0 the window has been closed
WAITUNTIL w1 = 0
ENDSUB
SUB main
IF @MESSAGE = @IDCLOSEWINDOW
REM closes the window and sets w1 = 0
CLOSEWINDOW w1
ENDIF
' RETURN
ENDSUB
Compiler Output:
Compiling...
HelloISTR.eba
File: C:\ExcelDLLs\HelloISTR.eba (6) no appropriate conversion exists - )
Error(s) in compiling C:\ExcelDLLs\HelloISTR.eba
May you have a blessed day.
Sincerely,
Michael D Fitzpatrick
Mike,
An ISTRING is not a really a type, it is a way of dimensioning a STRING to override the default size of 255 characters.
All strings are passed by reference, so a STRING type is really just an address. Change your sub like so:
SUB HelloWindowSTR(WMsge: STRING, WAmt: STRING)
And this is also wrong:
DEF InsiderJrSr[3]:ISTRING
InsiderJrSr = "ABC"
Can you guess why? Strings in Emergence/Aurora/Creative, like in many languages, are NULL terminated. So "ABC" is actually 4 characters long. The 3 needs to be a 4. You won't get an error, because it is a compiler and not an interpreter, but you will be overwriting memory. It's a common newbie mistake, so don't feel bad.
Paul.
With the number of times this mistake is made, I wonder if it would be a good idea to just make ISTRING an alias for STRING in parameters?
Paul and Parker
I had a similar problem, and thanks to this discussion I was able to resolve it.
But the problem manifested obliquely. I had declared:
Declare IMPORT,_
FtpGetCurrentDirectory ALIAS FtpGetCurrentDirectoryA( _
hInternetConnect As INT, _
lpszCurrentDirectory As IWSTRING, _
lpdwCurrentDirectory As INT_
), INT
The compiler balked at the call:
gotDir = FtpGetCurrentDirectory( _
hInetConnection, _
sDir, _
dirLen)
but gave the "no appropriate..." error on the LAST line, with the dirLen argument.
This of course confused the issue, but changing the 2nd param to WSTRING fixed it.
I have since tried
dirLen _
)
for which the compiler showed the error on the paren.
If I had written it that way to begin with, I would not have thought the problem was the 3rd arg.
I agree with Parker that allowing ISTRING/IWSTRING in params would be helpful.
"Can you guess why? Strings in Emergence/Aurora/Creative, like in many languages, are NULL terminated. So "ABC" is actually 4 characters long. The 3 needs to be a 4. You won't get an error, because it is a compiler and not an interpreter, but you will be overwriting memory. It's a common newbie mistake, so don't feel bad."
Hmmm.. I had never even thought about that.... And since it never gives an error, I dont think I would have ever thought about that.... Us newbies learn something new every day ;D
Sorry, but now I am a little confused. ::)
The example in the Users Guide
OPENCONSOLE
'Define a string of exactly 30 characters
DEF name[30]:ISTRING
name = "john Smith"
name[0] = "J"
PRINT name
PRINT "Press any key to close"
DO:UNTIL INKEY$ <> ""
CLOSECONSOLE
END
Shows that ISTRING is zero-based.
So would not EvangelMike's example of :
DEF InsiderJrSr[3]:ISTRING
InsiderJrSr = "ABC"
be okay as there are 4 places allocated.
InsiderJrSr[0] = "A"
InsiderJrSr[1] = "B"
InsiderJrSr[2] = "C"
InsiderJrSr[3] = NULL
No, indexes are zero based, not dimensions.
DEF InsiderJrSr[3]:ISTRING
has indexes 0, 1 and 2
No different than
DEF zz[3]:INT
Again valid indexes of 0, 1 and 2
It's in the users guide folks, has been since the beginning with IBasic back in the 90's.
Language->Variables
Quote
As noted in the above example you access an array using an â€ËÅ"index’ into the array. Indices start at 0 so the maximum index will be one less than the value specified in the DEF statement. To create a multidimensional array use the comma to separate dimensions.
Paul.