PDA

View Full Version : Error Code 400



peter
15-10-2008, 17:01
Hi Eros,

i get an error message .
Error Code 400.
"Subscript out of range in array or matrix."

The routine is simple:

dim buffer4 as string
dim datas(4) as string

datas(1) = "Hallo"
datas(2) = "Halla"
datas(3) = "Hallu"
datas(4) = "Halli"

buffer4 = ""
dim j
for j = 1 to 4
buffer = buffer + datas(j)
next

I checked it with other Basic language.
No problems therewith !

Peter

Michael Hartlef
15-10-2008, 17:16
Peter,you code is full of errors.

1) You defined buffer4 but not buffer
2) you try to dimension J but without the AS LONG
3) You try to add to BUFFER but didn't define it.

Try this



uses "CONSOLE"

dim buffer as string
dim datas(4) as string
dim j as long

datas(1) = "Hallo"
datas(2) = "Halla"
datas(3) = "Hallu"
datas(4) = "Halli"

buffer = ""

for j = 1 to 4
buffer = buffer + datas(j)
next
console_print(buffer)
console_waitkey

Michael Clease
15-10-2008, 17:19
for j = LBOUND(datas) to UBOUND(datas)
buffer += datas(j)
next

:P @ Mike

Michael Hartlef
15-10-2008, 17:23
Humbuck. Cosmetics :P ;D

Petr Schreiber
15-10-2008, 17:43
Both Michaels code works fine,

if the code really just has to concatenate array elements, we can go this way too:


uses "CONSOLE"

dim buffer as string
dim datas(4) as string
dim j as long

' -- Array assign is clean way to assign whole array
array assign datas() = "Hallo", "Halla", "Hallu", "Halli"

' -- Join$ can concatenate elements of array very easily
buffer = join$(datas, "")

console_print(buffer)
console_waitkey



Petr

ErosOlmi
15-10-2008, 18:20
Petr,

one of the problem and joy of thinBasic is that it is strictly typed. That is you need to state what type a variable is.
Coming from other BASIC where you can just use an undefined name and the language will make some assumption, this can be a problem.
Automatically define new variables when tokens are not recognized is a quite easy step but this would create more problems because if you just miss one letter in a previously used variable, a new variable would be allocated. We prefer to be more restrictive also for a programming educational point of view.

If you do not specify a type with the AS clause, VARIANT is assumed.
I just checked help file and this is not stated, so this is my fault. I will fix it for the next release under DIM keyword.

The rest is already replied I suppose.

Ciao
Eros

peter
15-10-2008, 18:39
Hi all,

i forgot "as Long", but this is no mistake.
j is only a variant typ.
The name of the Buffer should be called Buffer4 !
The code is not for a consoles Program!

In the meantime I was able to found the error !
and I have corrected it.

However:
You have been a great help, thank you very much !
Peter

By the way:
My game is ready soon.
Where can i upload it ?

ErosOlmi
15-10-2008, 18:55
By the way:
My game is ready soon.
Where can i upload it ?



I think you can use this forum: http://community.thinbasic.com/index.php?board=46.0
Important is to make a post with your program attached and if any update always keep updated that post. So just avoid to spread different similar versions of the same program.

Ciao
Eros