A apresentação está carregando. Por favor, espere

A apresentação está carregando. Por favor, espere

Trabalho Computacional Mecânica de Fluidos Ambiental Guillaume Riflet, Pedro Pina, Luís Fernandes.

Apresentações semelhantes


Apresentação em tema: "Trabalho Computacional Mecânica de Fluidos Ambiental Guillaume Riflet, Pedro Pina, Luís Fernandes."— Transcrição da apresentação:

1 Trabalho Computacional Mecânica de Fluidos Ambiental Guillaume Riflet, Pedro Pina, Luís Fernandes

2 Objectivos Programming 101 MS-excel macros Visual Basic for Applications (VBA) 101 https://fenix.ist.utl.pt/homepage/ist146730/mecan ica-dos-fluidos-ambiental

3 Interesse para engenheiros do ambiente Utilização mais avançadas de ferramentas de folhas de cálculo. Em muitas circunstâncias, o excel (ou derivado) é a melhor ferramenta realizar tarefas. Qualquer empresa do sector público ou privado usa uma ferramenta de folha de cálculo. Todas permitem utilizar macros. 90% permitem programar em VBA.

4 Linguagens de programação Visual Basic Fortran C/C++ C# Matlab Java (pôr linguagem de programação favorita)

5 Diferenças entre VB e VBA VBVBA CompiladoInterpretado IDE próprio (VS2Kx)IDE embebido no Office Bibliotecas e classes externas importadas Bibliotecas e classes nativas de Office

6 Exemplo I Sheet1 Dica: Alt+F11

7 Exemplo I: glossário Source-code, código-fonte Compiler/interpreter, compilador/interpretador Subroutine, Subrotina String, Sequência de caracteres Propriedade dum objecto Excel macro, Macro de excel

8 Exemplo II Sheet1

9 Exemplo III Sheet1

10 Exemplo III: glossário Argument, Argumento Argument passing, Passagem de argumento Argument type, Tipo de argumento

11 Exemplo IV Sheet1

12 Exemplo IV: glossário Function, Função Function type, Tipo de função

13 Exemplo V Sheet1

14 Exemplo V: glossário Variable, Variável Variable type, Tipo de variável

15 Variáveis Dim Nome As Tipo Dim Aluno as String Dim Idade as Integer Dim Nota as Single Declaração Implícita/Explícita Function SafeSqr(num) TempVal = Abs(num) SafeSqr = Sqr(TempVal) End Function Function SafeSqr(num) TempVal = Abs(num) SafeSqr = Sqr(TemVal) End Function Option Explicit

16 Tipos de variáveis I Data typeRange Byte0 to 255 BooleanTrue or False Integer-32,768 to 32,767 Long (long integer) -2,147,483,648 to 2,147,483,647 Single (single-precision floating-point) -3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values Double (double-precision floating-point) -1.79769313486232E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values Currency (scaled integer) -922,337,203,685,477.5808 to 922,337,203,685,477.5807

17 Tipos de variáveis II Decimal+/-79,228,162,514,264,337,593,543,950,335 with no decimal point; +/-7.9228162514264337593543950335 with 28 places to the right of the decimal; DateJanuary 1, 100 to December 31, 9999 ObjectAny Object reference String (variable-length) 0 to approximately 2 billion String (fixed-length) 1 to approximately 65,400 Variant (with numbers) Any numeric value up to the range of a Double Variant (with characters) Same range as for variable-length String User-defined (using Type) The range of each element is the same as the range of its data type.

18 Constantes Public Const conMaxPlanets As Integer = 9 Const conReleaseDate = #1/1/95# Const conPi = 3.14159265358979 Constantes são valores que aparecem várias vezes no programa e que ao contrário das variáveis não alteram o seu valor.

19 Projecto Modulo SubRotina Private Nome as Tipo Public Nome as Tipo Dim Nome as Tipo

20 Sub-procedures & functions Sub Rotinas Sub teste (File As String) Open (File) ReadFirstLine (File)... End Sub Call teste (A) Funções Function Hypotenuse (A As Integer, B As _ Integer) As Double Hypotenuse = Sqr(A ^ 2 + B ^ 2) End Function strX = Hypotenuse(Width, Height)

21 Arrays Dim Conta(6) As Integer i = 0 i = 1 i = 2 i = 3 i = 4 i = 5 Conta(0) = 12 ; Conta(3) = 21; Conta(5) = 3 i = 0 i = 1 i = 2 i = 3 i = 4 i = 5 12002103 Dim Teste(3,3) As Boolean Teste(0,1) = True ; Teste (2,0) = True True False True

22 Exemplo VI Sheet1

23 Estruturas de loop I Do While... Loop Do While line < 10 Call ReadLine(line) line = line+1 Loop For...Next For i = 0 To 10 For j = 0 to 10 Matriz(i,j) = cos(x) Next Next For Each...Next For Each File In folder.File() Call ReadFile (File) Next File

24 Exemplo VII Sheet1

25 Configurações regionais Atenção no que toca à linguagem nativa do office. SEN (português) ou SIN (inglês). Atenção às definições de separadores de casas decimais (3.14 ou 3,14) e de formatos de data (13/05/1980 ou 1980-05-13 ou...).


Carregar ppt "Trabalho Computacional Mecânica de Fluidos Ambiental Guillaume Riflet, Pedro Pina, Luís Fernandes."

Apresentações semelhantes


Anúncios Google