sexta-feira, 29 de janeiro de 2010

Ficha 21



Const PI = 3.14

Private Function VCilindro(x As Single, z As Single) As Single
VCilindro = PI * x ^ 2 * z
End Function
Private Function ACirculo(x As Single) As Single
ACirculo = PI * x ^ 2
End Function
Private Function VCubo(x As Single) As Single
VCubo = x ^ 3
End Function
Private Function AEsfera(x As Single) As Single
AEsfera = 4 * PI * x ^ 2
End Function
Private Function VEsfera(x As Single) As Single
VEsfera = 4 / 3 * PI * x ^ 3
End Function
Private Function AQuadrado(x As Single) As Single
AQuadrado = x * x
End Function
Private Function PQuadrado(x As Single) As Single
PQuadrado = x * x * x * x
End Function
Private Function ARectangulo(x As Single, z As Single) As Single
ARectangulo = x * z
End Function
Private Function PRectangulo(x As Single, z As Single) As Single
PRectangulo = 2 * (x + z)
End Function
Private Function ATriangulo(x As Single, z As Single) As Single
ATriangulo = x * z / 2
End Function
Private Function PTriangulo(x As Single) As Single
PTriangulo = x + x + x
End Function

Private Sub Autor_Click()

MsgBox "Programa protagonizado por João Florindo", vbOKOnly, "Exercício - Autor"

End Sub

Private Sub Cilindro_Click()

Dim r As Single, h As Single, v As Single

Do
r = Val(InputBox("Digite o valor do raio", "Volume do Cilindro"))
Loop While r <= 0
Do
h = Val(InputBox("Digite o valor da altura", "Volume do Cilindro"))
Loop While h <= 0

v = VCilindro(r, h)

MsgBox "O volume do cilindro é " & v & "m2", 64, " Volume do Cilindro"


End Sub

Private Sub Circulo_Click()

Dim r As Single, a As Single

Do
r = Val(InputBox("Digite o valor do raio", "Área do Círculo"))
Loop While r <= 0

a = ACirculo(r)

MsgBox "A área do círculo é " & a & "m2", 64, " Área do Círculo"

End Sub

Private Sub Cubo_Click()

Dim v As Single, a As Single

Do
a = Val(InputBox("Digite o valor da aresta", "Volume do Cubo"))
Loop While a <= 0

v = VCubo(a)

MsgBox "O volume do cubo é " & v & "m2", 64, " Volume do Cubo"

End Sub

Private Sub Esfera_Click()

Dim a As Single, r As Single

Do
r = Val(InputBox("Digite o valor da esfera", "Área da Esfera"))
Loop While r <= 0

a = AEsfera(r)

MsgBox "A área da esfera é " & a & "m2", 64, " Área da Esfera"

End Sub

Private Sub Esfera2_Click()

Dim v As Single, r As Single

Do
r = Val(InputBox("Digite o valor da esfera", "Volume da Esfera"))
Loop While r <= 0

v = VEsfera(r)

MsgBox "O volume da esfera é " & v & "m2", 64, " Volume da Esfera"

End Sub

Private Sub Quadrado_click()

Dim a As Single, l As Single

Do
l = Val(InputBox("Digite o valor do lado", "Área do Quadrado"))
Loop While l <= 0

a = AQuadrado(l)

MsgBox "A área do quadrado é " & a & "m2", 64, " Área do Quadrado"

End Sub

Private Sub Quadrado2_Click()

Dim p As Single, l As Single

Do
l = Val(InputBox("Digite o valor dos lados", "Perímetro do Quadrado"))
Loop While l <= 0

p = PQuadrado(l)

MsgBox "O perímetro do quadrado é " & p & "m2", 64, " Perímetro do Quadrado"

End Sub

Private Sub Rectangulo_Click()

Dim a As Single, b As Single, h As Single

Do
b = Val(InputBox("Digite o valor da base", "Área do Rectângulo"))
Loop While b <= 0

