Jump to content


Photo

Array Dinâmico


  • Faça o login para participar
Nenhuma resposta neste tópico

#1 andregv

andregv

    12 Horas

  • Usuários
  • 157 posts
  • Sexo:Masculino
  • Localidade:São José dos Campos - SP
  • Interesses:Programação Delphi, C/C++, ASP, Banco de Dados, WebDesigner.

Posted 18/11/2005, 11:59

Estou com o seguinte array dinâmico. Eu faço uma busca no banco de dados usando recursividade... passo os dados para o array public.
Só que acontece o seguinte... o primeiro vetor do array fica em branco, myArray(0,x), e gostaria de preencher esse falor com os dados do usuário reg=1 (utilizado para iniciar a busca no bando de dados)... Porém, quanto eu atribuo os dados (linha em negrito)... os demais dados do array somem... alguém pode me orientar onde estou errando?

Agradeço desde já
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
	Response.Buffer = False
	Dim myArray()
	ReDim myArray(0,4)

	Public Function Acres()
  Dim Qtd, Tmp()
  Qtd = Ubound(myArray,1)
  ReDim Tmp(Qtd, 4)
  For i = 0 To Qtd
 	 Tmp(i,0) = myArray(i,0)
 	 Tmp(i,1) = myArray(i,1)
 	 Tmp(i,2) = myArray(i,2)
 	 Tmp(i,3) = myArray(i,3)
  Next
  ReDim myArray(Qtd+1,4)
  For i = 0 To Ubound(Tmp,1)
 	 myArray(i,0) = Tmp(i,0)
 	 myArray(i,1) = Tmp(i,1)
 	 myArray(i,2) = Tmp(i,2)
 	 myArray(i,3) = Tmp(i,3)
  Next
  Acres = Qtd+1
	End Function
	
	Sub MontaLista(varLM, varNivel)
  Dim objRs, varTotal
  Set objRs = objCon.Execute("select idAss, Associate from tblAssociados where line_manager='" & varLM & "' And ativo <> 2")
  If Not objRs.Eof Then
 	 Do Until objRs.Eof
    varTotal = Acres
    myArray(varTotal,0) = objRs("idAss")
    myArray(varTotal,1) = objRs("associate")
    myArray(varTotal,2) = varLM
    myArray(varTotal,3) = varNivel
    MontaLista objRs("associate"),varNivel+1
    objRs.MoveNext
 	 Loop
  End If
  objRs.Close
  Set objRs = Nothing
	End Sub
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Montagem de &Aacute;rvore</title>
</head>
<body>
<%
	Set objCon = Server.CreateObject("ADODB.Connection")
	objCon.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath ("db.mdb") & ";Persist Security Info=False")
	Set objRs = objCon.Execute("select id, associado, diretor from tblassociados where reg=1")
	If Not objRs.Eof Then
  idAssociado = objRs("id")
  varNome = objRs("associate")
  varGerente = objRs("diretor")
	End If
	objRs.Close
	Set objRs = Nothing
	MontaLista varNome, 1
	myArray(0,0) = idAssociado
	myArray(0,1) = varNome
	myArray(0,2) = varGerente
	myArray(0,3) = 0 'nível inicial da busca
	objCon.Close
	Set objCon = Nothing
	Response.Write("<br /><br /><table width='100%' border='1' cellpadding='0' cellspacing='0'>")
	For i = 0 To Ubound(myArray,1)
  If myArray(i,0) = "" Then
 	 Response.Write("<tr>")
 	 Response.Write("<td colspan='4'>Em branco: Posicção " & i & "</td>")
 	 Response.Write("</tr>")
  Else
 	 Response.Write("<tr>")
 	 Response.Write("<td>" & myArray(i,0) & "</td>")
 	 Response.Write("<td>" & myArray(i,1) & "</td>")
 	 Response.Write("<td>" & myArray(i,2) & "</td>")
 	 Response.Write("<td>" & myArray(i,3) & "</td>")
 	 Response.Write("</tr>")
  End If
	Next
	Response.Write("</table>")
%>
</body>
</html>





0 user(s) are reading this topic

0 membro(s), 0 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq