λ³μ μ¬μ©
λ€μμ LibreOffice Basicμ λ³μ μ¬μ©μ λν κΈ°λ³Έμ μΈ μ¬νμ μ€λͺ ν κ²μ λλ€.
λ³μμ λͺ λͺ κ·μΉ
λ³μ μ΄λ¦μ μ΅λ 255μλ‘ κ΅¬μ±ν μ μμ΅λλ€. λ³μ μ΄λ¦μ 첫 λ²μ§Έ λ¬Έμλ λ°λμ A-Z λλ a-z μ¬μ΄μ λ¬Έμμ¬μΌ ν©λλ€. λ³μ μ΄λ¦μ μ«μλ μ¬μ©ν μ μμ§λ§, λ¬Έμ₯ λΆνΈλ νΉμ λ¬Έμλ μ¬μ©ν μ μμ΅λλ€. λ¨, λ°μ€("_")μ μ¬μ©ν μ μμ΅λλ€. LibreOffice Basicμμ λ³μ νμΈμλ λ/μλ¬Έμλ₯Ό ꡬλΆνμ§ μμ΅λλ€. λ³μ μ΄λ¦μ 곡백μ μ¬μ©ν κ²½μ°μλ ν΄λΉ λ³μλ₯Ό κ°κ΄νΈλ‘ λ¬Άμ΄μΌ ν©λλ€.
λ³μ μλ³μ μ:
MyNumber=5 'Correct'
MyNumber5=15 'Correct'
MyNumber_5=20 'Correct'
My Number=20 'Not valid, variable with space must be enclosed in square brackets'
[My Number]=12 'Correct'
DΓ©jΓ Vu=25 'Not valid, special characters are not allowed'
5MyNumber=12 'Not valid, variable may not begin with a number'
Number,Mine=12 'Not valid, punctuation marks are not allowed'
λ³μ μ μΈ
LibreOffice Basicμμλ λ³μλ₯Ό λͺ μμ μΌλ‘ μ μΈν νμκ° μμ΅λλ€. λ³μ μ μΈμ Dim λ¬Έμ μ¬μ©νμ¬ μνν μ μμ΅λλ€. μΌνλ‘ μ΄λ¦μ ꡬλΆνλ©΄ λ κ° μ΄μμ λ³μλ₯Ό λμμ μ μΈν μ μμ΅λλ€. λ³μ μ νμ μ§μ νλ €λ©΄ μ΄λ¦ λ€μμ μ ν μ μΈ κΈ°νΈλ₯Ό μ¬μ©νκ±°λ ν΄λΉ ν€μλλ₯Ό μ¬μ©ν©λλ€.
λ³μ μ μΈμ μ:
Dim a$ 'Declares the variable "a" as a String'
Dim a As String 'Declares the variable "a" as a String'
Dim a$, b As Integer 'Declares one variable as a String and one as an Integer'
Dim c As Boolean 'Declares c as a Boolean variable that can be TRUE or FALSE'
λ³μλ₯Ό νΉμ μ νμΌλ‘ μ μΈν λ€μμλ ν΄λΉ λ³μλ₯Ό λμΌν μ΄λ¦μ κ°μ§κ³ λ€λ₯Έ μ νμΌλ‘ μ μΈν μ μμ΅λλ€.
λ³μ μ μΈ κ°μ
λ³μ μ μΈμ κ°μ νλ €λ©΄ λ€μ λͺ λ Ήμ μ¬μ©ν©λλ€.
Option Explicit
Option Explicit λ¬Έμ λͺ¨λμμ 첫 λ²μ§Έ SUB μμ 첫 μ€μ μμ΄μΌ ν©λλ€. μΌλ°μ μΌλ‘ λ°°μ΄λ§ λͺ μμ μΌλ‘ μ μΈν΄μΌ ν©λλ€. λ€λ₯Έ λͺ¨λ λ³μλ μ ν μ μΈ λ¬Έμμ λ°λΌ μ μΈλκ±°λ μ΄ λ¬Έμκ° μμ κ²½μ° κΈ°λ³Έ μ νμΈ Singleλ‘ μ μΈλ©λλ€.
λ³μ μ ν
LibreOffice Basicμ λ€μκ³Ό κ°μ λ€ κ°μ§ λ³μ ν΄λμ€λ₯Ό μ§μν©λλ€.
-
Numeric λ³μλ μ«μ κ°μ ν¬ν¨ν μ μμ΅λλ€. μΌλΆ λ³μλ ν¬κ±°λ μμ μ«μλ₯Ό μ μ₯νλ λ° μ¬μ©λλ©° λ€λ₯Έ λ³μλ λΆλ μμμ λλ λΆμμ μ¬μ©λ©λλ€.
-
String λ³μλ λ¬Έμμ΄μ ν¬ν¨ν©λλ€.
-
Boolean λ³μλ TRUE λλ FALSE κ°μ ν¬ν¨ν©λλ€.
-
Object λ³μλ λ¬Έμ λ΄μ ν μ΄λΈ λ° λ¬Έμ κ°μ λ€μν μ νμ κ°μ²΄λ₯Ό μ μ₯ν μ μμ΅λλ€.
Integer λ³μ
Integer λ³μλ -32768μμ 32767κΉμ§μ λ²μλ₯Ό κ°μ§λλ€. Integer λ³μμ λΆλ μμμ κ°μ ν λΉν κ²½μ° μμμ μ΄ν μλ¦Ώμκ° λ€μ μ μλ‘ λ°μ¬λ¦Όλ©λλ€. Integer λ³μλ νλ‘μμ μμ μ μνκ² κ³μ°λκΈ° λλ¬Έμ 루νμ μΉ΄μ΄ν° λ³μμ μ ν©ν©λλ€. Integer λ³μμλ λ¨μ§ 2λ°μ΄νΈμ λ©λͺ¨λ¦¬λ§ νμνλ©° μ ν μ μΈ λ¬Έμλ "%"μ λλ€.
Dim Variable%
Dim Variable As Integer
Long Integer λ³μ
Long Integer λ³μλ -2147483648μμ 2147483647κΉμ§μ λ²μλ₯Ό κ°μ§λλ€. Long Integer λ³μμ λΆλ μμμ κ°μ ν λΉν κ²½μ° μμμ μ΄ν μλ¦Ώμκ° λ€μ μ μλ‘ λ°μ¬λ¦Όλ©λλ€. Long Integer λ³μλ νλ‘μμ μμ μ μνκ² κ³μ°λκΈ° λλ¬Έμ ν° κ°μ λν 루νμ μΉ΄μ΄ν° λ³μμ μ ν©ν©λλ€. Long Integer λ³μμλ 4λ°μ΄νΈμ λ©λͺ¨λ¦¬κ° νμνλ©° μ ν μ μΈ λ¬Έμλ "&"μ λλ€.
Dim Variable&
Dim Variable As Long
decimal λ³μ
decimal λ³μλ μμ, μμ λλ 0 κ°μ μ·¨ν μ μμ΅λλ€. μμμ μ΄ν μλ¦Ώμλ μ΅λ 29κ°λ‘ μ νλ©λλ€.
μμ μμ λνκΈ°(+) λλ λΉΌκΈ°(-) κΈ°νΈλ₯Ό μ¬μ©ν μ μμ΅λλ€(곡백 μ 무 κ΄κ³ μμ).
integer λ³μμ μμκ° ν λΉλλ©΄ LibreOffice Basicμ΄ μ«μλ₯Ό μ¬λ¦Ό λλ λ²λ¦Όν©λλ€.
Single λ³μ
Single variables can take positive or negative values ranging from 3.402823 x 10E38 to 1.401298 x 10E-45. Single variables are floating-point variables, in which the decimal precision decreases as the non-decimal part of the number increases. Single variables are suitable for mathematical calculations of average precision. Calculations require more time than for Integer variables, but are faster than calculations with Double variables. A Single variable requires 4 bytes of memory. The type-declaration character is "!".
Dim Variable!
Dim Variable As Single
Double λ³μ
Double variables can take positive or negative values ranging from 1.79769313486232 x 10E308 to 4.94065645841247 x 10E-324. Double variables are floating-point variables, in which the decimal precision decreases as the non-decimal part of the number increases. Double variables are suitable for precise calculations. Calculations require more time than for Single variables. A Double variable requires 8 bytes of memory. The type-declaration character is "#".
Dim Variable#
Dim Variable As Double
Currency λ³μ
Currency λ³μλ λ΄λΆμ μΌλ‘ 64λΉνΈ μ«μ(8λ°μ΄νΈ)λ‘ μ μ₯λλ©° μμμ μ μλ¦Ώμκ° 15μ리μ΄κ³ μμμ μ΄ν μλ¦Ώμκ° 4μλ¦¬μΈ κ³ μ μμμ μ«μλ‘ νμλ©λλ€. κ° λ²μλ -922337203685477.5808μμ +922337203685477.5807κΉμ§μ λλ€. Currency λ³μλ μ νλκ° λμ ν΅ν κ° κ³μ°μ μ¬μ©λλ©° μ ν μ μΈ λ¬Έμλ "@"μ λλ€.
Dim Variable@
Dim Variable As Currency
Literals for integers
Numbers can be encoded using octal and hexadecimal forms.
xi = &o13 ' 8 + 3
ci = &h65 ' 6*16 + 5
MAX_Integer = &o77777 ' 32767 = &h7FFF
MIN_Integer = &o100000 ' -32768 = &h8000
MAX_Long = &h7fffffff ' 2147483647 = &o17777777777
MIN_Long = &h80000000 ' -2147483648 = &o20000000000
String λ³μ
String λ³μλ μ΅λ 65,535μμ λ¬Έμμ΄μ ν¬ν¨ν μ μμ΅λλ€. κ° λ¬Έμλ ν΄λΉ μ λμ½λ κ°μΌλ‘ μ μ₯λ©λλ€. String λ³μλ νλ‘κ·Έλ¨ λ΄μ λ¬Έμ μμ κ³Ό μ΅λ 64KBμ μΈμν μ μλ λ¬Έμμ μμ μ μ₯μ μ ν©ν©λλ€. String λ³μλ₯Ό μ μ₯νλ λ° νμν λ©λͺ¨λ¦¬λ λ³μμ λ¬Έμ μμ λ°λΌ λ¬λΌμ§λλ€. μ ν μ μΈ λ¬Έμλ "$"μ λλ€.
Dim Variable$
Dim Variable As String
Boolean λ³μ
Boolean λ³μλ TRUE κ° λλ FALSE κ° μ€ νλλ§ μ μ₯ν©λλ€. μ«μ 0μ FALSE, λ€λ₯Έ λͺ¨λ κ°μ TRUEλ‘ νκ°λ©λλ€.
Dim Variable As Boolean
Date λ³μ
Date λ³μλ λ΄λΆ μμμΌλ‘ μ μ₯λ λ μ§ λ° μκ° κ°λ§ ν¬ν¨ν μ μμ΅λλ€. Dateserial, Datevalue, Timeserial λλ Timevalueλ₯Ό μ¬μ©νμ¬ Date λ³μμ ν λΉλ κ°μ μλμΌλ‘ λ΄λΆ μμμΌλ‘ λ³νλ©λλ€. Date λ³μλ Day, Month, Year λλ Hour, Minute, Second ν¨μλ₯Ό μ¬μ©νμ¬ μΌλ° μ«μλ‘ λ³νλ©λλ€. λ΄λΆ μμμ λ μ«μμ μ°¨λ₯Ό κ³μ°νμ¬ λ μ§/μκ° κ°μ λΉκ΅ν μ μκ² ν©λλ€. Date λ³μλ ν€μλ Dateλ‘λ§ μ μΈν μ μμ΅λλ€.
Dim Variable As Date
μ΄κΈ° λ³μ κ°
μ΄ λ³μλ μ μΈλμλ§μ "Null" κ°μΌλ‘ μλ μ€μ λ©λλ€. λ€μ κ·μΉμ μ£Όμν©λλ€.
Numeric λ³μλ μ μΈλμλ§μ κ° "0"μ΄ μλμΌλ‘ ν λΉλ©λλ€.
Date λ³μμλ κ° 0μ΄ λ΄λΆμ μΌλ‘ ν λΉλ©λλ€. μ΄κ²μ Day, Month, Year λλ Hour, Minute, Second ν¨μλ₯Ό μ¬μ©νμ¬ κ°μ "0"μΌλ‘ λ³ννλ κ²κ³Ό κ°μ΅λλ€.
String λ³μλ μ μΈλ λ λΉ λ¬Έμμ΄("")μ΄ ν λΉλ©λλ€.
λ°°μ΄
LibreOffice Basicμ μ§μ ν λ³μ μ νμ μν΄ μ§μ λλ μΌμ°¨μ λλ λ€μ°¨μ λ°°μ΄μ μΈμν©λλ€. λ°°μ΄μ νλ‘κ·Έλ¨μμ λͺ©λ‘κ³Ό ν μ΄λΈμ νΈμ§νλ λ° μ ν©ν©λλ€. λ°°μ΄μ κ°λ³ μμλ μ«μ μμΈμ ν΅ν΄ μ§μ ν μ μμ΅λλ€.
λ°°μ΄μ λ°λμ Dim λ¬Έμ μ¬μ©νμ¬ μ μΈν΄μΌ ν©λλ€. λ€μμ λ°°μ΄μ μμΈ λ²μλ₯Ό μ§μ νλ λͺ κ°μ§ λ°©λ²μ λλ€.
Dim Text$(20) '21 elements numbered from 0 to 20'
Dim Text$(5,4) '30 elements (a matrix of 6 x 5 elements)'
Dim Text$(5 To 25) '21 elements numbered from 5 to 25'
Dim Text$(-15 To 5) '21 elements (including 0), numbered from -15 to 5'
μμΈ λ²μλ μμμ μμλ₯Ό λͺ¨λ ν¬ν¨ν μ μμ΅λλ€.
μμ
μμλ κ³ μ κ°μ κ°μ§λλ€. μμλ λ€μκ³Ό κ°μ΄ νλ‘κ·Έλ¨μμ ν λ²λ§ μ§μ λλ©° λμ€μ λ€μ μ§μ ν μ μμ΅λλ€.
Const ConstName=Expression