***** Programmes Simples En VB Pour Word *****
Sub HelloWorld1()
Selection.TypeText ("Hello World...")
End Sub
Sub HelloWorld5()
Selection.TypeText ("Hello World....." & vbCrLf)
Selection.TypeText ("Hello World....." & vbCrLf)
Selection.TypeText ("Hello World....." & vbCrLf)
Selection.TypeText ("Hello World....." & vbCrLf)
Selection.TypeText ("Hello World....." & vbCrLf)
End Sub
Sub HelloWorld9()
Dim i
'----- LOOP
For i = 1 To 9
Selection.TypeText ("Hello World........." & vbCrLf)
Next
End Sub
Sub Write2x2()
Selection.TypeText (2 + 2)
End Sub
Sub WriteCalc()
Dim R
Dim C, A
R = 10
C = 2 * 3.14159 * R
A = 3.14159 * R * R
Selection.TypeText ("Radius=" & R & vbCrLf)
Selection.TypeText ("Circumference=" & C & vbCrLf)
Selection.TypeText ("Area=" & A & vbCrLf)
End Sub
Sub WriteMsg()
Dim MyMsg
MyMsg = "- Nice weather, isn't it ?" & vbCrLf _
& "- Yes ""nice"" weather." & vbCrLf
Selection.TypeText (MyMsg)
End Sub
Sub Chr20_FF()
Dim i
Selection.TypeText ("***** CHARS: ")
'----- LOOP
For i = 32 To 255
Selection.TypeText (Chr(i))
Next
End Sub
Sub PrimeNb()
Dim IsPrimeArray(1000)
Dim i
Dim j, jMax
Selection.TypeText ("***** PRIME NUMBERS: ")
'----- LOOP 1 , On each number
For i = 1 To 1000
'----- Could be a prime number
IsPrimeArray(i) = True
'----- LOOP 2 , Search a divisor
j = 2
jMax = i \ 2 '--- Int div
While IsPrimeArray(i) And (j <= jMax)
'----- "j" can divide "i" ?
If (i Mod j) = 0 Then
IsPrimeArray(i) = False
End If
j = j + 1
Wend
'----- Display only prime numbers
If IsPrimeArray(i) = True Then
Selection.TypeText (i & " ")
End If
Next i
'
' [<-- i -->]
' [<-- j -->]
' .#.....................#.........................#
' | | |
' 2 i div 2 1000
'
End Sub