Jump to content

[VB.net 05] Funções


Recommended Posts

boas estou com um problema no seguinte código :

  Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Dim linha, nfich, res As String

        nfich = TextBox1.Text + ".txt"

        FileOpen(1, nfich, OpenMode.Input)
        res = ""
        Do While Not EOF(1)
            linha = LineInput(1)
            res = res & vbCrLf & linha
        TextBox2.Text = res
        textbox3.Text = contapal(TextBox2.Text)

    End Sub

este código é o que chama a função contapal() [que deve estar incorrecto, mas pronto.]

Agora, a função propriamente dita :

Module funcoes
    Function contapal(ByVal x As String) As Integer

        Dim l, i As Integer
        Dim esp As Integer

        l = Len(x) : esp = 0
        For i = 0 To l
            If Mid(x, i, 1) = " " Then esp += 1
        Return esp + 1
    End Function

End Module

em anexo envio o programa completo para verem como está organizado/estruturado.

Desde já obrigado,


Link to comment
Share on other sites

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.