Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array Filling 1

Status
Not open for further replies.

TanTrazz

Programmer
Aug 18, 2001
54
NL
Hi all,

I've got an array with max 4 values. But all 4 values must be filled with a number.

Is it possible to fill the array with for example a 0 (zero) value?

or maybe with an if statement?

Test = Split(ids, ",") Here i split the ID's.

if there are only 2 values are clicked there would be 2 ids, but im expecting 4 ids. is it possible to fill the last 2 id's with 0 (zero)?

if test(2) = "" then test(2)=0 will not work.

Thanks in advance.

TanTrazz
 
You just have to do it... don't rely on some builtin function otherwise it would be pure inflation of the function library.
[tt]
dim a(3),test
'ids given somewhere
test=split(ids,",")
if ubound(test)>ubound(a) then 'I want to keep the logic less dependent on the concrete number 3 in dim a(3)
'you get something more than you expect: do something
else
for i=0 to ubound(test)
a(i)=test(i)
next
for i=ubound(test)+1 to ubound(a)
a(i)=0
next
end if
'a is for further use in the desired format
[/tt]
 
tsuji,

You have more experience with ASP than I do. I started thinking about this problem before you responded. I have come up with a solution that is different than yours, and was wondering if you could take a look at it. In my opinion, it's simpler than your code, but as we all know, simpler is not always better.

Code:
Dim ids
Dim Test

ids = "1,2"

Test = Split(ids [!]& ",0,0,0,0"[/!], ",")
[!]Redim Preserve Test(3)[/!]
For i = lbound(test) to ubound(test)
	Response.write(test(i) & "<br />")
Next

Basically, we add extra items to the list of id's and then redim preserve the resulting array to 4 elements.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Gmmastros,

Its works fine thank u very much.

tsuji,

Thanks for the fast reply.

Greetz TanTrazz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top