请问下面两几是什么意思?
1)
Print #1, Chr(27) + Chr(74) + Chr(100) + Chr(27) + Chr(74) + Chr(100)
2)
Open "LPT1:" For Output As #1
Print #1, Chr(27) + Chr(64) + Chr(27) + Chr(50) + Chr(27) + Chr(67) + Chr(29) + Chr(27) + Chr(106) + Chr(100) + Chr(27) + Chr(106) + Chr(100) + Chr(27) + Chr(106) + Chr(75)
1.向句柄为1的对象中写入{ESC}Jd{ESC}Jd
2.输出到打印机:{ESC}@{ESC}2{ESC}C................................
以 ASCII 方式写文件 MSDN 有详细介绍
唉,你是问Print,#1,Chr(),Open,For,Output,As 这些是做什么用的?
Print:输出方法,配合Open就属于File I/O, 如果直接调用,则是PrintScreen.
#1:是句柄为"1"的对象
Chr():是一个函数,可以将ASCII码转成字符。
Open:File I/O的方法
For:在这里是Open方法中的关键字
Output:在这里是File I/O的操作类型(输出)
...
...
Open Statement Example
This example illustrates various uses of the Open statement to enable input and output to a file.
The following code opens the file TESTFILE in sequential-input mode.
Open "TESTFILE" For Input As #1
Close before reopening in another mode.
Close #1
This example opens the file in Binary mode for writing operations only.
Open "TESTFILE" For Binary Access Write As #1
Close before reopening in another mode.
Close #1
The following example opens the file in Random mode. The file contains records of the user-defined type Record.
Type Record Define user-defined type.
ID As Integer
Name As String * 20
End Type
Dim MyRecord As Record Declare variable.
Open "TESTFILE" For Random As #1 Len = Len(MyRecord)
Close before reopening in another mode.
Close #1
This code example opens the file for sequential output; any process can read or write to file.
Open "TESTFILE" For Output Shared As #1
Close before reopening in another mode.
Close #1
This code example opens the file in Binary mode for reading; other processes cant read file.
Open "TESTFILE" For Binary Access Read Lock Read As #1
Dim MyChar
MyChar = Chr(65) Returns A.
MyChar = Chr(97) Returns a.
MyChar = Chr(62) Returns >.
MyChar = Chr(37) Returns %.
QB、VB1~3能得到正确结果
但自从VB4引入UniCode字符串后,直接Chr即有可能造成字符集映射错误
强烈建议用二进制方式操作,用Byte数组读写