Different StrSplit in 6.9

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Before 6.9 I could do:

Sub Globals
Dim arrColWidths(1) As Int64
End Sub

Sub btnSQL_Click

Dim strColWidths

arrColWidths() = StrSplit(strColWidths, ",")


But that now gives:
Error compiling program.

Error message: error CS0029: Cannot implicitly convert type 'string[]' to 'long[]'

What is the best way to handle this?
Of course I can just do instead: Dim arrColWidths(1)
without setting the datatype, but maybe there is a better way.


RBS
 

mjcoon

Well-Known Member
Licensed User
Dim arrColWidths(1) As Int64

Well, StrSplit is defined to return an array of strings, and the 6.90 help suggests declaring the array explicitly as such.

So it is a bit unfair to expect an implicit conversion! Especially as it would fail if any of the split strings happened not to be numeric...

No doubt you could do it before merely because the "Int64" was actually ignored and what you got was an array of strings regardless.

Mike.
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Yes, I found this now in the What is new section of the help:

Backwards compatibility issues:
· The type of arrays and structures cannot be changed after the first declaration.


RBS
 

sitajony

Active Member
Licensed User
Hi, I'm not sure but maybe you can write this:
B4X:
Sub Globals
Dim arrColWidths(0) As String
End Sub

Sub btnSQL_Click

Dim strColWidths

arrColWidths() = StrSplit(strColWidths, ",")
And after you get the datas... The output of the StrSplit Function is an String Array. You can't normaly put a string in a int64...
StrSplit=String Split and not Int64 Split ;)
You can use this values on the attributes Width even if it's in String normaly...
Example:
B4X:
.Width=arrColWidths(0)
...=....

I hope it's helpfull...

Else you can also I think do this otherwise:
B4X:
pos=StrIndexOf(strColWidths,",",0)
Do While pos>-1
   .Width=SubString(strColWidths,0,pos)
   strColWidths=substring(strColsWidths,pos+1,StrLength(strColsWidths)-pos-1)
   pos=StrIndexOf(strColWidths,",",0)
Loop
But it's longer... (And maybe there's an Error...)

Good luck ;)
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Yes, declaring the array as a string array seems to make sense.
Difference won't be noticeable in practice, but I suppose it is a bit faster.
Main thing is that I understand now what is going on in 6.9.

RBS
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
As written in an above post, what happened in previous versions was that although you declared the array as Int64 it was replaced with a strings array as the result of StrSplit.
So the performance here is exactly the same as before.

BTW, as of v6.90 it is recommended to declare numeric variables with the Number type (which maps to Double). The Number type should perform best.
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
What I found somewhat strange is that loop counter should be declared as Number. Strange as Number is a double and loop counters always will be integer numbers. Why are they/should they be declared as Number?

RBS
 

corwin42

Expert
Licensed User
Longtime User
But the question keeps the same. Why are double variables better than integer as loop variables? Integer are shorter and so they should be modifiable much faster.

Erel, can you explain why double variables are the fastest?
 
Top