Do
h = Val(InputBox("Digite o valor da altura", "Área do Rectângulo"))
Loop While h <= 0

a = ARectangulo(b, h)

MsgBox "A área do rectângulo é " & a & "m2", 64, " Área do Rectângulo"

End Sub

Private Sub Rectangulo2_Click()

Dim p As Single, b As Single, h As Single

Do
b = Val(InputBox("Digite o valor da base", "Perímetro do Rectângulo"))
Loop While b <= 0

Do
h = Val(InputBox("Digite o valor da altura", "Perímetro do Rectângulo"))
Loop While h <= 0

p = PRectangulo(b, h)

MsgBox "O perímetro do rectângulo é " & p & "m2", 64, " Perímetro do Rectângulo"

End Sub

Private Sub Sair_Click()

If MsgBox("Deseja mesmo sair?", vbYesNo + vbQuestion, " Exercício - Confirmação") = vbYes Then End

End Sub

Private Sub Triangulo_Click()

Dim a As Single, b As Single, h As Single

Do
b = Val(InputBox("Digite o valor da base", "Área do Triângulo"))
Loop While b <= 0

Do
h = Val(InputBox("Digite o valor da altura", "Área do Triângulo"))
Loop While h <= 0

a = ATriangulo(b, h)

MsgBox "A área do triângulo é " & a & "m2", 64, " Área do Triângulo"

End Sub

Private Sub Triangulo2_Click()

Dim p As Single, l As Single

Do
l = Val(InputBox("Digite o valor dos lados", "Perímetro do Triângulo"))
Loop While l <= 0

p = PTriangulo(l)

MsgBox "O perímetro do triângulo é " & p & "m2", 64, " Perímetro do Triângulo"

End Sub

quinta-feira, 28 de janeiro de 2010

Trabalho 2







Form1:

Function FU_Delay(Quanto As Double, PermiteDoEvents As Integer) As Double

Dim inicio As Double
Dim Check As Double
Dim Contador As Double
Contador = Timer
inicio = Timer
Do Until Check >= (inicio + Quanto)
Check = Timer
If PermiteDoEvents Then DoEvents
Loop

FU_Delay = (Timer - Contador)
End Function

Private Sub Form_Load()
Form1.Show
If res = Sair Then
r = FU_Delay(3, True)
Form1.Hide
Form2.Show
End If
End Sub


Form2:

Dim movie As Integer, cont As Integer, total As Single, result As Single, mt As Single
Dim mat As Single
Private Sub Calcular_Click()

If Cliente.Text = "" And Val(Filmes.Text) = 0 Then
'Só poderá continuar o programa se os campos do Número do Cliente e Total de filmes a alugar estiverem preenchidos
x = MsgBox("Preencha os campos 'Número do Cliente' e 'Total de filmes a alugar' ", vbOKOnly + vbExclamation, "Campo Obrigatório")
ElseIf Cliente.Text = "" Then
'Terá que ser preenchido o campo Número Cliente para o programa continuar
x = MsgBox("Preencha o campo 'Número do Cliente' ", vbOKOnly + vbExclamation, "Campo Obrigatório")
ElseIf Val(Filmes.Text) = 0 Then
'Terá que ser preenchido o campo Total de filmes a alugar para o programa continuar
x = MsgBox("Preencha o campo 'Total de filmes a alugar' ", vbOKOnly + vbExclamation, "Campo Obrigatório")
Else

'Cont é onde começa a ser contados os clientes
cont = cont + 1

'movie é o número de filmes
movie = Val(Filmes.Text)

'É feita a multiplicação do preço dos filmes que o cliente deseja comprar
total_sem.Caption = Filmes * 2.5 & " €"

'Preço dos filmes sem desconto
mat = Round(Filmes * 2.5, 2)

'Desconto dos filmes
desconto.Caption = mat * 0.1 & " €"

