Toon posts:

[Asp] arrays 'feature'

Pagina: 1
Acties:

Verwijderd

Topicstarter
Ik ben lekker bezig met arrays etc en stuitte op de volgende leuke feature:

code:
1
2
3
4
5
6
7
8
9
10
dim bla ()

redim bla (5)

bla (0) = "bla"
bla (1) = "bla2"
bla (2) = "bla3"
bla (3) = "bla4"
bla (4) = "bla5"
bla (5) = "bla6"


Dit gaat gewoon goed...

Doe je echter de volgende regel toevoegen, dan pas gaat het fout:
Subscript out of range: '[number: 6]'

code:
1
bla (6) = "bla7"


Ben ik nou gek of niet? Als ik de eerste code in Java probeer, dan weet ik zeker dat ik al eerder een array out of bounds error krijg.

Ik specifeer een array van grootte 5 en hij maakt hem grootte 6, een beetje heel erg weird.

Dit zorgt voor een probleempje in mijn eigenlijke code, is hier niets aan te doen of moet ik het maar zo accepteren dan MicroSoft andere ideeen toepast op het gebied van arrays?

Dominique.

  • gorgi_19
  • Registratie: Mei 2002
  • Laatst online: 10:01

gorgi_19

Kruimeltjes zijn weer op :9

Dim can also be used to create static (fixed) and dynamic arrays.

A static array has the number of elements declared by the Dim statement. However, you must remember that the elements in an array are numbered starting at zero. Consider the following Dim declaration. It creates a static array containing six elements that are numbered 0, 1, 2, 3, 4 and 5.

Code:
<% Dim SixElementArray(5) %>

[ Voor 6% gewijzigd door gorgi_19 op 26-01-2004 11:29 ]

Digitaal onderwijsmateriaal, leermateriaal voor hbo


  • zneek
  • Registratie: Augustus 2001
  • Laatst online: 08-02-2025
bookmark die site maar: DevGuru to the resque!!!

Overigens kun je de ASP en Vbscript reference ook op je eigen schijf vinden. Wordt bij de meeste Office versie mee geinstalled (geloof ik). Zoek maar eens op ASP.chm en vbscript5.chm. Scheelt je weer hoofdpijn als je de soms niet logische werking van functies niet snapt.

  • .oisyn
  • Registratie: September 2000
  • Laatst online: 10:51

.oisyn

Moderator Devschuur®

Demotivational Speaker

Ik snap het probleem niet, het staat ook gewoon in de documentatie
[ <attrlist> ] [{ Public | Protected | Friend | Protected Friend |
Private | Static }] [ Shared ] [ Shadows ] [ ReadOnly ]
Dim [ WithEvents ] name[ (boundlist) ] [ As [ New ] type ] [ = initexpr ]

[..]

boundlist
Optional. List of non-negative integers representing the upper bounds of the dimensions of an array variable. Multiple upper bounds are separated by commas. An array can have up to 60 dimensions.
Each value in boundlist specifies the upper bound of a dimension, not the length. The lower bound is always zero, so the subscript for each dimension can vary from zero through the upper-bound value.

It is possible to use -1 to declare the upper bound of an array dimension. This signifies that the array is empty but not Nothing, a distinction required by certain common language runtime functions. However, Visual Basic code cannot successfully access such an array. If you attempt to do so, an IndexOutOfRangeException error occurs during execution.

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.