加密:
Public Function blue()
Dim str As String
str = "Provider=SQLOLEDB;Data Source=0.0.0.1;UID=X;PWD=000;Initial Catalog=X_Data"
n = Len(str)
Dim a2() As Byte
For i = 1 To n
ReDim a2(1 To n) As Byte
a2(i) = StrConv(Left(str, 1), vbUnicode)
str = Right(str, Len(str) - 1)
Next i
'加密
Open "d:\system\include\res.txt" For Binary As #1
Put #1, , a2
Close #1
End Function
解密:
Public Function db()
    Dim conn As New ADODB.Connection
    Dim a() As Byte
    Open "d:\system\include\res.txt" For Binary As #1
    n2 = LOF(1)
    ReDim a(n2) As Byte
    Get #1, , a(0)
    Close #1
    Dim s As String
    For i = 0 To n2 - 1
    s = s & Chr(a(UBound(a) - i))
    Next i
    s = StrReverse(s)
    '解密
    conn.Open s
    Set db = conn
End FunctionPublic Sub connclose(connname)
connname.Close
Set connname = Nothing
End Sub
我现在的问题是,无法进行文件的读写
各位高手帮小妹看看吧 感激不尽!!

解决方案 »

  1.   

    还有一个问题,如果我要将一个字符串拆分成一个一个的字符,转换成ASCII码(因为我还要对它加密,所以要转成ASCII码),写入文件X,然后在另一文件中读出X,将得出的东西(是ASCII码的)转换成相应字符,并连成字符串,
    拆分:str = "Provider=SQLOLEDB;Data Source=0.0.0.1;UID=X;PWD=000;Initial Catalog=X_Data"
    n = Len(str)
    Dim a2() As Byte
    For i = 1 To n
    ReDim a2(1 To n) As Byte
    a2(i) = StrConv(Left(str, 1), vbUnicode)
    str = Right(str, Len(str) - 1)
    Next i
    重新组合:
    Dim s As String
        For i = 0 To n2 - 1
        s = s & Chr(a(UBound(a) - i))
        Next i
        s = StrReverse(s)
        不知道这样做对不对
    但运行不出来
    各位大哥帮忙啊
      

  2.   

    把 for 后面的改为 access read或者access write 试一试
      

  3.   

    redim好像用错了阿
    不应该放在for里面的.
      

  4.   

    我只改了一部分  
    可能对你有所帮助
    '修改部分
    '++++++++++++++++++++++
    Option ExplicitPublic Function blue()
    Dim str As String
    str = "steasdf"
    Dim n, i As IntegerOpen App.Path & "\res.txt" For Binary As #1n = Len(str)Dim a2() As Variant
    ReDim a2(1 To n) As VariantFor i = 1 To n
        a2(i) = StrConv(Left(str, 1), vbUnicode)
        str = Right(str, Len(str) - 1)
        Put #1, , a2(i)
    Next i
        
    Close #1
    End Function
    '+++++++++++++++++++++++++++
    '解密:
    Public Function db()
        Dim conn As New ADODB.Connection
        Dim a() As Byte
        Open App.Path & "res.txt" For Binary As #1
        n2 = LOF(1)
        ReDim a(n2) As Byte
        Get #1, , a(0)
        Close #1
        Dim s As String
        For i = 0 To n2 - 1
        s = s & Chr(a(UBound(a) - i))
        Next i
        s = StrReverse(s)
        '解密
        conn.Open s
        Set db = conn
    End FunctionPublic Sub connclose(connname)
    connname.Close
    Set connname = Nothing
    End Sub
    Private Sub Command1_Click()Call blue
    '是可以写入的End SubPrivate Sub Command2_Click()Call dbEnd Sub
      

  5.   

    这样是可以的:你可以在窗体上加入两个按纽 command1 command2把代码拷贝后试试! 我测试通过了
    Option Explicit
    Public n As Integer
    Dim str As StringPublic Function blue()str = "Provider=SQLOLEDB;Data Source=0.0.0.1;UID=X;PWD=000;Initial Catalog=X_Data"
    Dim i As IntegerOpen App.Path & "\res.txt" For Binary As #1n = Len(str)Dim a2() As Variant
    ReDim a2(1 To n) As VariantFor i = 1 To n
        a2(i) = StrConv(Left(str, 1), vbUnicode)
        str = Right(str, Len(str) - 1)
        Put #1, , a2(i)
    Next i
        
    Close #1
    End FunctionPublic Function db()
        Dim conn As New ADODB.Connection
        Dim a() As Variant
        Dim s As String
        Dim i As Integer
        
        s = ""
        Open App.Path & "\res.txt" For Binary As #1
        'n2 = LOF(1)
        
        ReDim a(n) As Variant
        Get #1, , a
        Close #1
        
        For i = 1 To n
            's = s & Chr(a(UBound(a) - i))
            s = s & StrConv(a(UBound(a) - i), vbFromUnicode)
        Next i
        s = StrReverse(s)
        '½âÃÜ
        conn.Open s
        Set db = conn
    End FunctionPublic Sub connclose(connname)
    connname.Close
    Set connname = Nothing
    End Sub
    Private Sub Command1_Click()Call blueEnd SubPrivate Sub Command2_Click()Call dbEnd SubPrivate Sub Form_Load()Open App.Path & "\res.txt" For Binary As #1
         
         str = "Provider=SQLOLEDB;Data Source=0.0.0.1;UID=X;PWD=000;Initial Catalog=X_Data"
         n = Len(str)Close #1End Sub
      

  6.   

    Open App.Path & "res.txt" For Binary As #1最好写成 Open App.Path & "\res.txt" For Binary As #1