'Preço dos filmes com desconto
total_com.Caption = mat - (mat * 0.1) & " €"


mt = Round(mat - (mat * 0.1), 2)


result = mt


total = Round(total + result, 2)

Total_clientes.Caption = cont
l1 = cont


Total_recebido.Caption = total & " €"
l2 = total

Limpar.Enabled = True
Imprimir.Enabled = True
Calcular.Enabled = False

End If

End Sub

Private Sub Form_Load()

cont = 0
total = 0

End Sub

Private Sub Imprimir_Click()
'Será imprimido os clientes e o total facturado numa nova form
Form3.Show
Load Form3

End Sub

Private Sub Limpar_Click()
'Neste botão a função Limpar serve para limpar os valores do cliente , o número do cliente e o total de filmes a alugar
Cliente.Text = ""
Filmes.Text = ""
total_sem.Caption = ""
desconto.Caption = ""
total_com.Caption = ""

Calcular.Enabled = True
Limpar.Enabled = False
Imprimir.Enabled = False

End Sub

Private Sub Sair_Click()
'Aqui o programa será terminado
x = MsgBox("Deseja mesmo sair?", vbYesNo + vbQuestion, "Vídeo Clube")

If x = vbYes Then
End
Else

End If

End Sub


Form3:

Private Sub Form_Load()
'Será carregado os totais calculados na form2
Label1.Caption = l1
Label2.Caption = l2 & " €"

End Sub

Private Sub Label5_Click()
'O programa voltará de novo a form2 para novos resultados
Label1.Caption = ""
Label2.Caption = ""

Form3.Hide
Unload Form3
End Sub


Module:

Public l1 As Integer, l2 As Single

Trabalho 1







Form1:


Dim neve1 As Integer, neve2 As Integer, nevetotal1 As Integer, nevetotal2 As Integer
Dim mat(1 To 1, 1 To 2) As Integer, l As Integer, ll As Integer

Private Sub Calcular_Click()

If Nome.Text = "" And Val(CC.Text) = 0 Then
x = MsgBox("Preencha o campo 'Nome' e 'CC' ", vbOKOnly + vbExclamation, "Campo Obrigatório")
ElseIf Nome.Text = "" Then
x = MsgBox("Preencha o campo 'Nome' ", vbOKOnly + vbExclamation, "Campo Obrigatório")
ElseIf Val(CC.Text) = 0 Then
x = MsgBox("Preencha o campo 'CC' ", vbOKOnly + vbExclamation, "Campo Obrigatório")
Else

For l = 1 To 1

Picture1.Print "Nome do Cliente"
Picture1.Print Nome
Picture1.Print "Nº do Cartão de Cidadão"
Picture1.Print CC & Chr(13)

For ll = 1 To 2

neve1 = Val(snow1.Text)
neve2 = Val(snow2.Text)

snowtotal1.Caption = neve1 * 20 & " €"
mat(l, 1) = snowtotal1.Caption
snowtotal2.Caption = neve2 * 30 & " €"
mat(l, 2) = snowtotal2.Caption


Next ll
Next l

nevetotal1 = snowtotal1.Caption
nevetotal2 = snowtotal2.Caption
neveal1 = neveal1 + neve1
neveal2 = neveal2 + neve2
snowal1.Caption = neveal1

snowal2.Caption = neveal2

totalgeral.Caption = nevetotal1 + nevetotal2

totalalugueis.Caption = neveal1 + neveal2

alugueltotal = totalalugueis.Caption

End If

If Nome.Text = "" And Val(CC.Text) = 0 Then
Calcular.Enabled = True
ElseIf Nome.Text = "" Then
Calcular.Enabled = True
ElseIf Val(CC.Text) = 0 Then
Calcular.Enabled = True
Else
Calcular.Enabled = False
Imprimir.Enabled = True
Limpar.Enabled = True
LimparTudo.Enabled = True

End If

End Sub

Private Sub Limpar_Click()

