- Oct 08 Tue 2013 11:03
-
[VB.Net][使用javascript onkeypress事件]
- Oct 08 Tue 2013 11:01
-
[VB.Net][防止按鈕重複按]
- Oct 08 Tue 2013 10:56
-
[VB.Net][使用ICSharpCode.SharpZipLib.dll元件處理壓縮]
步驟二:將下列程式加入Class
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.IO
Imports ICSharpCode.SharpZipLib.Zip
Public Class Zip
''' <summary>
''' 壓縮整個資料夾
''' </summary>
''' <param name="SourceDir">要壓縮的資料夾(完整路徑) </param>
''' <param name="TargetFile">要產生的Zip檔案(完整路徑檔名)</param>
''' <param name="Password">密碼</param>
''' <param name="BackupOldFile">是否備份舊檔案</param>
Public Sub ZipDir(ByVal SourceDir As String, ByVal TargetFile As String, ByVal Password As String, ByVal BackupOldFile As Boolean)
Dim oZipDir As New ICSharpCode.SharpZipLib.Zip.FastZip()
Try
If Not Directory.Exists(SourceDir) Then
Throw New Exception("資料夾不存在!")
End If
If BackupOldFile = True Then
'判斷要產生的ZIP檔案是否存在
If File.Exists(TargetFile) = True Then
'原本的檔案存在,把他ReName
File.Copy(TargetFile, TargetFile & "-" & DateTime.Now.ToString("yyyyMMddHHmmss") & ".back")
File.Delete(TargetFile)
End If
End If
If Password <> "" Then
oZipDir.Password = Password
End If
oZipDir.CreateZip(TargetFile, SourceDir, True, "")
Catch
Throw
End Try
End Sub
''' <summary>
'''壓縮整個資料夾
''' </summary>
''' <param name="SourceDir">要壓縮的資料夾(完整路徑) </param>
''' <param name="TargetFile">要產生的Zip檔案(完整路徑檔名)</param>
''' <param name="Password">密碼</param>
Public Sub ZipDir(ByVal SourceDir As String, ByVal TargetFile As String, ByVal Password As String)
Me.ZipDir(SourceDir, TargetFile, Password, True)
End Sub
''' <summary>
'''壓縮整個資料夾
''' </summary>
''' <param name="SourceDir">要壓縮的資料夾(完整路徑) </param>
''' <param name="TargetFile">要產生的Zip檔案(完整路徑檔名)</param>
Public Sub ZipDir(ByVal SourceDir As String, ByVal TargetFile As String)
Me.ZipDir(SourceDir, TargetFile, "", True)
End Sub
''' <summary>
''' 壓縮檔案
''' </summary>
''' <param name="SourceFiles">要壓縮的檔案(完整路徑)</param>
''' <param name="TargetFile">要產生的Zip檔案(完整路徑檔名)</param>
''' <param name="Password">密碼</param>
''' <param name="BackupOldFile">是否備份舊檔案</param>
Public Sub ZipFiles(ByVal SourceFiles As String(), ByVal TargetFile As String, ByVal Password As String, ByVal BackupOldFile As Boolean)
Try
If SourceFiles Is Nothing OrElse SourceFiles.Length <= 0 Then
Throw New Exception("並未傳入檔案完整路徑")
End If
For i As Integer = 0 To SourceFiles.Length - 1
If File.Exists(SourceFiles(i)) = False Then
Throw New Exception("要壓縮的檔案【" & SourceFiles(i) & "】不存在")
End If
Next
If BackupOldFile = True Then
'判斷要產生的ZIP檔案是否存在
If File.Exists(TargetFile) = True Then
'原本的檔案存在,把他ReName
File.Copy(TargetFile, TargetFile & "-" & DateTime.Now.ToString("yyyyMMddHHmmss") & ".back")
File.Delete(TargetFile)
End If
End If
Dim zs As New ZipOutputStream(File.Create(TargetFile))
zs.SetLevel(9)
'壓縮比
If Password <> "" Then
zs.Password = Password
End If
For i As Integer = 0 To SourceFiles.Length - 1
Dim s As FileStream = File.OpenRead(SourceFiles(i))
Dim buffer As Byte() = New Byte(s.Length - 1) {}
s.Read(buffer, 0, buffer.Length)
Dim Entry As New ZipEntry(Path.GetFileName(SourceFiles(i)))
Entry.DateTime = DateTime.Now
Entry.Size = s.Length
s.Close()
zs.PutNextEntry(Entry)
zs.Write(buffer, 0, buffer.Length)
Next
zs.Finish()
zs.Close()
Catch
Throw
End Try
End Sub
''' <summary>
''' 壓縮檔案
''' </summary>
''' <param name="SourceFiles">要壓縮的檔案(完整路徑)</param>
''' <param name="TargetFile">要產生的Zip檔案(完整路徑檔名)</param>
''' <param name="Password">密碼</param>
Public Sub ZipFiles(ByVal SourceFiles As String(), ByVal TargetFile As String, ByVal Password As String)
Me.ZipFiles(SourceFiles, TargetFile, Password, True)
End Sub
''' <summary>
''' 壓縮檔案
''' </summary>
''' <param name="SourceFiles">要壓縮的檔案(完整路徑)</param>
''' <param name="TargetFile">要產生的Zip檔案(完整路徑檔名)</param>
Public Sub ZipFiles(ByVal SourceFiles As String(), ByVal TargetFile As String)
Me.ZipFiles(SourceFiles, TargetFile, "", True)
End Sub
''' <summary>
''' 壓縮單一檔案
''' </summary>
''' <param name="SourceFiles">要壓縮的檔案(完整路徑)</param>
''' <param name="TargetFile">要產生的Zip檔案(完整路徑檔名)</param>
''' <param name="Password">密碼</param>
''' <param name="BackupOldFile">是否備份舊檔案</param>
Public Sub ZipFile(ByVal SourceFile As String, ByVal TargetFile As String, ByVal Password As String, ByVal BackupOldFile As Boolean)
Me.ZipFiles(New String() {SourceFile}, TargetFile, Password, BackupOldFile)
End Sub
''' <summary>
''' 壓縮單一檔案
''' </summary>
''' <param name="SourceFiles">要壓縮的檔案(完整路徑)</param>
''' <param name="TargetFile">要產生的Zip檔案(完整路徑檔名)</param>
''' <param name="Password">密碼</param>
Public Sub ZipFile(ByVal SourceFile As String, ByVal TargetFile As String, ByVal Password As String)
Me.ZipFile(SourceFile, TargetFile, Password, True)
End Sub
''' <summary>
''' 壓縮單一檔案
''' </summary>
''' <param name="SourceFiles">要壓縮的檔案(完整路徑)</param>
''' <param name="TargetFile">要產生的Zip檔案(完整路徑檔名)</param>
''' <returns></returns>
Public Sub ZipFile(ByVal SourceFile As String, ByVal TargetFile As String)
Me.ZipFile(SourceFile, TargetFile, "", True)
End Sub
''' <summary>
''' 解壓縮
''' </summary>
''' <param name="SourceFile">要解壓縮的Zip檔案(完整路徑檔名) </param>
''' <param name="TargetDir">解壓縮後存放的資料夾路徑(完整路徑) </param>
''' <param name="Password">密碼</param>
Public Sub ExtractZip(ByVal SourceFile As String, ByVal TargetDir As String, ByVal Password As String)
Dim oZip As New ICSharpCode.SharpZipLib.Zip.FastZip()
Try
'判斷要產生的ZIP檔案是否存在
If File.Exists(SourceFile) = False Then
Throw New Exception("要解壓縮的檔案【" & SourceFile & "】不存在,無法執行")
End If
If Password <> "" Then
oZip.Password = Password
End If
oZip.ExtractZip(SourceFile, TargetDir, "")
Catch
Throw
End Try
End Sub
''' <summary>
''' 解壓縮
''' </summary>
''' <param name="SourceFile">要解壓縮的Zip檔案(完整路徑檔名) </param>
''' <param name="TargetDir">解壓縮後存放的資料夾路徑(完整路徑) </param>
Public Sub ExtractZip(ByVal SourceFile As String, ByVal TargetDir As String)
Me.ExtractZip(SourceFile, TargetDir, "")
End Sub
End Class
- Oct 08 Tue 2013 10:56
-
[VB.Net][全型轉半型不含中文字]
Imports System.Text
'全型轉半型
Public Function ToNchr(ByRef data As String) As String
Dim sb As New StringBuilder
Dim ascii As Integer = 0
For Each c As Char In data.Replace("〔", "[").Replace("〕", "]").Replace("'", "'").ToCharArray()
ascii = System.Convert.ToInt32(c)
If ascii = 12288 Then
sb.Append(System.Convert.ToChar(32))
Else
If ascii > 65280 And ascii < 65375 Then
sb.Append(System.Convert.ToChar(ascii - 65248))
Else
sb.Append(System.Convert.ToChar(ascii))
End If
End If
Next
Return sb.ToString
End Function
- Oct 08 Tue 2013 10:54
-
[VB.Net][檔案Anis轉成Unicode格式]
Imports System.IO
Imports System.Text
'檔案Anis轉成Unicode格式
Dim reader1 As New StreamReader("D:\TEST.DAT", Encoding.GetEncoding(0))
Dim writer1 As New StreamWriter("D:\TEST_Un.TXT", True, Encoding.Unicode)
writer1.Write(reader1.ReadToEnd)
writer1.Flush()
writer1.Close()
reader1.Close()
- Oct 08 Tue 2013 10:53
-
[VB.Net][使用StreamWriter匯出文字檔]
Imports System.IO
Imports System.Text
'StreamWriter匯出文字檔
Dim sL_Path As String = "D:\AAA.csv"
Dim sw As StreamWriter = New StreamWriter(sL_Path, True, Encoding.Unicode)
If File.Exists(sL_Path) Then
File.Delete(sL_Path)
End If
sw.WriteLine("開始")
sw.WriteLine("內容1")
sw.WriteLine("內容2")
sw.WriteLine("結束")
sw.Close()
- Oct 08 Tue 2013 10:14
-
[VBA]Access程式集
http://vb.ncis.com.tw/LMVB2.0/exp/exp.html
VB新增資料表或資料庫.
http://tw.knowledge.yahoo.com/question/question?qid=1607042107814
======================================================================================================================
設定資料新增或修改的警告視窗
----------------------------
DoCmd.SetWarnings False
- Feb 05 Tue 2013 16:18
-
[VB.Net][Calendar控制項日期複選\取消,年曆、月曆、行事曆]
- Feb 05 Tue 2013 14:13
-
[VB.Net][DataTable、DataView、DataSet與DataRow的互轉]
- Jun 15 Fri 2012 10:00
-
裝潢建議分享
純粹分享在網路上收集的一些裝潢建議資料,將其資料做整理分類。
裝潢工程裡還有許多細節及專業的地方,小弟不才,沒有辦法一一列出,所以這邊只有列出,一般人常遇到的問題。小弟只單純希望此文章,對大家可以有所幫助,絕對沒有針對任何個人或公司,有任何攻擊或評論之行為。關於裡面分享的一些想法或做法,還是需要經過專業人員的評估是否可行,不一定適合每個現場。
- Sep 07 Wed 2011 10:20
-
[T-SQL]難字處理
update <table_name> set <filed_name>=N'我是難字:双喆堃’ where <condition>;
- Aug 22 Mon 2011 15:50
-
[VB.Net][GridView上下鍵](按鍵盤上的下,跳到下一行…)
--=================================== [頁面] ===============================================--