neon_yt Posted January 10, 2016 at 09:14 PM Report Share #591786 Posted January 10, 2016 at 09:14 PM Olá, eu estou a fazer um jogo e preciso de transformar, por exemplo, 90 em 5, 80 em 4, 60 em 3, etc. Como posso fazê-lo? Link to comment Share on other sites More sharing options...
He B TeMy Posted January 10, 2016 at 09:15 PM Report Share #591787 Posted January 10, 2016 at 09:15 PM Precisas de transformar o quê? Podes ser mais específico. Link to comment Share on other sites More sharing options...
ribeiro55 Posted January 11, 2016 at 11:16 AM Report Share #591806 Posted January 11, 2016 at 11:16 AM A pergunta é tão vaga, que até posso dar-me ao luxo de responder assim: 90/18 = 5 80/20 = 4 60/20 = 3 Tenta ser um pouco mais explícito, pois só tu sabes o teu contexto 😁 Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips" Link to comment Share on other sites More sharing options...
neon_yt Posted January 11, 2016 at 05:11 PM Author Report Share #591821 Posted January 11, 2016 at 05:11 PM A pergunta é tão vaga, que até posso dar-me ao luxo de responder assim: 90/18 = 5 80/20 = 4 60/20 = 3 Tenta ser um pouco mais explícito, pois só tu sabes o teu contexto 😁 Eu quero classificar com um de 0 a 19, com dois de 21 a 49, com três de 50 a 69, com quatro de 70 a 89 e com cinco de 90 a 100, ou substituir os números que eu escrevi por extenso com texto, com, por exemplo, o um "Mau", o dois "Nada de importante", o três "Normal", o quatro "Acima da média" e o cinco "Viral". Já tentei usar o If, mas não funciona. Já apaguei o código, não o peçam =P. Link to comment Share on other sites More sharing options...
Retsu9 Posted January 11, 2016 at 05:30 PM Report Share #591822 Posted January 11, 2016 at 05:30 PM e um if nao da porque? if ..else ou select case é o que tens de utilizar Link to comment Share on other sites More sharing options...
He B TeMy Posted January 11, 2016 at 05:31 PM Report Share #591823 Posted January 11, 2016 at 05:31 PM Podes usar um select case... Dim number As Integer = 20 Select Case number Case < 20 MessageBox.Show("Menor que 20") Case < 40 MessageBox.Show("Menor que 40") End Select Ou podes fazer: Case 1 to 19 'etc Link to comment Share on other sites More sharing options...
ribeiro55 Posted January 11, 2016 at 05:34 PM Report Share #591824 Posted January 11, 2016 at 05:34 PM Se o If "não deu" é porque não o fizeste correctamente 🙂 Deixo-te 3 alternativas para que possas analisar. Private Function Classificar(valor As Integer, Optional numeros As Boolean = False) As String Select Case valor Case 90 To 100 : Return IIf(numeros, 5, "Viral") Case 70 To 89 : Return IIf(numeros, 4, "Acima da Média") Case 50 To 69 : Return IIf(numeros, 3, "Normal") Case 21 To 49 : Return IIf(numeros, 2, "Nada de Importante") Case 0 To 19 : Return IIf(numeros, 1, "Mau") Case Else : Return IIf(numeros, 0, "Não faço ideia") End Select End Function Private Function Classificar2(valor As Integer, Optional numeros As Boolean = False) As String If valor >= 90 And valor <= 100 Then Return IIf(numeros, 5, "Viral") If valor >= 70 And valor <= 89 Then Return IIf(numeros, 4, "Acima da Média") If valor >= 50 And valor <= 69 Then Return IIf(numeros, 3, "Normal") If valor >= 21 And valor <= 49 Then Return IIf(numeros, 2, "Nada de Importante") If valor >= 0 And valor <= 19 Then Return IIf(numeros, 1, "Mau") Return IIf(numeros, 0, "Não faço ideia") End Function Private Function Classificar3(valor As Integer, Optional numeros As Boolean = False) As String If valor >= 90 And valor <= 100 Then Return IIf(numeros, 5, "Viral") ElseIf valor >= 70 And valor <= 89 Then Return IIf(numeros, 4, "Acima da Média") ElseIf valor >= 50 And valor <= 69 Then Return IIf(numeros, 3, "Normal") ElseIf valor >= 21 And valor <= 49 Then Return IIf(numeros, 2, "Nada de Importante") ElseIf valor >= 0 And valor <= 19 Then Return IIf(numeros, 1, "Mau") Else Return IIf(numeros, 0, "Não faço ideia") End If End Function A primeira é a mais elegante, no universo Visual Basic. Sérgio Ribeiro "Great coders aren't born. They're compiled and released""Expert coders do not need a keyboard. They just throw magnets at the RAM chips" Link to comment Share on other sites More sharing options...
neon_yt Posted January 11, 2016 at 05:36 PM Author Report Share #591825 Posted January 11, 2016 at 05:36 PM Obrigado =) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now