Nome.Text = ""
CC.Text = ""
snow1.Text = ""
snow2.Text = ""
snowtotal1.Caption = ""
snowtotal2.Caption = ""
totalgeral.Caption = ""

Calcular.Enabled = True
Limpar.Enabled = False
Imprimir.Enabled = False

End Sub

Private Sub LimparTudo_Click()

Nome.Text = ""
CC.Text = ""
snow1.Text = ""
snow2.Text = ""
snowtotal1.Caption = ""
snowtotal2.Caption = ""
totalgeral.Caption = ""
neveal1 = 0
snowal1.Caption = ""
neveal2 = 0
snowal2.Caption = ""
alugueltotal = 0
totalalugueis.Caption = ""

Calcular.Enabled = True
Limpar.Enabled = False
LimparTudo.Enabled = False
Imprimir.Enabled = False

End Sub

Private Sub Imprimir_Click()

Calcular.Enabled = False
Limpar.Enabled = False
LimparTudo.Enabled = False
Imprimir.Enabled = False
Form2.Show

End Sub

Private Sub Sair_Click()

Picture1.Visible = False
Picture2.Visible = True
MsgBox "Obrigado pela sua visita!", vbOKOnly + vbInformation, "BOA QUEDA - Sair"

End

End Sub

Private Sub Timer1_Timer()

Label1.Caption = Time

End Sub

Form2:

Private Sub Form_Load()

Label1.Caption = neveal1
Label2.Caption = neveal2
Label3.Caption = alugueltotal

End Sub
Private Sub Label5_Click()

Form2.Hide

End Sub


Module:


Public neveal1 As Integer, neveal2 As Integer, alugueltotal As Integer

domingo, 24 de janeiro de 2010

Ficha 20



Private Sub Alegre_Click()

S_Alegre.Visible = True
S_Triste.Visible = False
C_Copas.Visible = False
C_Ouros.Visible = False
C_Paus.Visible = False
C_Espadas.Visible = False

End Sub

Private Sub Copas_Click()

S_Alegre.Visible = False
S_Triste.Visible = False
C_Copas.Visible = True
C_Ouros.Visible = False
C_Paus.Visible = False
C_Espadas.Visible = False

End Sub

Private Sub Espadas_Click()

S_Alegre.Visible = False
S_Triste.Visible = False
C_Copas.Visible = False
C_Ouros.Visible = False
C_Paus.Visible = False
C_Espadas.Visible = True

End Sub


Private Sub Limpar_Click()

S_Alegre.Visible = False
S_Triste.Visible = False
C_Copas.Visible = False
C_Ouros.Visible = False
C_Paus.Visible = False
C_Espadas.Visible = False

End Sub

Private Sub Ouros_Click()

S_Alegre.Visible = False
S_Triste.Visible = False
C_Copas.Visible = False
C_Ouros.Visible = True
C_Paus.Visible = False
C_Espadas.Visible = False

End Sub

Private Sub Paus_Click()

S_Alegre.Visible = False
S_Triste.Visible = False
C_Copas.Visible = False
C_Ouros.Visible = False
C_Paus.Visible = True
C_Espadas.Visible = False

End Sub

Private Sub Sair_Click()

End

End Sub

Private Sub Triste_Click()

S_Alegre.Visible = False
S_Triste.Visible = True
C_Copas.Visible = False
C_Ouros.Visible = False
C_Paus.Visible = False
C_Espadas.Visible = False

End Sub

Ficha 19



Private Sub Command1_Click()

If Combo1 = "Classificação de triângulos" Then
Form2.Show
Form1.Hide
ElseIf Combo1 = "Classificação de circunferência" Then
Form3.Show
Form1.Hide
Else
x = MsgBox("Escolha uma Classificação..", vbOKOnly + vbInformation, "Form1")
End If

End Sub

Private Sub Command2_Click()

End

End Sub

Private Sub Form_Load()

