Jump to content

Recommended Posts

Posted

Bom dia,

Estou desenvolvendo um sistema em vb.net 2010. A solução contém cinco projetos, um EXE (Principal) e quatro DLL (Cadastro, Financeiro, Jurídico e Biblioteca). A Biblioteca.dll contém uma classe Utils com funções para validar CPF, encriptar Senha e outras. Referenciei a Biblioteca.dll no projeto Principal.exe.  Quando chamo fValidaCPF(txtCPF.text) do Projeto Principal.exe é apresentado um erro “Expressão não é um método”.

'----------------------------------------------------------------------

'Projeto Principal.exe

'----------------------------------------------------------------------

Imports Biblioteca

Imports Biblioteca.Utils

Imports System.Windows.Forms

Public Class Principal

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

        fValidaCPF(TextBox1.Text)

    End Sub

End Class







'----------------------------------------------------------------------

'Projeto Biblioteca.dll

'Valida CPF

'----------------------------------------------------------------------

Public Function FValidaCPF(ByVal CPF As String) As Boolean

    Dim i, x, n1, n2 As Integer

    CPF = CPF.Trim

    For i = 0 To dadosArray.Length - 1

        If CPF.Length <> 14 Or dadosArray(i).Equals(CPF) Then

            Return False

        End If

    Next

    'remove a maskara

    'If Len(CPF) > 11 Then

    CPF = CPF.Substring(0, 3) + CPF.Substring(4, 3) + CPF.Substring(8, 3) + CPF.Substring(12)

    'End If

    For x = 0 To 1

        n1 = 0

        For i = 0 To 8 + x

            n1 = n1 + Val(CPF.Substring(i, 1)) * (10 + x - i)

        Next

        n2 = 11 - (n1 - (Int(n1 / 11) * 11))

        If n2 = 10 Or n2 = 11 Then n2 = 0

        If n2 <> Val(CPF.Substring(9 + x, 1)) Then

            MsgBox("O CPF informado não é válido. Verifique se digitou corretamente.", _

                   MsgBoxStyle.Information, "GA .Net Consultoria")

            Return False

        End If

    Next



    MsgBox("O CPF informado é válido.", _

           MsgBoxStyle.Information, "GA .Net Consultoria")



    Return True

End Function
  • 4 weeks later...
Posted

Boa noite,

o teu método pertence à classe. Para o usares tens de criares uma instância da classe

Imports Biblioteca

Module Module1
    Sub Main()
        Dim u As Utils = New Utils()
        u.FValidaCPF("teste")
    End Sub
End Module

Ou então, defines o método como Shared

Public Class Utils
    Public Shared Function FValidaCPF(ByVal CPF As String) As Boolean
        ' --
    End Function
End Class

 e já podes chamar diretamente

Imports Biblioteca.Utils

Module Module1
    Sub Main()
        FValidaCPF("teste")
    End Sub
End Module

Espero que ajude

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.