Página 1 de 1

Ajuda com vetor

Enviado: 25 Mar 2016 13:59
por asimoes
Pessoal,

Eu tenho um vetor exemplo assim:

Código: Selecionar todos

LOCAL oElemento
aVetor:={}
aAdd(aVetor, {"Linha1"," Coluna"})
aAdd(aVetor, {"Linha2"," Coluna"})
aAdd(aVetor, {"Linha3", "Coluna"})
aAdd(aVetor, {"Linha4", "Coluna"})

FOR EACH o Elemento IN aVetor
   ? oElemento[1], oElemento[2]
NEXT
Eu sei quantas linhas tem usando a função Len, nLinhas:=Len(aVetor), agora eu queria saber quantas colunas tem esse vetor por linha, tem como, rodando dentro do FOR EACH?

Ajuda com vetor

Enviado: 25 Mar 2016 14:13
por asimoes
Pessoal,

Consegui,

A minha intenção é montar um html table

Código: Selecionar todos

aVetor:={}

aAdd(aVetor, {"Linha1"," Coluna", "1"})
aAdd(aVetor, {"Linha2"," Coluna", "2"})
aAdd(aVetor, {"Linha3", "Coluna", "3"})
aAdd(aVetor, {"Linha4", "Coluna", "4"})

cHtml:=MontaHtml(aVetor)

FUNCTION MontaHtml(aVetor)
LOCAL oElemento, cTable

   cTable := '<!DOCTYPE html>'+hb_eol()
   cTable += '<html>'+hb_eol()
   cTable += '<body>'+hb_eol()
   cTable += '<table border="1" style="width:50%">'+hb_eol()
   nCol := Len(aVetor[1])
   FOR EACH oElemento IN aVetor
       IF Mod(oElemento:__enumIndex(), 1) = 0
          cTable += '   <tr>'+hb_eol()
       ENDIF
       FOR nCont:=1 TO nCol
          cTable += '      <td>'+oElemento[nCont]+'</td>'+hb_eol()
       NEXT
       cTable += '   </tr>'+hb_eol()
   NEXT
   cTable += '<body>'+hb_eol()
   cTable += '<html>'+hb_eol()
   hb_Memowrit("tabela.html", cTable)
RETURN cTable   
O resultador é esse:
Resultado
Resultado
Screen Shot 03-25-16 at 02.12 PM.PNG (3.92 KiB) Exibido 800 vezes

Ajuda com vetor

Enviado: 25 Mar 2016 17:46
por fladimir
Legal... parabéns

Obrigado por compartilhar.

Ajuda com vetor

Enviado: 25 Mar 2016 18:31
por asimoes
Gerar mensagem table html para envio email.

Uso:

Código: Selecionar todos

aVetor:={}

aAdd(aVetor, {'Data e Hora do Erro', hb_DtoC( Date(),"DD/MM/YYYY" ) + " - " + Time()})
aAdd(aVetor, {'Nome do Executável', cExeName})
aAdd(aVetor, {'Data e Hora do Executável', cDataExe})
aAdd(aVetor, {'Nome do Computador', hb_GetEnv("computername", NetName())})
aAdd(aVetor, {'Usuário do Computador', hb_GetEnv("username", NetName(.T.))})
aAdd(aVetor, {'IP/MAC do Computador', aMac[1, 1]+" "+aMac[1, 2]})
aAdd(aVetor, {'Memória Disponível', Transform(LTrim(Str( Memory(0) )),"@R 9,999,999")})
aAdd(aVetor, {'Espaço em Disco', LTrim(Transform(DiskSpace(),"@R 999,999,999,999,999,999"))})
aAdd(aVetor, {'Serial Lógico do HD', Serial_HD() })
aAdd(aVetor, {'Pasta de Diretório', hb_DirBase()})
aAdd(aVetor, {'Sistema Operacional', Os()})
aAdd(aVetor, {'Compilador C', hb_Version(HB_VERSION_COMPILER)})
aAdd(aVetor, {'Versão do Harbour',  hb_Version(HB_VERSION_HARBOUR)+ " "+hb_Version(HB_VERSION_BUILD_DATE_STR)})
aAdd(aVetor, {'Versão da HWgUI', hwg_Version( 1 )})

cHtmlErroAdd:=win_AnsiToOem(MontaHtml(aVetor, {"Descrição", "Valor"}))


FUNCTION MontaHtml(aVetor, aCabec)
LOCAL oElemento, cTable

   cTable := '<!DOCTYPE html>'+hb_eol()
   cTable += '<html>'+hb_eol()
   *---------------------------------------
   cTable += '<head>'+hb_eol()
   cTable += '<style>'+hb_eol()
   cTable += 'table, th, td {'+hb_eol()
   cTable += '   border: 1px solid black;'+hb_eol()
   cTable += '   border-collapse: collapse;'+hb_eol()
   cTable += '}'+hb_eol()
   cTable += '</head>'+hb_eol()
   cTable += '</style>'+hb_eol()
   cTable += '<body>'+hb_eol()
   cTable += '<table border="1" style="width:100%">'+hb_eol()
   cTable += '<table style="width:100%">'+hb_eol()
   nCol := Len(aVetor[1])
   
   cTable += '<tr>'
   
   FOR EACH oElemento IN aCabec
       cTable += ' <th>'+oElemento+'</th>'+hb_eol()
   NEXT
   
   cTable += '</tr>'
 
   FOR EACH oElemento IN aVetor
       IF Mod(oElemento:__enumIndex(), 1) = 0 
          cTable += '   <tr>'+hb_eol()
       ENDIF
       FOR nCont:=1 TO nCol
          cTable += '      <td>'+oElemento[nCont]+'</td>'+hb_eol()
       NEXT
       cTable += '   </tr>'+hb_eol()
   NEXT
   cTable += '<body>'+hb_eol()
   cTable += '<html>'
   hb_Memowrit("tabela.html", cTable)
RETURN cTable   

Table html com mensagem
Table html com mensagem

Ajuda com vetor

Enviado: 26 Mar 2016 11:53
por janio
aSimoes,

Eu já tenho algo bem parecido em que o meu sistema mim envia um email com o erro. Porem, eu gero um txt com as informações do erro.

Pq vc prefere em html? qual seria a diferença em relação ao txt?

Janio

Ajuda com vetor

Enviado: 26 Mar 2016 12:01
por asimoes
Ao invés de eu anexar um arquivo txt do erro, eu recebo o html formatado assim é menos um lixo no hd, o email será descartado depois de ler.

Ajuda com vetor

Enviado: 26 Mar 2016 15:24
por ANDRIL
Que bom que já conseguiu, segue mais um exemplo.

Código: Selecionar todos


nColunas=0
FOR EACH oElemento IN aVetor
 ? oElemento[1], oElemento[2]
 ? len(oElemento)
 nColunas+=len(oElemento)
NEXT
? nColunas
Até+