Combo1.AddItem "Classificação de triângulos"
Combo1.AddItem "Classificação de circunferência"

End Sub

Private Sub Timer1_Timer()

Label1 = Time

End Sub




Private Sub cmd1_Click()

Dim a As Single, b As Single, c As Single, x As Single, y As Single, z As Single

x = Val(operA.Text)
y = Val(operB.Text)
z = Val(operC.Text)

If x > y And x > z Then
a = x
b = y
c = z
ElseIf y > x And y > z Then
a = y
b = x
c = z
ElseIf z > x And z > y Then
a = z
b = x
c = y
Else
a = x
b = y
c = z
End If


If a >= b + c Then
resultado.Caption = "Nenhum triângulo formado"
Image1.Visible = False
Image2.Visible = False
Image3.Visible = False
Image4.Visible = True

ElseIf a ^ 2 = b ^ 2 + c ^ 2 Then
resultado.Caption = "Triângulo retângulo"
Image1.Visible = True
Image2.Visible = False
Image3.Visible = False
Image4.Visible = False

ElseIf a ^ 2 > b ^ 2 + c ^ 2 Then
resultado.Caption = "Triângulo obtusângulo"
Image1.Visible = False
Image2.Visible = True
Image3.Visible = False
Image4.Visible = False

ElseIf a ^ 2 < b ^ 2 + c ^ 2 Then
resultado.Caption = "Triângulo acutângulo"
Image1.Visible = False
Image2.Visible = False
Image3.Visible = True
Image4.Visible = False

End If

End Sub

Private Sub cmd2_Click()

Form2.Hide
Form1.Show

End Sub

Private Sub cmd3_Click()

End

End Sub




Private Sub Command1_Click()

Dim pontox As Integer, pontoy As Integer

Picture1.Cls
Label1.Caption = ""

pontox = Val(InputBox("Intoduza coordenada X", "Introdução de dados"))

Picture1.Print Tab(4); "X=" & pontox
pontoy = Val(InputBox("Introduza coordenada Y", "Introdução de dados"))

Picture1.Print Tab(4); "Y=" & pontoy

If (x - a) ^ 2 + (y - b) ^ 2 Then

Label1.Caption = ("O ponto introduzido é interior à circunferência de centro")

ElseIf (x - a) ^ 2 + (y - b) ^ 2 > r ^ 2 Then
Label1.Caption = ("O ponto introduzido é exterior à circuferencia de centro")

ElseIf (x - a) ^ 2 + (y - b) ^ 2 = r ^ 2 Then
Label1.Caption = ("O ponto introduzido é fronteiro à circuferencia de centro")

Else

MsgBox "Pontos inválidos!", vbOKOnly + vbInformation, "Informação"

End If


End Sub

Private Sub Command2_Click()

Form3.Hide
Form1.Show

End Sub

Private Sub Command3_Click()

End

End Sub

quinta-feira, 7 de janeiro de 2010

Ficha 18-2






Dim matriz(1 To 4, 1 To 3)
Private Sub cmd1_Click()

Dim funcionário As Integer, mes As Integer, cont As Integer, contf As Integer

cont = 0
contf = 1
Picture1.Print Tab(16); "Meses"
For funcionario = 1 To 4
Picture1.Print "Funcionário " & contf & Chr(32); Chr(26);
contf = contf + 1
For mes = 1 To 3
matriz(funcionario, mes) = Val(InputBox("Introduza a " & mes & "º venda do " & funcionario & "º funcionário", "Audi"))
Picture1.Print matriz(funcionario, mes);
cont = cont + 1
If cont = 3 Then
Picture1.Print Chr(13)
cont = 0
End If
Next mes
Next funcionario

cmd1.Enabled = False
cmd2.Enabled = True

End Sub

Private Sub cmd2_Click()

Dim consulta As Integer, soma As Integer, mes As Integer

soma = 0

