2009年11月21日 星期六

Crontab 設定

使用 crontab -e command 編輯時需熟悉 ed 語法,但這個語法我想沒幾個人會吧,而且更換 Editor 還要改系統參數,不同版本的語法也不太一樣:

export EDITOR=vi

在網路上找到一個簡單的方法:

crontab -l > crontab.dat
vi crontab.dat
crontab crontab.dat

將 目前 crontab 的內容轉出,在修改完後在加入即可。

2009年7月19日 星期日

在巨集中呼叫外部巨集文字檔的方法

1.需將巨集安全性設定中的 [ 信任存取 Visual Basic 專案 ] 的項目打開, 如無開啟會出現 [ 執行期錯誤: 1004 ]的錯訊息。


2.建立一個巨集輸入下面代碼

'匯入 VBA 巨集的文字檔
Me.VBProject.VBComponents.Import Filename:="X:\XXXX\test.vbs"

'執行匯入巨集程式
Result = Application.Run("巨集名稱", "Arg#1","Arg#2")

'將匯入之巨集移除,不然下次執行時會出現錯誤
Me.VBProject.VBComponents.Remove Me.VBProject.VBComponents.Item(Me.VBProject.VBComponents.Count)

'顯示傳回結果
MsgBox Result

2009年5月15日 星期五

Excel VBA 在儲存前捉取別 Excel 檔 sheet 作更新動作

'存檔前執行
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)


Dim ofile, ff, readfile
Dim theShell As Object

'指定路徑和檔名
DataPath = "C:\XXXX\YYYYY\"
DataFile = "ZZZZZ.xls"

'確認是否有此檔案
With Application.FileSearch
.NewSearch
.LookIn = DataPath
.Filename = DataFile
If .Execute() > 0 Then ff = .FoundFiles.Count
End With


'如果有檔案則開啟此檔案,如果無則跳出 File 對話窗,選取檔案
If ff > 0 Then

' Open( 檔名 , 不做 Update link , 唯讀 )
Set ofile = Workbooks.Open( DataPath & DataFile , 0, True)

Else
'如果找不到檔案,開啟 File 對話窗選取檔案
MsgBox DataPath & DataFile & "檔案不存在,請重新選取路徑。"
Set readfile = Application.FileDialog(msoFileDialogFilePicker)
Dim v As Variant
With readfile
.Filters.Clear
.InitialFileName = DataPath
.InitialView = msoFileDialogViewDetails
.Filters.Add "All Excel Files", "*.xls"
.AllowMultiSelect = False
If .Show Then
v = .SelectedItems.Item(1)
End If
End With

'如果沒有選擇檔案直接結束。
If v Is Nothing Then
Set ofile = Workbooks.Open(v, 0, True)

Else
MsgBox "檔案不存在,請確認。"
End
End If
End If


Cells.Select
Selection.Copy


Dim ck, ckr As Boolean

ck = False

'確認本地檔案中是否有 Index sheet ,如果有需 Delete Index sheet
For Each element In Me.Worksheets

If element.Name = "Index" Then
' Disable 詢問
Application.DisplayAlerts = False
Me.Worksheets("Index").Delete
Application.DisplayAlerts = True
ck = True
Exit For

End If

Next


ck = False

'由來源檔插入 Index Fig sheet 於 Content sheet 之後,並將 Index Fig sheet 改名為 Index sheet
For Each element In ofile.Worksheets

If element.Name = "Index Fig" Then
ofile.Worksheets("Index Fig").Copy after:=Me.Worksheets("Content")
Me.Worksheets("Index Fig").Name = "Index"
ck = True
Exit For
End If

Next

'如果 ck = False 表 來源檔無 Index Fig sheet
If ck = False Then
MsgBox "ZZZZZ.xls 中的 [ Index Fig ] sheet 不存在請確認"
ofile.Close (False)
End

End If



ofile.Close (False)





End Sub

2009年2月17日 星期二

第一隻 Rebol 程式

[ Code ]

i: 0
loop 10 [ starstr: ""
for count 0 i 1 [ starstr: join starstr "*" ]
print starstr
i: i+1 ]

[ Result ]

*
**
***
****
*****
******
*******
********
*********
**********

2009年1月2日 星期五

System.getProperty 中 os.name 、os.version、and os.arch傳回值

