λ³€μˆ˜ μ‚¬μš©

λ‹€μŒμ€ 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'
warning

λ³€μˆ˜λ₯Ό νŠΉμ • μœ ν˜•μœΌλ‘œ μ„ μ–Έν•œ λ‹€μŒμ—λŠ” ν•΄λ‹Ή λ³€μˆ˜λ₯Ό λ™μΌν•œ 이름을 가지고 λ‹€λ₯Έ μœ ν˜•μœΌλ‘œ μ„ μ–Έν•  수 μ—†μŠ΅λ‹ˆλ‹€.


When you declare multiple variables in a single line of code you need to specify the type of each variable. If the type of a variable is not explicitly specified, then Basic will assume that the variable is of the Variant type.


  ' Both variables "a" and "b" are of the Integer type
  Dim a As Integer, b As Integer
  ' Variable "c" is a Variant and "d" is an Integer
  Dim c, d As Integer
  ' A variable can also be explicitly declared as a Variant
  Dim e As Variant, f As Double
note

The Variant type is a special data type that can store any kind of value. To learn more, refer to the section The Variant type below.


λ³€μˆ˜ μ„ μ–Έ κ°•μ œ

λ³€μˆ˜ 선언을 κ°•μ œν•˜λ €λ©΄ λ‹€μŒ λͺ…령을 μ‚¬μš©ν•©λ‹ˆλ‹€.


Option Explicit

Option Explicit 문은 λͺ¨λ“ˆμ—μ„œ 첫 번째 SUB μ•žμ˜ 첫 쀄에 μžˆμ–΄μ•Ό ν•©λ‹ˆλ‹€. 일반적으둜 λ°°μ—΄λ§Œ λͺ…μ‹œμ μœΌλ‘œ μ„ μ–Έν•΄μ•Ό ν•©λ‹ˆλ‹€. λ‹€λ₯Έ λͺ¨λ“  λ³€μˆ˜λŠ” μœ ν˜• μ„ μ–Έ λ¬Έμžμ— 따라 μ„ μ–Έλ˜κ±°λ‚˜ 이 λ¬Έμžκ°€ 없을 경우 κΈ°λ³Έ μœ ν˜•μΈ Single둜 μ„ μ–Έλ©λ‹ˆλ‹€.

λ³€μˆ˜ μœ ν˜•

LibreOffice Basic은 λ‹€μŒκ³Ό 같은 λ„€ 가지 λ³€μˆ˜ 클래슀λ₯Ό μ§€μ›ν•©λ‹ˆλ‹€.

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 variables can hold character strings with up to 2,147,483,648 characters. Each character is stored as the corresponding Unicode value. String variables are suitable for word processing within programs and for temporary storage of any non-printable character up to a maximum length of 2 Gbytes. The memory required for storing string variables depends on the number of characters in the variable. The type-declaration character is "$".

tip

In BASIC String functions, the first character of the string has index 1.



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

Literals for Dates

Date literals allow to specify unambiguous date variables that are independent from the current language. Literals are enclosed between hash signs #. Possible formats are:


  zeroDay = #12/30/1899#
  dob = #2010-09-28#

The Variant type

Variables declared as Variant can handle any data type. This means that the actual data type is defined during runtime as a value is assigned to the variable.

There are three main ways to create a Variant variable, as shown below:


  Dim varA            ' The type is not specified, hence the variable is a Variant
  Dim varB as Variant ' The variable is explicitly declared as a Variant
  varC = "abc"        ' Previously undeclared variables are treated as Variants

The example below uses the TypeName function to show how the type of a Variant variable changes upon assignment.


  Dim myVar As Variant
  MsgBox TypeName(myVar) ' Empty
  myVar = "Hello!"
  MsgBox TypeName(myVar) ' String
  myVar = 10
  MsgBox TypeName(myVar) ' Integer
note

A Variant variable is initialized with the Empty special data type. You can use the IsEmpty function to test if a variable is an Empty Variant.


You can also use the keyword Any to declare a variable as a Variant. However, Any is deprecated and is available for backward compatibility.

warning

Arguments with type Variant or Any passed in function calls are not checked for their types.



  Dim myVar As Any ' Variable "myVar" is a Variant

초기 λ³€μˆ˜ κ°’

이 λ³€μˆ˜λŠ” μ„ μ–Έλ˜μžλ§ˆμž "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

Please support us!