consulta = Val(InputBox("Qual o total de vendas do Funcionário que vai querer consultar ?" & Chr(13) & "Funcionário 1, 2, 3 ou 4?", "Audi"))

If consulta > 0 And consulta < 5 Then
For mes = 1 To 3
soma = soma + matriz(consulta, mes)
Next mes
Else
erro = MsgBox("O número que introduziu ''" & consulta & "'' não corresponde a nenhum Funcionário" & Chr(13) & Chr(13) & "Por favor tente novamente", vbInformation + vbOKOnly, "Informação")
End If

If consulta > 0 And consulta < 5 Then

Picture2.Print "Funcionário consultado " & Chr(26) & Chr(32) & consulta
Picture2.Print Chr(13); soma
cmd1.Enabled = False
cmd2.Enabled = False
cmd3.Enabled = True
Else
Picture2.Print Chr(13); " erro "
cmd1.Enabled = False
cmd2.Enabled = False
cmd3.Enabled = False
End If

End Sub

Private Sub cmd3_Click()

Dim indice As Integer, total As Integer, funcionario As Integer, contf2 As Integer

total = 0
contf2 = 1

indice = Val(InputBox("Qual o mes de vendas que vai querer consultar ?" & Chr(13) & "Mês 1, 2 ou 3?", "Audi"))

Picture3.Print "Mês " & Chr(26) & Chr(32) & indice & Chr(13)
If indice > 0 And indice < 4 Then
For funcionario = 1 To 4
total = 0
total = total + matriz(funcionario, indice)
Picture3.Print "Funcionário " & contf2
contf2 = contf2 + 1
Picture3.Print Tab(5); total & Chr(13)
Next funcionario
Else
erro = MsgBox("O número que introduziu ''" & indice & "'' não corresponde a nenhum Funcionário" & Chr(13) & Chr(13) & "Por favor tente novamente", vbInformation + vbOKOnly, "Informação")
Picture3.Print "erro"
End If

cmd1.Enabled = False
cmd2.Enabled = False
cmd3.Enabled = False

End Sub

Private Sub cmd4_Click()

Picture1.Cls
Picture2.Cls
Picture3.Cls
cmd1.Enabled = True
cmd2.Enabled = False

End Sub

Private Sub cmd5_Click()

End

End Sub

Ficha 18-1




Dim matriz(1 To 4, 1 To 3) As Integer

Private Sub Gerar_Click()

Dim linha As Integer, coluna As Integer, cont As Integer

Randomize

For linha = 1 To 4
For coluna = 1 To 3
matriz(linha, coluna) = Int(Rnd() * 100)
Picture1.Print matriz(linha, coluna);
cont = cont + 1
If cont = 3 Then
Picture1.Print Chr(13)
cont = 0
End If
Next coluna
Next linha

Somar.Enabled = True
Gerar.Enabled = False
Limpar.Enabled = True

End Sub

Private Sub Somar_Click()
Dim consulta As Integer, soma As Integer, linha As Integer

soma = 0

consulta = Val(InputBox("Qual a coluna que vai querer consultar ?" & Chr(13) & "Coluna 1, Coluna 2 ou Coluna 3?", "Coluna"))

If consulta > 0 And consulta < 4 Then
For linha = 1 To 4
soma = soma + matriz(linha, consulta)
Next linha
Else
erro = MsgBox("O número que introduziu ''" & consulta & "'' não é o correcto" & Chr(13) & Chr(13) & "Por favor tente novamente", vbInformation + vbOKOnly, "Informação")
End If

If consulta > 0 And consulta < 4 Then
Picture2.Print Chr(13); Tab(5); soma
Else
Picture2.Print Chr(13); Tab(5); " erro"
End If

Gerar.Enabled = False
Somar.Enabled = False

End Sub

Private Sub Limpar_Click()

Picture1.Cls
Picture2.Cls
Gerar.Enabled = True
Somar.Enabled = False
Limpar.Enabled = False

End Sub

Private Sub Sair_Click()

End

End Sub