os.name os.version os.arch 說明
Linux 2.0.31 x86 IBM Java 1.3
Linux (*) i386 Sun Java 1.3.1, 1.4 or Blackdown Java; (*) os.version depends on Linux Kernel version
Linux (*) x86_64 Blackdown Java; note x86_64 might change to amd64; (*) os.version depends on Linux Kernel version
Linux (*) sparc Blackdown Java; (*) os.version depends on Linux Kernel version
Linux (*) ppc Blackdown Java; (*) os.version depends on Linux Kernel version
Linux (*) armv41 Blackdown Java; (*) os.version depends on Linux Kernel version
Linux (*) i686 GNU Java Compiler (GCJ); (*) os.version depends on Linux Kernel version
Linux (*) ppc64 IBM Java 1.3; (*) os.version depends on Linux Kernel version
Mac OS 7.5.1 PowerPC
Mac OS 8.1 PowerPC
Mac OS 9.0, 9.2.2 PowerPC MacOS 9.0: java.version=1.1.8, mrj.version=2.2.5; MacOS 9.2.2: java.version=1.1.8 mrj.version=2.2.5
Mac OS X 10.1.3 ppc
Mac OS X 10.2.6 ppc Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-39)
Java HotSpot(TM) Client VM (build 1.4.1_01-14, mixed mode)
Mac OS X 10.2.8 ppc using 1.3 JVM: java.vm.version=1.3.1_03-74, mrj.version=3.3.2; using 1.4 JVM: java.vm.version=1.4.1_01-24, mrj.version=69.1
Mac OS X 10.3.1, 10.3.2, 10.3.3, 10.3.4 ppc JDK 1.4.x
Mac OS X 10.3.8 ppc Mac OS X 10.3.8 Server; using 1.3 JVM: java.vm.version=1.3.1_03-76, mrj.version=3.3.3; using 1.4 JVM: java.vm.version=1.4.2-38; mrj.version=141.3
Windows 95 4.0 x86
Windows 98 4.10 x86 Note, that if you run Sun JDK 1.2.1 or 1.2.2 Windows 98 identifies itself as Windows 95.
Windows Me 4.90 x86
Windows NT 4.0 x86
Windows 2000 5.0 x86
Windows XP 5.1 x86 Note, that if you run older Java runtimes Windows XP identifies itself as Windows 2000.
Windows 2003 5.2 x86 java.vm.version=1.4.2_06-b03; Note, that Windows Server 2003 identifies itself only as Windows 2003.
Windows CE 3.0 build 11171 arm Compaq iPAQ 3950 (PocketPC 2002)
OS/2 20.40 x86
Solaris 2.x sparc
SunOS 5.7 sparc Sun Ultra 5 running Solaris 2.7
SunOS 5.8 sparc Sun Ultra 2 running Solaris 8
SunOS 5.9 sparc Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)
MPE/iX C.55.00 PA-RISC
HP-UX B.10.20 PA-RISC JDK 1.1.x
HP-UX B.11.00 PA-RISC JDK 1.1.x
HP-UX B.11.11 PA-RISC JDK 1.1.x
HP-UX B.11.11 PA_RISC JDK 1.2.x/1.3.x; note Java 2 returns PA_RISC and Java 1 returns PA-RISC
HP-UX B.11.00 PA_RISC JDK 1.2.x/1.3.x
HP-UX B.11.23 IA64N JDK 1.4.x
HP-UX B.11.11 PA_RISC2.0 JDK 1.3.x or JDK 1.4.x, when run on a PA-RISC 2.0 system
HP-UX B.11.11 PA_RISC JDK 1.2.x, even when run on a PA-RISC 2.0 system
HP-UX B.11.11 PA-RISC JDK 1.1.x, even when run on a PA-RISC 2.0 system
AIX 5.2 ppc64 sun.arch.data.model=64
AIX 4.3 Power
AIX 4.1 POWER_RS
OS/390 390 02.10.00 J2RE 1.3.1 IBM OS/390 Persistent Reusable VM
FreeBSD 2.2.2-RELEASE x86
Irix 6.3 mips
Digital Unix 4.0 alpha
NetWare 4.11 4.11 x86
OSF1 V5.1 alpha Java 1.3.1 on Compaq (now HP) Tru64 Unix V5.1
OpenVMS V7.2-1 alpha Java 1.3.1_1 on OpenVMS 7.2

System.getProperty用法

System.getProperty()参数大全

java.version Java Runtime Environment version
java.vendor Java Runtime Environment vendor
java.vendor.url Java vendor URL
java.home Java installation directory
java.vm.specification.version Java Virtual Machine specification version
java.vm.specification.vendor Java Virtual Machine specification vendor
java.vm.specification.name Java Virtual Machine specification name
java.vm.version Java Virtual Machine implementation version
java.vm.vendor Java Virtual Machine implementation vendor
java.vm.name Java Virtual Machine implementation name
java.specification.version Java Runtime Environment specification version
java.specification.vendor Java Runtime Environment specification vendor
java.specification.name Java Runtime Environment specification name
java.class.version Java class format version number
java.class.path Java class path
java.library.path List of paths to search when loading libraries
java.io.tmpdir Default temp file path
java.compiler Name of JIT compiler to use
java.ext.dirs Path of extension directory or directories
os.name Operating system name
os.arch Operating system architecture
os.version Operating system version
file.separator File separator ("/" on UNIX)
path.separator Path separator (":" on UNIX)
line.separator Line separator ("\n" on UNIX)
user.name User's account name
user.home User's home directory
user.dir User's current working directory

[Excel]如何創建自定義函數

在 Excel 內建函式中找不到自已想要的函式怎麼辦?事實上我們可以自已建一個,以下是一個簡單的Excel自定義函數示例,用於將民國年轉為西元: Function 民國轉西元(x As Double) As Double     民國轉西元 = x + 1911 End Func...