| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Thursday, June 19, 2008
Oracle Profiles
Using Resource User Profiles
Bạn có thể dùng profile để giới hạn tài nguyên của hệ thống, database mà user sử dụng và quản lý password. Nếu không có profile nào được tạo trong database, thì database sẽ dùng default profile – chỉ định tài nguyên không giới hạn (unlimited resource) cho tất cả các user.
Resource | Description |
SESSION_PER_USER | Số session đồng thời của 1 user |
CPU_PER_SESSION | Thời gian CPU mà session có thể dùng (100s) |
CPU_PER_CALL | Thời gian CPU mà 1 thao tác (parse, execute, hoặc fetch) có thể dùng |
CONNECT_TIME | Thời gian session có thể connect đến database (phút) |
IDLE_TIME | Thời gian session ở trạng thái idle sau khi connect đến database |
LOGICAL_READS_PER_SESSION | Số database block có thể đọc trong 1 session |
LOGICAL_READS_PER_CALL | Số database block có thể đọc trong 1 thao tác (parse, execute, fetch) |
PRIVATE_SGA | Dung lượng session có thể cấp phát trong Shared Pool (đối với Shared Server) |
FAILED_LOGIN_ATTEMPTS | Số lần login fail liên tiếp => account bị lock |
PASSWORD_LIFE_TIME | Số ngày dùng password trước khi password bị expire |
PASSWORD_REUSE_TIME | Số ngày phải trải qua để có thể dùng lại password |
PASSWORD_REUSE_MAX | Số lần password bị thay đổi trước khi có thể dùng lại |
PASSWORD_LOCK_TIME | Số ngày account bị lock nếu login fail vượt quá FAILED_LOGIN_ATTEMPTS |
PASSWORD_GRACE_TIME | Số ngày password vẫn có thể được thay đổi khi đến ngày PASSWORD_LIFE_TIME |
PASSWORD_VERIFY_FUNCTION | Tên của hàm (function) của Oracle được dùng để đánh giá độ phức tạp của password. Hàm này có thể được chỉnh sửa. |
First things first, the resouce_limit parameter must be set to TRUE. You can either set it in the init.ora or via ALTER SYSTEM.
Next, you create the profile and assign limits to it. Read the descriptions carefully, though, some of the resource parameters may sound self-explanatory, but aren't. For example, you would think SESSIONS_PER_USER would mean the number of times a particular user can login. In fact, it's the number of concurrent sessions that can run at one time.
SQL> create profile really_small limit
2 sessions_per_user 1
3 cpu_per_session 100
4 cpu_per_call 100
5 connect_time 5
6 /
Profile created.
Then you assign the profile to a particular user:
SQL> alter user jh profile really_small;
User altered.
Just for kicks, you can check that your profile is assigned to your user.
SQL> select username, profile from dba_users where username = 'JH';
USERNAME PROFILE
------------ ---------------
JH REALLY_SMALL
SQL> select resource_name, resource_type, limit
2 from dba_profiles
3 where profile = 'REALLY_SMALL';
RESOURCE_NAME RESOURCE LIMIT
-------------------------------- -------- ------------------
COMPOSITE_LIMIT KERNEL DEFAULT
SESSIONS_PER_USER KERNEL 1
CPU_PER_SESSION KERNEL 100
CPU_PER_CALL KERNEL 100
LOGICAL_READS_PER_SESSION KERNEL DEFAULT
LOGICAL_READS_PER_CALL KERNEL DEFAULT
IDLE_TIME KERNEL DEFAULT
CONNECT_TIME KERNEL 5
PRIVATE_SGA KERNEL DEFAULT
FAILED_LOGIN_ATTEMPTS PASSWORD DEFAULT
PASSWORD_LIFE_TIME PASSWORD DEFAULT
PASSWORD_REUSE_TIME PASSWORD DEFAULT
PASSWORD_REUSE_MAX PASSWORD DEFAULT
PASSWORD_VERIFY_FUNCTION PASSWORD DEFAULT
PASSWORD_LOCK_TIME PASSWORD DEFAULT
PASSWORD_GRACE_TIME PASSWORD DEFAULT
16 rows selected.
Tuesday, June 10, 2008
Crontab - Quick reference
____________
You can execute crontab if your name appears in the file /usr/lib/cron/cron.allow. If that file does not exist, you can use
crontab if your name does not appear in the file /usr/lib/cron/cron.deny.
If only cron.deny exists and is empty, all users can use crontab. If neither file exists, only the root user can use crontab. The allow/deny files consist of one user name per line.
2. Crontab Commands
__________
export EDITOR=vi ;to specify a editor to open crontab file.
crontab -e Edit your crontab file, or create one if it doesn't already exist.
crontab -l Display your crontab file.
crontab -r Remove your crontab file.
crontab -v Display the last time you edited your crontab file. (This option is only available on a few systems.)
3. Crontab file
___________
Crontab syntax :-
A crontab file has five fields for specifying day , date and time followed by the command to be run at that interval.
* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)
* in the value field above means all legal values as in braces for that column.
The value column can have a * or a list of elements separated by commas. An element is either a number in the ranges shown above or two numbers in the range separated by a hyphen (meaning an inclusive range).
Note: The specification of days can be made in two fields: month day and weekday. If both are specified in an entry, they are cumulative meaning both of the entries will get executed .
4. Crontab Example
_______
A line in crontab file like below removes the tmp files from /home/someuser/tmp each day at 6:30 PM.
30 18 * * * rm /home/someuser/tmp/*
Changing the parameter values as below will cause this command to run at different time schedule below :
min | hour | day/month | month | day/week | Execution time |
30 | 0 | 1 | 1,6,12 | * | -- 00:30 Hrs on 1st of Jan, June & Dec. |
: | |||||
0 | 20 | * | 10 | 1-5 | --8.00 PM every weekday (Mon-Fri) only in Oct. |
: | |||||
0 | 0 | 1,10,15 | * | * | -- midnight on 1st ,10th & 15th of month |
: | |||||
5,10 | 0 | 10 | * | 1 | -- At 12.05,12.10 every Monday & on 10th of every month |
: |
Note : If you inadvertently enter the crontab command with no argument(s), do not attempt to get out with Control-d. This removes all entries in your crontab file. Instead, exit with Control-c.
5. Crontab Environment
___________
cron invokes the command from the user's HOME directory with the shell, (/usr/bin/sh).
cron supplies a default environment for every shell, defining:
HOME=user's-home-directory
LOGNAME=user's-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh
Users who desire to have their .profile executed must explicitly do so in the crontab entry or in a script called by the entry.
6. Disable Email
____________
By default cron jobs sends a email to the user account executing the cronjob. If this is not needed put the following command At the end of the cron job line .
>/dev/null 2>&1
7. Generate log file
________________
To collect the cron execution execution log in a file :
30 18 * * * rm /home/someuser/tmp/* > /home/someuser/cronlogs/clean_tmp_dir.log
8. Next Steps
This article covered a significant aspect of system administration of setting up cronjobs . Unix administration involves lots of different tasks and some of these tasks are covered in this website but still there are many areas not covered here .
Following books available for online buying from Amazon.com . You should have following two books in your bookshelf for ready reference if you are involved in Unix system administration .
Cơ bản về Cron trên Unix/Linux
Trên Unix/Linux bạn thường nghe đến cái tên Cron...
Vậy Cron là cái gì nhỉ? Trước hết Cron là một chương trình. Do sự tiện dụng và cần thiết của nó lên đã được nâng lên làm deadmon.
Vậy nó có chức năng gì ? Chắc bạn không lạ gì chương trình Scheduling Agent chuyên được dùng để thực hiện các tác vụ theo định kỳ đã được lên kế hoạch và thời gian trước. Thì Cron sẽ thay bạn thực hiện tính năng này trong Unix/Linux.
Thường thì cron được cài đặt mặc định và chạy trên các hệ thống Unix/Linux rồi. Nếu hệ thống của bạn chưa được cài đặt Cron thì bạn có thể Dowload nó từ: http://www.freshmeat.net/ Và cần cho khởi động nó như một deadmon trên hệ thống của bạn bằng lệnh:
root@localhost#: crond start
Bây giờ chúng ta cùng bắt tay cấu hình cho Cron. Để sử dụng Cron bạn phải, bạn cần một file cấu hình dạng text, còn gọi là file "lịch" (để lên lịch chạy của các chương trình). Ngoài ra bạn sẽ phải dùng thêm chương trình crontab (có sau khi cài cron) để đăng ký file lịch với hệ thống, xem thông tin về file lịch của user...
Bạn có thể đặt tên cho file lịch là jobs.txt hoặc schedule.txt hay tên gì đó cũng được, miễn nó là file text. Cấu trúc của file lịch như sau:
* File lịch gồm có 2 phần, phần đầu là phần cấu hình, có dạng TÊN_BIẾN = GIÁ TRỊ
* Phần thứ hai là lịch trình chạy của các chương trình
* Các chú thích bắt đầu bằng ký tự #
(bạn xem thêm thông tin qua lệnh man crontab)
Phần cấu hình của file lịch (có thể) như sau:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=abc
HOME=/ # run-parts
Dòng đầu tiên cho biết là bạn dùng shell bash để chạy các chương trình, dòng thứ 2 thiết lập đường dẫn cho các chương trình (tuỳ chọn), dòng thứ 3 biểu thị rằng output của các chương trình sẽ được gởi tới email cho user abc (tuỳ chọn, mặc định sẽ gởi email tới cho user chủ sở hữu của file lịch, nếu bạn không muốn gởi email thì bạn đặt MAILTO=""), dòng thứ 4 sẽ báo cho cron biết rằng phải cd về thư mục gốc trước khi thi hành lệnh.
Phần lịch trình chạy các chương trình có dạng như sau:
phút giờ ngày tháng thứ chương_trình_cần_chạy
Phút có giá trị từ 0 đến 59 hoặc là *
Giờ có giá trị từ 0 đến 23 hoặc *
Ngày có giá trị 1 đến 31 hoặc *
Tháng có giá trị từ 1 đến 12 hoặc *
Thứ có giá trị 0 (Chủ nhật), 1 (thứ hai)...6 (thứ 7) hoặc *
Ví dụ bạn muốn chạy chương trình abc vào lúc 2g1' sáng ngày 12 tháng 5 (bất kể thứ) thì lịch chạy như sau:
1 2 12 5 * abc
(* biểu thị everything, tức là bất kể thứ nào)
Nếu bạn muốn chạy 1 file tên def trong thư mục /bin vào 15g chiều vào chủ nhật (bất kể ngày tháng) thì lịch chạy như sau:
0 15 * * 0 /bin/def
và nếu bạn muốn chạy 1 chương trình tên xyz vào mỗi giờ trong ngày (bắt đầu ở phút thứ 8 của giờ đó) thì:
8 * * * * xyz
còn nếu bạn muốn chương trình cứ 3 ngày chạy 1 lần vào đúng 4g10' sáng? thì đây:
10 4 */3 * * tên_chương_trình
(*/3 biểu thị cứ cách 3 đơn bị thì thực hiện 2 lần, ở ví dụ trên 1 đơn vị là 1 ngày nên 3 ngày chương trình sẽ chạy 1 lần)
Nếu bạn muốn chạy chương trình ngày 3 lần (cứ 8 tiếng đồng hồ thì chạy 1 lần) vào lúc 13 phút hàng tuần (trừ Thứ 7 và Chủ nhật) thì:
13 */8 * * 1-5 tên_chương_trình
(1-5 biểu thị trong giới hạn từ 1 đến 5 thì thực hiện, ở ví dụ trên 1 là thứ 2, 5 là thứ 6, 1-5 biểu thị từ thứ 2 đến thứ 6)
Và cuối cùng, sau khi soạn thảo và lưu lai file lịch ở dạng text. Bạn đăng ký file lịch với hệ thống qua lệnh crontab:
crontab schedules.txt
Mỗi user trên hệ thống linux của bạn có thể tạo 1 file lịch khác nhau và đăng ký với hệ thống, 2 user khác nhau sẽ có file lịch khác nhau và không sợ bị ghi dè lên nhau.
lệnh crontab -l sẽ liệt kê file lịch mà bạn đã đăng ký với hệ thống. Nếu bạn đăng ký nhiều file lịch, thì file sau sẽ ghi đè lên file trước.
lệnh crontab -r sẽ rút tên file lịch mà bạn đã đăng ký trên hệ thống ra (không đăng ký lịch nữa).
12 bước là chủ oracle
In this database creation I used below features:
1. OMF (Oracle Managed File) for datafiles, redolog files & controlfiles
2. FRA (Flash Recovery Area) for Archivelog or backup files
3. ASM (Automatic Storage Mgmt) for Volume manager
1. Create Required Directories
E:\>mkdir e:\oracle\ORA11G
NOTE: above directory is for TRACE FOLDER.
And for ASM I already created DGRP2 group for database.
2. Set Enviourment Variable (ORACLE_HOME,ORACLE_SID,PATH)
E:\>set ORACLE_HOME=c:\app\m.taj\product\11.1.0\db_1
E:\>set PATH=c:\app\m.taj\product\11.1.0\db_1\bin
E:\>set ORACLE_SID=ora11g
3. Choose a Database Administrator Authentication Method
Two authentication method we can use.
1. Password Authentication method
For Password Authentication method we need to create PASSWORD file through ORAPWD utility.
2. OS Authentication method
For OS Authentication method OS user must be member of OS DBA Group.
And SQLNET.AUTHENTICATION_SERVICES= (NTS) is set in SQLNET.ORA file
NOTE: Here I used OS authentication Method.
3. Creating INIT.ORA parameter file
Set minimum required parameter in INIT.ora file.
Open NOTEPAD file and set below parameters
db_name = 'ORA11G'
#Database name.
db_create_file_dest='+DGRP2'
#OMF configuration for Datafile,controlfile
db_create_online_log_dest_1='+DGRP2'
#OMF configuration for redolog file
db_recovery_file_dest='+DGRP2'
db_recovery_file_dest_size=10G
#FRA (FLASH RECOVERY AREA configuration)
diagnostic_dest='E:\ORACLE\ORA11G'
#It is new feature with 11g for trace files (bdump,udump,cdump or many others
#folder created in "DIAG" folder inside "e:\oracle\ora11g" folder.
Save it in Temporary folder.
4. Create an Instance
E:\>oradim -NEW -SID ora11g -STARTMODE auto
Instance created.
5. Connect to an Instance
E:\>sqlplus /nolog
SQL*Plus: Release 11.1.0.6.0 - Production on Thu May 1 18:04:30 2008
Copyright (c) 1982, 2007, Oracle. All rights reserved.
SQL> conn / as sysdba
Connected to an idle instance.
6. Create Server Parameter file (SPFILE)
SQL> create SPFILE from PFILE='c:\temp\init.TXT';
File created.
7. Start the Instance
SQL> startup nomount
ORACLE instance started.
Total System Global Area 150667264 bytes
Fixed Size 1331740 bytes
Variable Size 92278244 bytes
Database Buffers 50331648 bytes
Redo Buffers 6725632 bytes
8. Create Database
SQL> create database ORA11G;
Database created.
9. Create Temporary and Additional Tablespace
SQL> create temporary tablespace TEMP TEMPFILE '+DGRP2' size 5m;
Tablespace created.
SQL> create tablespace USERDATA DATAFILE '+DGRP2' size 5m;
Tablespace created.
SQL> alter database default temporary tablespace TEMP;
Database altered.
SQL> alter database default tablespace USERDATA;
Database altered.
10. Run Scripts to build data dictionary views
SQL> @%ORACLE_HOME%/rdbms/admin/catalog.sql
SQL> @%ORACLE_HOME%/rdbms/admin/catproc.sql
SQL> @%ORACLE_HOME%/sqlplus/admin/pupbld.sql
11. Change Database Mode from NO-ARCHIVELOG to ARCHIVELOG.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 150667264 bytes
Fixed Size 1331740 bytes
Variable Size 92278244 bytes
Database Buffers 50331648 bytes
Redo Buffers 6725632 bytes
Database mounted.
SQL> alter database ARCHIVELOG;
Database altered.
SQL> alter database OPEN;
Database altered.
NOTE: It is recommended to run database in ARCHIVELOG MODE
12. Check all database files how is look in ASM :)
SQL> select NAME from v$datafile
2 union all
3 select NAME from v$controlfile
4 union all
5 select MEMBER from v$logfile;
NAME
--------------------------------------------------
+DGRP2/ora11g/datafile/system.281.653595347
+DGRP2/ora11g/datafile/sysaux.280.653595371
+DGRP2/ora11g/datafile/sys_undots.279.653595393
+DGRP2/ora11g/datafile/userdata.273.653595537
+DGRP2/ora11g/controlfile/current.285.653595303
+DGRP2/ora11g/onlinelog/group_1.283.653595305
+DGRP2/ora11g/onlinelog/group_2.282.653595325
7 rows selected.
Monday, June 9, 2008
Oracle Database 10g (10.1.0.2) Installation On Red Hat Enterprise Linux 4 (RHEL4)
- X Window System
- GNOME Desktop Environment
- Editors
- Graphical Internet
- Text-based Internet
- Server Configuration Tools
- Development Tools
- Administration Tools
- System Tools
Download Software
Download the following software:Unpack Files
First unzip the files:Next unpack the contents of the files:gunzip ship.db.cpio.gz
You should now have a single directory (Disk1) containing installation files.cpio -idmv <>
Hosts File
The /etc/hosts file must contain a fully qualified name for the server:Set Kernel Parameters
Add the following lines to the /etc/sysctl.conf file:Run the following command to change the current kernel parameters:kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
# semaphores: semmsl, semmns, semopm, semmni
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
Add the following lines to the /etc/security/limits.conf file:/sbin/sysctl -p
Add the following line to the /etc/pam.d/login file, if it does not already exist:* soft nproc 2047
* hard nproc 16384
* soft nofile 1024
* hard nofile 65536
Note by Kent Anderson: In the event that pam_limits.so cannot set privilidged limit settings see Bug 115442.session required /lib/security/pam_limits.so
Disable secure linux by editing the /etc/selinux/config file, making sure the SELINUX flag is set as follows:
Alternatively, this alteration can be done using the GUI tool (Applications > System Settings > Security Level). Click on the SELinux tab and disable the feature.SELINUX=disabled
Setup
Install the following packages:Create the new groups and users:# From RedHat AS4 Disk 2
cd /media/cdrom/RedHat/RPMS
rpm -Uvh setarch-1*
rpm -Uvh compat-libstdc++-33-3*
# From RedHat AS4 Disk 3
cd /media/cdrom/RedHat/RPMS
rpm -Uvh openmotif-2*
rpm -Uvh compat-db-4*
# From RedHat AS4 Disk 4
cd /media/cdrom/RedHat/RPMS
rpm -Uvh compat-gcc-32-3*
rpm -Uvh compat-gcc-32-c++-3*
Create the directories in which the Oracle software will be installed:groupadd oinstall
groupadd dba
groupadd oper
useradd -g oinstall -G dba oracle
passwd oracle
Login as root and issue the following command:mkdir -p /u01/app/oracle/product/10.1.0/db_1
chown -R oracle.oinstall /u01
Edit the /etc/redhat-release file replacing the current release information (Red Hat Enterprise Linux AS release 4 (Nahant)) with the following:xhost +
Login as the oracle user and add the following lines at the end of the .bash_profile file:redhat-3
# Oracle Settings
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/10.1.0/db_1; export ORACLE_HOME
ORACLE_SID=TSH1; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH
#LD_ASSUME_KERNEL=2.4.1; export LD_ASSUME_KERNEL
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
Installation
Log into the oracle user. If you are using X emulation then set the DISPLAY environmental variable:Start the Oracle Universal Installer (OUI) by issuing the following command in the Disk1 directory:DISPLAY=:0.0; export DISPLAY
During the installation enter the appropriate ORACLE_HOME and name then continue with a "software only" installation../runInstaller
Post Installation
Create a new instance using the DBCA. If you get the "ORA-27125: unable to create shared memory segment" error when using the DBCA issue the following commands as the oracle user then try again:I didn't encounter the previous issue myself, so hopefully you won't either.cd $ORACLE_HOME/bin
mv oracle oracle.bin
cat >oracle <<"EOF" #!/bin/bash export DISABLE_HUGETLBFS=1 exec $ORACLE_HOME/bin/oracle.bin $@ EOF chmod +x oracle
Edit the /etc/redhat-release file restoring the original release information:
Finally edit the /etc/oratab file setting the restart flag for each instance to 'Y':Red Hat Enterprise Linux AS release 4 (Nahant)
For more information see:TSH1:/u01/app/oracle/product/10.1.0/db_1:Y
Hope this helps. Regards Tim...
Tuesday, June 3, 2008
Làm sao để ghi tiền bằng chữ trong Excel

