📄 shift.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "转换成BASE64编码"
ClientHeight = 2940
ClientLeft = 60
ClientTop = 345
ClientWidth = 3960
LinkTopic = "Form1"
ScaleHeight = 2940
ScaleWidth = 3960
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text2
Height = 270
Left = 480
Locked = -1 'True
TabIndex = 2
Top = 1920
Width = 2775
End
Begin VB.CommandButton Command1
Caption = "转换成BASE64编码"
Height = 615
Left = 480
TabIndex = 1
Top = 960
Width = 2775
End
Begin VB.TextBox Text1
Height = 270
Left = 480
TabIndex = 0
Top = 360
Width = 2775
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Base64TalbeStr(0 To 63) As String * 1
Const Chars64Table As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Public Function StringToBase64(ByRef Text As String) As String '将字符串转换成Base64码的函数
Dim CharsInAsc() As Integer, StrInLen As Long '
Dim i As Long, j As Long
Dim Base64Len As Long, strout As String
For i = 0 To 63: Base64TalbeStr(i) = Mid$(Chars64Table, i + 1, 1): Next '建立Base64码表数组
StrInLen = Len(Text)
If StrInLen = 0 Then Exit Function '输入字符串校验,长度不能为0
Base64Len = ((StrInLen + 2) \ 3) * 4 '输入字符串的转换为Base64码后的长度
ReDim CharsInAsc(1 To StrInLen)
For i = 1 To StrInLen: CharsInAsc(i) = Asc(Mid$(Text, i, 1)): Next
ReDim Chars64(0 To Base64Len - 1)
For i = 1 To StrInLen - 2 Step 3 '一次转换三个字符
strout = strout & Base64TalbeStr(CharsInAsc(i) \ &H4) '除4,取其高6位
strout = strout & Base64TalbeStr((CharsInAsc(i) And &H3) * &H10 + _
CharsInAsc(i + 1) \ &H10) '取第一字节的低二位并 *16,取第二字节的高4位,相加
strout = strout & Base64TalbeStr((CharsInAsc(i + 1) And &HF) * &H4 + CharsInAsc(i + 2) \ &H40)
'取第二字节的低4位并 *16,取第三字节的高2位,相加
strout = strout & Base64TalbeStr(CharsInAsc(i + 2) And &H3F) '取第三字节的低6位
j = j + 4
Next i
Select Case StrInLen - i '当输入的字符不是3的倍数时,继续转换未转换完的输入字符Base64码
Case 0 '输入为3*n+1 个字符
strout = strout & Base64TalbeStr(CharsInAsc(i) \ &H4)
strout = strout & Base64TalbeStr((CharsInAsc(i) And &H3) * &H10)
strout = strout & "=="
Case 1 '输入为3*n+2 个字符
strout = strout & Base64TalbeStr(CharsInAsc(i) \ &H4)
strout = strout & Base64TalbeStr((CharsInAsc(i) And &H3) * &H10 + CharsInAsc(i + 1) \ &H10)
strout = strout & Base64TalbeStr((CharsInAsc(i + 1) And &HF) * &H4)
strout = strout & "="
End Select
StringToBase64 = strout
End Function
Private Sub Command1_Click()
Text2.Text = StringToBase64(Text1.Text)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -