Working with strings

BlitzMax Forums/BlitzMax Beginners Area/Working with strings

297Chrisc(Posted 2007) [#1]
I'm looking for a way to collect input to a custom gui textbox (without using blitz gui) and displaying it on a multiple line textbox (editable by the user) any suggestions?


297Chrisc(Posted 2007) [#2]
I can deal with the input side of things, I just need to know the best way to store the textbox content and how I go about converting it to display on multiple lines


tonyg(Posted 2007) [#3]
I would store each textbox entry as a type instance and display each on a seperate line.


Dreamora(Posted 2007) [#4]
If you want to do your own multiline textbox you will need to seperate the line into single strings.
Simplest way to do so is using the linebreak character as seperation character for the string.split() method which returns an array of string

after that you just render line after line.

To store it, you can write each string with writeline to a file and get it back by using readline.


297Chrisc(Posted 2007) [#5]
can you write a quicky example for me? sorry :)


Dreamora(Posted 2007) [#6]

' its assumed that you have an array lines:string[] which is filled with the textlines
'according my descripting above with the .split method from blitzmax string module

for local i:int = startLine to endLine
  drawtext lines[i], x, y + (i-startLine)*15 
next




save and read works through the regular stream readline / writeline commands using the lines array


297Chrisc(Posted 2007) [#7]
Ive got:

Type Gui_Textbox
Field X,Y,W,H
Field Content$
End Type
Gui_Textbox_list:Tlist = createlist()


297Chrisc(Posted 2007) [#8]
I think ill just go to sleep and give up :(


Dreamora(Posted 2007) [#9]
Instead of Content, make it Content:string[]

And save line for line in it.

As well you will perhaps need 2 numbers that specifiy the first and last textline to draw in case you have more text than can be rendered at once ie you need a scrollbar.


297Chrisc(Posted 2007) [#10]
Ok, really confused, started trying to write a small test to get used to arrays... why wont this work?!

Names:String[1]
Names[0] = "Name1"
Names[1] = "Name2"


Brucey(Posted 2007) [#11]
You need to initialize the array with "size", which in your case is 2.... 0 being the first entry, 1 being the second.

So,

Namess:String[2]


297Chrisc(Posted 2007) [#12]
But this dont work either:

Names:String[2]
Names[0]= "Test"
Names[1]= "Test2"


297Chrisc(Posted 2007) [#13]
Oh Im so dumb, I just had to declare it as either a local or global, sorry


297Chrisc(Posted 2007) [#14]
How can I add more elements to the array, whilst retaining the origional elements?
i.e.
Local Test:String[10]
blah blah blah

but then I need to add say two more onto the end resulting in an array with 12 elemts if you see what I mean?


Dreamora(Posted 2007) [#15]
By using Slicing (see docs for more specific information)

this means test = test[.. newNumberOfElements]


297Chrisc(Posted 2007) [#16]
got it up and running... kinda,
Here is the file:

http://www.mediafire.com/?511fjm6dzgx

Could someone run it and possibly tell me why it kinda goes wrong when the last character in any given line is a space?

Also tell me what you think cos its my first attempt at a blitzmax program, and I decided to jump in at the deep end and try to build a simple gui.

Cheers


297Chrisc(Posted 2007) [#17]
also it wont delete back over a line, im stuck!! Help!