Adding new string to array?

BlitzMax Forums/BlitzMax Programming/Adding new string to array?

Trader3564(Posted 2008) [#1]
Hey. Im really strugeling on how to add strings to an array, or TList, or whatever.

I start with an undefined sized box, and i add strings.
At the end, i want to loop through these strings.
I get all kinds of errors that the opreation i do is not allowed.
Do i really have to define the size of an array? (And TList is pointers only, right? so that explains it doesnt take strings)


Trader3564(Posted 2008) [#2]
i know i could use a custom type... but isnt there another way?

type TStringArr
field str:String
end type


Dreamora(Posted 2008) [#3]
TList takes object and string is an object. The only thing it does not take are numerics which are no objects.

And an array without a size is no array, its null. You must initialize an array to be anything meaningfull.
Depending on what you want to put in the array it must either be of type :string or :object, the later will need backcasting -> potentially wasted performance


Sledge(Posted 2008) [#4]
...ie
SuperStrict

Local MyList:TList = CreateList()

For Local i:Int = 1 To 10
	Local NewString:String = String(i)
	ListAddLast MyList,NewString
Next

For Local OutputString:String = EachIn MyList
	Print OutputString
Next



Trader3564(Posted 2008) [#5]
ListAddLast(lines, line)

well, the above doesn't work, and im pretty sure that
lines = TList
line = String


Trader3564(Posted 2008) [#6]
sheesh!! thanks... i forgot ... = CreateList()
>_> pfff.. i need coffee!


Sledge(Posted 2008) [#7]
The above works fine, I don't post without testing. Are you using SuperStrict, and what error message are you getting?

EDIT: Ah, you got it sorted!


Trader3564(Posted 2008) [#8]
No its working fine :) But i was surprised to see ive een strugling all the time because i forgot to add = CreateList()
:-P
Thanks for your help! I now finished the thigy i was working on, and it works great.