如何用VB建个记事本,创建乱码文件?

如题所述

第1个回答  2011-08-02
Function Garbage(txt As TextBox, Max As Long)
Dim num As Long '乱码代号
If Len(txt) < Max Then
num = Round(Rnd * 45)
'假如num等于一个数,那么txt就加上一个字符
'这样就可以生成乱码了
If num = 1 Then txt = txt & " "
If num = 2 Then txt = txt & "~"
If num = 3 Then txt = txt & "!"
If num = 4 Then txt = txt & "@"
If num = 5 Then txt = txt & "#"
If num = 6 Then txt = txt & "$"
If num = 7 Then txt = txt & "%"
If num = 8 Then txt = txt & "^"
If num = 9 Then txt = txt & "&"
If num = 10 Then txt = txt & "*"
If num = 11 Then txt = txt & "("
If num = 12 Then txt = txt & ")"
If num = 13 Then txt = txt & "16"
If num = 14 Then txt = txt & "24"
If num = 15 Then txt = txt & "39"
If num = 16 Then txt = txt & "58"
If num = 17 Then txt = txt & "70"
If num = 18 Then txt = txt & "AC"
If num = 19 Then txt = txt & "RHF"
If num = 20 Then txt = txt & "Jds"
If num = 21 Then txt = txt & ":"
If num = 22 Then txt = txt & ";"
If num = 23 Then txt = txt & "["
If num = 24 Then txt = txt & "]"
If num = 25 Then txt = txt & " "
If num = 26 Then txt = txt & "KM,"
If num = 27 Then txt = txt & ","
If num = 28 Then txt = txt & "."
If num = 29 Then txt = txt & "?"
If num = 30 Then txt = txt & "-"
If num = 31 Then txt = txt & "="
If num = 32 Then txt = txt & "_"
If num = 33 Then txt = txt & "+"
If num = 34 Then txt = txt & "QV"
If num = 35 Then txt = txt & "|"
If num = 36 Then txt = txt & "\"
If num = 37 Then txt = txt & "{"
If num = 38 Then txt = txt & "}"
If num = 39 Then txt = txt & "`"
If num = 40 Then txt = txt & ">"
If num = 41 Then txt = txt & "<"
If num = 42 Then txt = txt & "BQ"
If num = 43 Then txt = txt & """"
If num = 44 Then txt = txt & "VP"
End If
End Function

用法:Call Garbage(生成在哪里,长度)
演示:
Private Sub Command1_Click()
Timer1.Interval = 1
End Sub

Private Sub Timer1_Timer()
On Error Resume Next
Call Garbage(Text1, 5000)
If Len(Text1) >= 5000 Then
Timer1.Interval = 0
End If
End Sub
第2个回答  2011-08-02
无意义的乱码文件:
Sub garbled(length As Long,name As String) '文件的长度和名字
On Error Resume Next
Dim invalidchars="/\:*?<>|"
For i=1 To 8
If InStr(1,name,Mid(invalidchars,i,1))>0 Then Exit Sub '验证文件名是否有效
Next i
If Dir(name)<>"" Then Exit Sub
Open name & ".txt" For Output As #1
For i=0 To length
Randomize
Print #1,ChrW(Int(Rnd*65535)) '写入乱码
Next i
Close #1
End Function
有意义的(详细代码我不写出来了):
建立一个变量(用于存储加密结果)和一个数组,元素数量为加密前字符串的长度,用于存储ASCII码,然后用For循环给每个元素赋值(赋的值是被改的ASCII码),最后用For循环把数组中的每个字符用ChrW函数读出连成字符串赋给一开始建立的用于存储加密结果的变量,再写入文件即可!本回答被提问者采纳
第3个回答  2011-08-02
将你要保存的内容的文本内容的ASC码进行ASC偏移后再存储,如dd = Chr(asc(dd) + 3000),读取时则相反。
第4个回答  2011-08-02
读到的数据文件为我们自己行业使用的专用软件,使用记事本打开时部分可正常显示乱码仅仅是你认为是无用的,对你单位的程序来说,也是有意义的,不是吗?
相似回答