Giải pháp:
Bước 1. Mở tập tin cần chuyển >> Nhấn tổ hợp phím Alt + F11 để mở trình soạn thảo VBA của Excell
Bước 2. Nhấp chuột phải lên VBA Project >> Insert >> Module >> và dán đoạn mã bên dưới vào cửa sổ của Module mới chèn

Dim Temp
Dim Dollars, Cents
Dim DecimalPlace, Count
ReDim Place(9) As String
Place(2) = " Nghin "
Place(3) = " Trieu "
Place(4) = " Ty "
Place(5) = " Ngan ty "
' Convert MyNumber to a string, trimming extra spaces.
MyNumber = Trim(Str(MyNumber))
' Find decimal place.
DecimalPlace = InStr(MyNumber, ".")
' If we find decimal place...
If DecimalPlace > 0 Then
' Convert cents
Temp = Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)
Cents = ConvertTens(Temp)
' Strip off cents from remainder to convert.
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If
Count = 1
Do While MyNumber <> ""
' Convert last 3 digits of MyNumber to English dollars.
Temp = ConvertHundreds(Right(MyNumber, 3))
If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
If Len(MyNumber) > 3 Then
' Remove last 3 converted digits from MyNumber.
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If
Count = Count + 1
Loop
' Clean up dollars.
Select Case Dollars
Case ""
Dollars = "khong Nghin"
Case "One"
Dollars = "Mot Nghin"
Case Else
Dollars = Dollars & " Nghin"
End Select
' Clean up cents.
Select Case Cents
Case ""
Cents = " va khong Dong"
Case "One"
Cents = " va mot Dong"
Case Else
Cents = " va " & Cents & " Dong"
End Select
ConvertCurrencyToVietnamese = Dollars & Cents
End Function
Private Function ConvertHundreds(ByVal MyNumber)
Dim Result As String
' Exit if there is nothing to convert.
If Val(MyNumber) = 0 Then Exit Function
' Append leading zeros to number.
MyNumber = Right("000" & MyNumber, 3)
' Do we have a hundreds place digit to convert?
If Left(MyNumber, 1) <> "0" Then
Result = ConvertDigit(Left(MyNumber, 1)) & " Tram "
End If
' Do we have a tens place digit to convert?
If Mid(MyNumber, 2, 1) <> "0" Then
Result = Result & ConvertTens(Mid(MyNumber, 2))
Else
' If not, then convert the ones place digit.
Result = Result & ConvertDigit(Mid(MyNumber, 3))
End If
ConvertHundreds = Trim(Result)
End Function
Private Function ConvertTens(ByVal MyTens)
Dim Result As String
' Is value between 10 and 19?
If Val(Left(MyTens, 1)) = 1 Then
Select Case Val(MyTens)
Case 10: Result = "Muoi"
Case 11: Result = "Muoi mot"
Case 12: Result = "Muoi hai"
Case 13: Result = "Muoi ba"
Case 14: Result = "Muoi bon"
Case 15: Result = "Muoi lam"
Case 16: Result = "Moi sau"
Case 17: Result = "Muoi bay"
Case 18: Result = "Muoi tam"
Case 19: Result = "Muoi chin"
Case Else
End Select
Else
' .. otherwise it's between 20 and 99.
Select Case Val(Left(MyTens, 1))
Case 2: Result = "Hai muoi "
Case 3: Result = "Ba muoi "
Case 4: Result = "Bon muoi "
Case 5: Result = "Nam muoi "
Case 6: Result = "Sau muoi "
Case 7: Result = "Bay muoi "
Case 8: Result = "Tam muoi "
Case 9: Result = "Chin muoi "
Case Else
End Select
' Convert ones place digit.
Result = Result & ConvertDigit(Right(MyTens, 1))
End If
ConvertTens = Result
End Function
Private Function ConvertDigit(ByVal MyDigit)
Select Case Val(MyDigit)
Case 1: ConvertDigit = "Mot"
Case 2: ConvertDigit = "Hai"
Case 3: ConvertDigit = "Ba"
Case 4: ConvertDigit = "Bon"
Case 5: ConvertDigit = "Nam"
Case 6: ConvertDigit = "Sau"
Case 7: ConvertDigit = "Bay"
Case 8: ConvertDigit = "Tam"
Case 9: ConvertDigit = "Chin"
Case Else: ConvertDigit = ""
End Select
End Function
Bước 3. Nhấn phím Alt + F11 một lần nữa và nhấn Ctrl + S để save lại toàn bộ tài liệu.
Bước 4. Đến đây, bạn có thể sử dụng công thức =ConvertCurrencyToVietnamese
Ví dụ: B3 có giá trị là: 123456 thì kết quả =ConvertCurrencyToVietnamese
![]() |