I have some code that I use in sites to enter values in the array, and store in session. This code is very useful for shopping cart in
loja virtual:
<%
Function VetorMonta(Acao,Valor)
'Usamos o case para manipular a ação da função
Select Case Trim(Acao)
Case "Incluir"
'Guarda na variavel Vetor o conteudo da Session
Vetor = Session("GuardaVetor")
'Verifica se a Variavel Vetor é um Array, caso nao for entao definimos ela um Array
If Not IsArray(Vetor) Then Vetor = Array() End if
'Verifica se o Valor que esta sendo inserido já esta no Vetor se estiver entao nao inseri para nao haver duplicidades do vetor
If InStr(Join(Vetor), Valor) = 0 Then
'Este comando ira preservar o vetor e adciona + 1 valor
ReDim preserve Vetor(UBound(Vetor)+1)
Vetor(Ubound(Vetor )) = Valor
'Coloca o conteudo da variavel vetor dentro da Session
Session("GuardaVetor") = Vetor
End if
End Select 'Fim do Case
End Function
Function Incluir_Vetor
'Executa a função que ira criar uma posição do vetor, basta passar a acao e o valor
Call VetorMonta("Incluir",Replace(Request("Valor_Vetor" ),"'",""))
Call VetorMonta("Incluir",Replace(Request("tamanho"),"' ",""))
End Function
Function VisualizaValoresVetor
Response.Write "<table border='2'>"
Response.Write "<tr><td>id</td><td>valor</td>"
Response.Write "</tr>"
For x = 0 To ubound(session("GuardaVetor")) 'ira fazer um laço mostrando todos os vetores criados
Response.Write "<tr><td>" & x & "</td>"
Response.Write "<td>" &session("GuardaVetor")(x) & "</td>"
Response.Write "</tr>"
Next
Response.Write "</table>"
'Verifica se a Session tem alguma posição, se tiver mostra a opção de apagar todos os vetores
If ubound(session("GuardaVetor")) >= 0 Then
Response.Write "<br>" &"<a href='vetor.asp?action=LimpaVetor'>Apagar Tudo</a>" & "<br>" 'Imprime o Vetor na tela
End if
End Function
'USAMOS CASES PARA MANUPULARAS CHAMADAS DAS FUNÃÃES
useraction=request("action")
select case useraction
Case "Incluir_Vetor"
'Chama a function que ira incluir um valor para o vetor
Call Incluir_Vetor
End Select
%>
<table width="100%">
<form name="form" method="post" action="?action=Incluir_Vetor">
<tr>
<td><input name="Valor_Vetor" type="text" id="Valor_Vetor"> </td>
<td><input name="tamanho" type="text" >
<input type="submit" name="Submit" value="Incluir no Vetor"></td>
</tr>
</form>
</table>
<%
'Chama a função que vizualiza todos os vetores criados
VisualizaValoresVetor
%>
I use almost all of my
sites. I hope you find it useful.