April 26, 2024, 08:42:06 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


STRING$ problem?

Started by billhsln, August 28, 2011, 02:45:54 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

billhsln

It seems that:

rtn = STRING$(3-i,"0") + rtn

Returns with this warning:

Compiling...
File: C:\Users\Public\Documents\IWBasic\MyProgs\Modified_Converter.iwb (94) Warning: Converting (1st argument) string to char

rtn = string
i = int

So, not sure why the warning.

Bill
When all else fails, get a bigger hammer.

LarryMc

I did this
string rtn ="Z"
int i=0
rtn = STRING$(3-i,"0") + rtn
print rtn

and received no warning

try it by itself and see if you still get the warning

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

billhsln

Used your exact code:

Compiling...
Test_String.iwb
File: C:\Users\Public\Documents\IWBasic\MyProgs\Test Programs\Test_String.iwb (3) Warning: Converting (1st argument) string to char
File: C:\Users\Public\Documents\IWBasic\MyProgs\Test Programs\Test_String.iwb (3) Warning: Converting (1st argument) string to char
File: C:\Users\Public\Documents\IWBasic\MyProgs\Test Programs\Test_String.iwb (3) Warning: Converting (1st argument) string to char
No Errors

Linking...
IWBasic Linker v1.11 Copyright © 2011 Ionic Wind Software
Generating C:\Users\Public\Documents\IWBasic\MyProgs\Test Programs\Test_String.exe
Build completed

Bill
When all else fails, get a bigger hammer.

LarryMc

Look in the about box of the IDE and see what version of the compiler you have.

try redownloading and installing over your current installation.

what compiler option flags do you have set?

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

STRING$(count as INT,c as char)
You have passed a string instead CHAR. Use `0` or ´0´ to get rid of the warning.
The reported index "1st" is wrong, it whould be "2nd" - will be fixed soon.

LarryMc

August 28, 2011, 03:36:26 PM #5 Last Edit: August 28, 2011, 03:38:52 PM by LarryMc
Then why do I NOT get a warning and he does?

BTW, the example in the user's guide for STRING$ uses an "A"

this compiles for me without errors or warnings and works fine

string rtn ="Z"
int i=0
rtn = STRING$(3-i,"0") + rtn
print rtn

' user's guide example
A$ = STRING$(5,"A")

print A$


FYI - the only compiler option I have checked is zero local variables

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

billhsln

I have no options checked.

Compiler is 2.094 (most current that I know of).

Weird....

Bill
When all else fails, get a bigger hammer.

LarryMc

too new.
I'm using the one from the customer download page which is 2.090.

the 94 version is one of those development versions of Sapero's that sneaked into the release version.

I believe if you go to the customer page and download the version currently there and install it over your copy your problem with the warning will go away.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

It appears the wrong version is currently in the customer download area.
Anyway, I went round about and got a copy of the 94 version of the parser.
with it I duplicate your problem exactly
with the 90 version of the parser your problem isn't there.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

billhsln

Downloaded file from Customer area again, it is still v 2.094.

Just my kind of luck to find a weird warning.

Bill
When all else fails, get a bigger hammer.

LarryMc

yep, and it's the wrong one.

Larry S will have to fix it tomorrow/today?

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

GWS

Hi,

There is now a divergence between IWB and CB ..  :o

This works with no problems in CB ..


openconsole
cls

def rtn:string
def i:int

i=0
rtn ="Z"
rtn = STRING$(3-i,"0") + rtn
print rtn

do:until inkey$<>""
closeconsole
end


.. the result being '000Z'.

But Sapero says the "0" in the string statement should be a character '0' .. not the string "0" .

Admittedly, the Help in CB for STRING$( ) simply says Result$ = STRING$ (count, character ),
and IWB Help says STRING = STRING$(count as INT,c as char).

IWB however, giving the example:

A$ = STRING$(5,"A")

So for consistency, I reckon we should stick to the format .. STRING$(3-i,"0")  ..  not STRING$(3-i,'0').

Implying I suppose that a 'character' is a string of length 1.

Interestingly, Visual Basic gives Microsoft's version as String$(strlength, ANSIcode), OR String$(strlength, strexpr).

With examples string$(8,43) - which gives a string of ++++++++
or string$(8,"+") which gives the same result.

I don't think IWB or CB can accept the ANSI form ..  ::)  It would be neat though.

best wishes, :)

Graham


Tomorrow may be too late ..

aurelCB

In EB works...
I must say that i'm always confused about type CHAR - which sounds like
CHAR - ACTER
In many other basics are BYTE .Maby have different meaning i dont know
look same example with TYPEDEF :
openconsole
cls

def rtn:string
def i:int
'look nex line
TYPEDEF byte CHAR


i=0
byte ="Z"
print LEN(byte)
byte = STRING$(3-i,"0") + byte
print byte

do:until inkey$<>""
closeconsole
end


So CHAR is character, right...
In some other languages i think that is not ... ::)

sapero

August 29, 2011, 06:49:46 AM #13 Last Edit: August 29, 2011, 07:00:08 AM by sapero
A string is still allowed when passing to an CHAR argument, but note that your code may be not always optimized, and a warning will be generated, because string to char/word/int conversion sometimes may be a serious bug, not always easy to find:
declare import, SendMessageA(/*cut*/, int lParam)
SendMessageA(/*cut*/, "hello") ' hell by value is passed - 4 first characters

If the message handler is expecting an string, the function above may crash your program, so you probably see why I added this warning.

When using characters - try not to use anonymous numbers. 0, 10, 13, 32, 48, 65 are easy to remember, but 69, 95 ... are very "anonymous" - if you go away and return back to your code after a week, it will be hard to read the code without an ascii table.

Aurel, BYTE in IWB is already known as a type. It has been added to use in the PRINT command, to display a number instead a character
char a=65
byte b = 65
schar c = 65
print a,b,c ' A65 65

GWS

"When using characters - try not to use anonymous numbers. 0, 10, 13, 32, 48, 65 are easy to remember, but 69, 95 ... are very "anonymous"

Good point - consider that one shot down ..  ;D

I take it you mean a "0" will still be acceptable in the STRING$ function as well as '0' in IWB, but IWB users will get a warning.

CB won't accept a character in the form '0' in the STRING$ function - the program will hang  :o
It has to be in the form "0".

best wishes, :)

Graham
Tomorrow may be too late ..

aurelCB

QuoteAurel, BYTE in IWB is already known as a type
Oups ...I don't know that.

Of course that '0' is not valid in CB ,by the way i don't know which basic use
'$' for string literal ,most use double quotes "$".

billhsln

Well, the beta version download works, the production version does not.

Just my luck, again.

Bill
When all else fails, get a bigger hammer.

LarryMc

OK, here's where we are at.
When everyone has the latest version this is how it will work(as it is fixed right now).

A$ = STRING$(5,"A")
will print AAAAA with no warning

A$ = STRING$(5,"ABC")
will print AAAAA with a warning

The preceding two generate un-optimized code.
-------------------------------------------------------
A$ = STRING$(5,95)
will print AAAAA with no warning

A$ = STRING$(5,`A`)      <--- ` is the key to the left of the 1 key
will print AAAAA with no warning

A$ = STRING$(5,`ABC`)      <--- ` is the key to the left of the 1 key
will print CCCCC with no warning
NOTE: Sapero may want to change this one after he sees this.
The preceding 3 generate optimized code because there is never a STRING to deal with.
-------------------------------------------------------------------------------------------------
Sapero tells me that the German keyboard has a ` that slopes in the opposite direction which can also be used.

You can NOT use the ' (straight up and down) that is shared with the " key.  That is a COMMENT.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library