Escolar Documentos
Profissional Documentos
Cultura Documentos
String 1Bytes
Integer 2Bytes
Long 4Bytes
Double - 8Bytes
Funes de Converso
Cint(string) Inteiro
Val(string) - Long (mais usada)
Cdbl(string) Double
Cdate(string) Data
3o Programa Multiplicador
Private Sub Command1_Click()
v1 = Val(Text1(0).Text) 'variavel = conversor(objeto.propriedade)'
v2 = Val(Text1(1).Text)
Label2.Caption = v1 * v2 'objeto.propr recebe operao'
End Sub
Operadores
= atribuio , + , - , * , / , ^ , mod (resto da diviso)
and , or , not
< , <= , > , >= , = , <> (diferente)
Condies
If <condio> Then
<comandos>
ElseIf <condio> Then
<comandos>
Else
<comandos>
End If
Teste If
Private Sub CommandButton1_Click()
v = CInt(TextBox1.Text)
r = v Mod 2
If r = 0 Then
Label2.Caption = "O nmero par"
Else
Label2.Caption = "O nmero mpar"
End If
End Sub
4o Programa Calculadora
Private Sub Command1_Click()
v1 = Val(Text1(0).Text) 'variavel = conversor(objeto.propriedade)'
v2 = Val(Text1(1).Text)
Label2.Caption = v1 + v2 'objeto.propr recebe operao'
End Sub
Private Sub Command2_Click()
v1 = Val(Text1(0).Text)
v2 = Val(Text1(1).Text)
Label2.Caption = v1 - v2
End Sub
With txtTeste
txtTeste.Visible = True
txtTeste.Text = Everton
txtTeste.FontName = Arial
txtTeste.FontSize = 20
.Visible = True
.Text = Everton
.FontName = Arial
.FontSize = 20
Ende With
Teste With
Private Sub CommandButton1_Click()
With Label1
.ForeColor = &H0&
.Caption = "Ol Mundo"
.Font = "Arial"
.ForeColor = &HFF&
End With
End Sub
Repetio ou Laos
Do
<comandos>
Loop While <condio>
Do
<comandos>
Loop Until <condio>
Case 14
.Caption = "14 - Amarelo Claro"
Case Else
.Caption = "15 - Branco Brilhante"
End Select
End With
End Sub
Private Sub Command1_Click()
cor = cor - 1
If cor < 0 Then
cor = 15
End If
mudacor
End Sub
Private Sub Command2_Click()
cor = cor + 1
If cor > 15 Then
cor = 0
End If
mudacor
End Sub
Private Sub Form_Load()
cor = 0
End Sub
6o Programa Fatorial
Public num As Double, fat As Double, resp As Integer
Private Sub Command1_Click()
num = Val(Text1.Text)
If num < 0 Then
Beep
Label3.Caption = "ERRO"
ElseIf num = 0 Or num = 1 Then
Label3.Caption = "1"
Else
fat = 1
Do
fat = fat * num
num = num - 1
Loop While num > 0
End If
Label3.Caption = fat
* resp = MsgBox("Deseja continuar?", 4, "Continuar?")
If resp = 7 Then
End
End If
End Sub
Caixa de Mensagens
MsgBox <mensagem> , <valor-botes> , <ttulo da caixa>
Valor
0
1
2
3
4
5
Descrio
OK
OK , Cancelar
Abortar, Repetir, Ignorar
Sim, No, Cancelar
Sim, No
Repetir , Cancelar
Descrio
OK
Cancelar
Abortar
Repetir
Ignorar
Sim
No
ImputBox
VARIAVEL-STRING = InputBox (<mensagem>,<caixa>,<val. se nd digitado>)
8o Programa InputBox
Public V As String
Sub Macro1()
'
' Macro1 Macro
'
' Atalho do teclado: Ctrl+i
V = InputBox("Digite um Valor", "VALOR")
If V = "" Then Exit Sub
* Worksheets(1).Cells(1, 1).Value = V
End Sub
Clulas (ex)
Worksheets(1).Range("S4").Value = 1
Worksheets(1).Cells(4, 19).Value = 1
Worksheets(1).Range("S4").Formula = "=SUM(A1:A5)"
Worksheets(1).Cells(4, 19).Formula = "=SUM(A1:A5)"
9o Funes
Public a, b, c, x1, x2, delta As Long
Sub eq2o_grau()
'
' eq2o_grau Macro
'
' Atalho do teclado: Ctrl+r
'
Selection.ClearContents
Range("A3").Select
Selection.ClearContents
Range("B3").Select
Selection.ClearContents
Range("C3").Select
Selection.ClearContents
Range("D3").Select
Selection.ClearContents
Range("E3").Select
Selection.ClearContents
a = InputBox("Digite o valor do termo A")
If a = "" Then End
a = Val(a)
Worksheets(1).Cells(3, 1).Value = a