以下是vba的模塊代碼,求助幫忙轉換成vb6代碼
Sub Txt2Jpg(inFileFullName As String, outFileFullName As String)
Dim a() As Byte, b() As Byte
Dim i As Long, j As Long
Dim FileNo As Long
FileNo = FreeFile
Open inFileFullName For Binary As FileNo
ReDim a(LOF(FileNo) - 1)
Get FileNo, , a
Close FileNo
ReDim b((UBound(a) + 1) * 3 / 4 - 1)
For i = LBound(a) To UBound(a)
If a(i) >= 65 And a(i) <= 90 Then
a(i) = a(i) - 65
ElseIf a(i) >= 97 And a(i) <= 122 Then
a(i) = a(i) - 71
ElseIf a(i) >= 48 And a(i) <= 57 Then
a(i) = a(i) + 4
ElseIf a(i) = 43 Then
a(i) = 62
ElseIf a(i) = 47 Then
a(i) = 63
End If
Next
For i = LBound(a) To UBound(a) Step 4
j = (i \ 4) * 3
b(j) = a(i) * 4 + a(i + 1) \ 16
b(j + 1) = (a(i + 1) Mod 16) * 16 + a(i + 2) \ 4
b(j + 2) = (a(i + 2) Mod 4) * 64 + a(i + 3)
Next
FileNo = FreeFile
Open outFileFullName For Binary As FileNo
Put FileNo, , b
Close FileNo
End Sub
Sub Main()
Dim vFileDLG As FileDialog
Dim vSeled As Variant
Dim strPath As String
Set vFileDLG = Application.FileDialog(msoFileDialogFolderPicker)
With vFileDLG
.Title = "Eersoft-選擇輸出檔案保存的檔案夾"
getpath: If .Show = -1 Then
strPath = .SelectedItems.Item(1)
strPath = strPath & IIf(Right$(strPath, 1) = "\", "", "\")
Else
If MsgBox("沒有選擇輸出檔案存放的檔案夾,需要重新選取嗎?如果不重新選取程式將退出。", vbQuestion + vbYesNo, "Eersoft-選取輸出檔案存放檔案夾") = vbYes Then
GoTo getpath
Else
Exit Sub
End If
End If
End With
Set vFileDLG = Application.FileDialog(msoFileDialogFilePicker)
With vFileDLG
.Title = "Eersoft-選擇需要轉換的檔案"
.Filters.Add "文本檔案", "*.txt"
getfile: If .Show = -1 Then
For Each vSeled In .SelectedItems
Call Txt2Jpg(CStr(vSeled), strPath & getNameForFullName(CStr(vSeled)) & ".jpg")
Next vSeled
MsgBox "所有檔案已經轉換完成。", vbInformation + vbOKOnly, "Eersoft-轉換完成"
Else
If MsgBox("沒有選擇需要轉換的檔案,需要重新選取嗎?如果不重新選取程式將退出。", vbQuestion + vbYesNo, "Eersoft-選取需要轉換的檔案") = vbYes Then
GoTo getfile
Else
Exit Sub
End If
End If
End With
Set vFileDLG = Nothing
End Sub
Function getNameForFullName(strPath As String) As String
Dim srr
srr = Split(strPath, "\")
getNameForFullName = Split(srr(UBound(srr)), ".")(0)
End Function
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/264625.html
標籤:VB基礎類
