Results 1 to 5 of 5

Thread: Help with this...

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2008
    Posts
    9

    Help with this...

    I need help with 2 things, I want enter 20 numbers in inputbox and say what is the greater and lesser in the end with msgbox.

    and the other is, enter a number in a inputbox and calculate his factorial.

    Thanks a i am lern vb now. English too ;p

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Help with this...

    Welcome to the forums.

    What code do you have so far?

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2008
    Posts
    9

    Re: Help with this...

    Thanks.

    Factorial i did this.

    Code:
    '// Declaração e Inicialização de Variáveis
        Dim valor As Integer = 0
        Dim resposta As String
        Dim temp As Double
        Dim fatorial As Double
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Do
                '// Entrada de Dados
                valor = InputBox("Entre com o valor a ser calculado:")
                If valor < 0 Then
                    MsgBox("Entre apenas com numeros positivos")
                End If
    
                '// Processamento de Dados
                If valor = 0 Then
                    fatorial = 1
                Else
                    temp = valor
                    Do Until valor <= 1
                        valor = valor - 1
                        temp = temp * valor
                    Loop
                    fatorial = temp
                End If
    
                '// Saida dos Dados
                MsgBox("O fatorial é " & fatorial)
    
    
    '// Perguntar se Quer Continuar
                resposta = InputBox("Deseja Continuar S/N?:")
                resposta = resposta.ToUpper
            Loop Until (resposta.Equals("N"))
            Close()
        End Sub
    End Class
    ------------------------------------------------------------------------
    I can´t find a way to do if I enter a negative value he restart the program.

    The other i don´t have a clue yet...

    ]

  4. #4
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Help with this...

    To get the factorial of a number you could just do:

    vb Code:
    1. Private Sub Form_Load()
    2.     MsgBox Factorial(5)
    3. End Sub
    4.  
    5. Private Function Factorial(ByVal Number As Long) As Long
    6.     If Number = 1 Then
    7.         Factorial = 1
    8.     Else
    9.         Factorial = Number * Factorial(Number - 1)
    10.     End If
    11. End Function

  5. #5

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width