打印输出大全
最新的新手通常学 Hello World程序,那我们也跟着潮流走吧
Private Sub Form_Load() Me.AutoRedraw = True Me.Print "Welcome to Visual Basic Programing!" MsgBox "Welcome to Visual Basic Programing!" End Sub
教程和练习通常要打印某种图形
(*注:所有例子窗体的AutoRedraw要设置为TRUE)
打印一个三角形
Private Sub Command1_Click() Dim i,j As Integer,s As String,c As String c = InputBox("请输入打印的字符:","*") c = Chr(Asc(c)) For i = 0 To 8 s = s & c Me.Print s Next i End Sub
打印一个 * 组成的平行四边形
Private Sub Command1_Click() Dim i,c As String s = InputBox("请输入打印的字符:","*") c = Chr(Asc(s)) For i = 0 To 8 s = Space(i) For j = 0 To 8 s = s & c Next j Me.Print s Next i End Sub
这里使代码更简洁的方法是
Private Sub Command1_Click() Dim i,"*") c = Chr(Asc(s)) For i = 0 To 8 s = Space(i) s = s & Replace(Space(8)," ",c Me.Print s Next i End Sub
要反过来,只要把Space(i) 改成Space(8 - i)就可以了
运行效果
其实无论怎么输出,就是Print 把某个字符画在窗体上,聪明的人会自己解决这些问题
我只是看不惯很多人为了写作业,满世界在那里喊