Inquiridor
COMO TRABALHAR COM CLASSES ?

Pergunta
-
Galera gostaria de saber como utilizar classes utilizando o ASP
Criei meu arqui de classe mas nao estou sabendo como utiliza-lo.Como eu utilizo as funções da classe??????
Por favor me ajudem.Segue abaixo meu arquivo com a classe e suas funçoes
<% 'definição do nome da sua classe Class Noticias '===================================================FUNÇOES ADMINISTRATIVAS==================================================== Dim Categoria, Categoria_coluna, Titulo, Texto, Reporter, Fotografo 'definição de variáveis que serão utilizadas para guardar as informações que serão digitadas. Dim var_Id_Noticia, var_Id_Categoria, var_Categoria, var_Categoria_coluna, var_Titulo, var_Texto, var_Reporter, var_Fotografo, var_Foto, var_Nome_Foto, ExibeData Private ConexaoDB 'variáel que fará a conexão com banco. Private RS_incluirnoticias , RS_ExibeCat_colunas, RS_ExibirConteudoPagina, RS_ExibirFotosNoticias, RS_AlteraNoticia , RS_UPLOAD'variável do recordset. Private SQL_incluirnoticias, SQL_ExibeCat_colunas, SQL_ExibirConteudoPagina, SQL_ExibirFotosNoticias, SQL_AlteraNoticia, SQL_UPLOAD 'variável que terá o retorno do que foi gravado. 'Criei variáveis privadas, porque só serão usadas aqui na classe. Private sub AbreConexao Set Conexaodb = Server.CreateObject("ADODB.Connection") Conexaodb.open "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=revistahoje; User=user;Password=senha;Option=3;" end sub 'função que fecha a conexão com o banco. Private Sub FechaConexao Conexaodb.close set Conexaodb = nothing end sub 'função que chamarei para fazer a inclusão dos dados. Sub IncluirNoticia 'chama a função que faz a conexão com banco. Call AbreConexao SQL_incluirnoticias = "Insert into tbl_noticias (categoria, categoria_coluna, titulo, texto, reporter, fotografo) values ('" & categoria & "', '"&categoria_coluna&"', '"&titulo&"', '"&texto&"', '"&reporter&"', '"&fotografo&"')" set RS_incluirnoticias = ConexaoDB.Execute(SQL) Call FechaConexao End Sub 'Função para UPLOAD DAS FOTOS Sub EnviarFotos Set objUpload = server.CreateObject("Dundas.Upload.2") objUpload.MaxFileSize = 500 objUpload.UseVirtualDir = false objUpload.UseUniqueNames = TRUE objUpload.Save("E:\vhosts\revistahoje.com.br\httpdocs\sgc\imgs_noticias\") For Each objUploadedFile in objUpload.Files path=objUploadedFile.Path var_Foto = objUpload.GetFileName(path) var_Nome_Foto = objUpload.GetFileName(objUpload.Files(0).Path) Call AbreConexao SQL_UPLOAD = "INSERT INTO fotos (id_noticia, foto) values ('"&var_Id_Noticia&"','"&var_Nome_Foto&"')" set RS_UPLOAD = ConexaoDB.Execute(SQL_UPLOAD) next Call fechaConexao set RS_UPLOAD = NOTHING Set objUpload = nothing End Sub 'FUNÇÃO PARA ALTERAÇÃO DE NOTÍCIAS Categoria, Categoria_coluna, Titulo, Texto, Reporter, Fotografo Sub AlteraNoticia Call AbreConexao SQL_AlteraNoticia = "UPDATE tbl_noticias SET categoria = '"&var_Categoria&"', categoria_coluna = '"&var_Categoria_coluna&"', titulo = '"&var_Titulo&"', texto = '"&var_Texto&"', reporter = '"&var_Reporter&"', fotografo = '"&var_Fotografo&"' WHERE id = = '"&var_Id_Noticia&"'" set RS_AlteraNoticia = ConexaoDB.Execute(SQL_AlteraNoticia) Call FechaConexao End Sub 'FUNÇÃO PARA EXCLUSÃO DE NOTICIA Sub ExcluirNoticia '-----------------------EXCLUIR FOTO------------------------------------ On Error Resume Next If Mid(var_Foto, 2, 1) <> ":" Then var_Foto = Server.MapPath("../imgs_noticias/"&var_Foto) End If If Err Then Err.Clear On Error GoTo 0 Dim FSO Set FSO = Server.CreateObject("Scripting.FileSystemObject") If FSO.FileExists(var_Foto) Then FSO.DeleteFile var_Foto End If Set FSO = Nothing '======================================================================= Call AbreConexao SQL_ExcluirNoticia = "DELETE FROM tbl_noticias where id = '"&var_Id_Noticia&"'" set RS_ExcluirNoticia = ConexaoDB.Execute(SQL_ExcluirNoticia) SQL_EXCLUIR_FOTO = "DELETE FROM tbl_noticias where id_noticia = '"&var_Id_Noticia&"'" set RS_EXCLUIR_FOTO = ConexaoDB.Execute(SQL_EXCLUIR_FOTO) Call FechaConexao End Sub 'FUNÇÃO PARA EXIBIR CATEGORIA DE DAS COLUNAS Sub ExibirCategoriasColunas Call AbreConexao SQL_ExibeCat_colunas = "SELECT * FROM cat_colunas" set RS_ExibeCat_colunas = ConexaoDB.Execute(SQL_ExibeCat_colunas) End Sub 'FUNÇÃO PARA EXIBIR CATEGORIAS DE NOTICIAS(CAPA-ENTREVISTA-POLITICA-ECONOMIA-SAUDE....) Sub ExibirConteudoPagina Call AbreConexao SQL_ExibirConteudoPagina = "SELECT * FROM tbl_noticias where categoria = '"&var_Id_Categoria&"' and categoria_coluna ='"&var_Categoria_coluna&"' order by id desc limit 3" set RS_ExibirConteudoPagina = ConexaoDB.Execute(SQL_ExibirConteudoPagina) End Sub 'FUNÇÃO PARA EXIBIR FOTOS RELACIONADAS A CADA NOTICIA Sub Exibir_Foto Call AbreConexao SQL_ExibirFotosNoticias = "SELECT * FROM fotos where id_categoria = '"&var_Id_Categoria&"'" set RS_ExibirFotosNoticias = ConexaoDB.Execute(SQL_ExibirFotosNoticias) End Sub Sub ResizeFotos Set Jpeg = Server.CreateObject("Persits.Jpeg") 'Set JpegLogo = Server.CreateObject("Persits.Jpeg") Jpeg.PreserveAspectRatio = True caminho = "sgc/imgs_noticias/"&var_Foto&"" 'JpegLogoPath = Server.MapPath("sgw/img/logo_divulga.png") 'Open source file Jpeg.Open (server.mappath(caminho)) 'JpegLogo.Open JpegLogoPath 'Jpeg.DrawImage Jpeg.Width-295, Jpeg.Height-100, JpegLogo Jpeg.Width = 245 Jpeg.Height = Jpeg.OriginalHeight * Jpeg.Width / Jpeg.OriginalWidth Response.BinaryWrite(Jpeg.SendBinary) End Sub '=======================================================FIM FUNÇÕES ADMINISTRATIVAS============================================= '------------------------------------------------------------------------------------------------------------------------------- '===========================================================FUNÇÕES AUXILIARES================================================== 'FUNÇÃO DATA Sub Exibe_Data Dim nDia, nMes, nAno, nDiaSemana, ExibeData Dim sDiaSemana, sMes nDia = day(Date) nMes = month(Date) nAno = year(Date) nDiaSemana = weekday(Date) select case nDiaSemana case 1 sDiaSemana = "Domingo" case 2 sDiaSemana = "Segunda-Feira" case 3 sDiaSemana = "Terça-Feira" case 4 sDiaSemana = "Quarta-Feira" case 5 sDiaSemana = "Quinta-Feira" case 6 sDiaSemana = "Sexta-Feira" case 7 sDiaSemana = "Sábado" end select select case nMes case 1 sMes = "Janeiro" case 2 sMes = "Fevereiro" case 3 sMes = "Março" case 4 sMes = "Abril" case 5 sMes = "Maio" case 6 sMes = "Junho" case 7 sMes = "Julho" case 8 sMes = "Agosto" case 9 sMes = "Setembro" case 10 sMes = "Outubro" case 11 sMes = "Novembro" case 12 sMes = "Dezembro" end select ExibeData = nDia & " de " & sMes & " de " & nAno End Sub 'FUNÇÃO ANTI-INJECTION Sub LimparTexto(str) str = trim(str) str = replace(str,"'","") str = replace(str,"""""","") str = replace(str," or ","") str = replace(str," and ","") str = replace(str,"update","") str = replace(str,"-shutdown","") str = replace(str,"--","") str = replace(str,"'","") str = replace(str,"#","") str = replace(str,"$","") str = replace(str,"%","") str = replace(str,"","") str = replace(str,"&","") str = replace(str,"'or'1'='1'","") str = replace(str,"--","") str = replace(str,"insert","") str = replace(str,"drop","") str = replace(str,"delete","") str = replace(str,"xp_","") str = replace(str,"select","") str = replace(str,"*","") LimparTexto = str end Sub '========================================================FIM FUNÇÕES AUXILIARES================================================== '------------------------------------------------------------------------------------------------------------------------------- End Class %>
Como devo proceder, por exemplo na pagina index, para exibir uma foto de determinada categoria, exibir o titulo de determinada noticia?
Enfim, quem puder me ajudar a endender classes no ASP ficarei muito grato!!!
Estou tentando exibir as informações na minha pagina princial da seguinte forma, porem esta dando erro.
Segue abaixo a forma que estou tentando chamar a função que exibe as informações do banco:
<% Dim CAPA, RS_ExibirConteudoPagina Set CAPA = new Noticias CAPA.var_Categoria = "Capa" CAPA.ExibirConteudoPagina %> <% Do While Not CAPA.ExibirConteudoPagina(RS_ExibirConteudoPagina).Eof %> <div align="left" class="style2"><%= CAPA.ExibirConteudoPagina(RS_ExibirConteudoPagina("titulo")) %></div><br> <div align="left" class="style2"><%= CAPA.ExibirConteudoPagina(mid(CAPA.RS_ExibirConteudoPagina("titulo"), 1, 35 ))%>...</div> <% CAPA.ExibirConteudoPagina(RS_ExibirConteudoPagina).MoveNext Loop call fechaconexao %>
Quando executo a pagina, é exibido o seguinte erro:
Microsoft VBScript runtime error '800a01c2'
Wrong number of arguments or invalid property assignment: 'ExibirConteudoPagina'
Alguém me ajuda?????
Obrigado!!!
ANDRÉ GUSTAVO
Todas as Respostas
-
André, não se já resolveu a questão, mas pelo que verifiquei no código parece que você esta chamando 'ExibirConteudoPagina' passando parâmetros como se fosse uma função, porém você declarou como uma 'SUB' e não como 'FUNCTION'.
Abraço
Estevam
**** Se a reposta foi útil, então não esqueça de marca-lá. ***