vbs实现编程算法之一——图形输出

上一篇 / 下一篇  2012-02-13 13:34:35 / 个人分类:VBScript

最近闲来无聊,看了些编程的算法,用vbs实现了下,算是巩固下vbs
vbs没有像c那样的printf打印函数,只能先用&连接字符串,用vbcrlf来控制换行,然后再用msgbox来显示
**九九乘法表**
dim i,j
for i=1 to 9
for j=1 to i
str=str & j & "*" & i & "=" & i* j & " "
next 
str=str & vbCrlf '换行
next
Msgbox str
**杨辉三角**
dim i,j,a(10,10)
'数组赋值
for i =0 to 9
a(i,0)=1
a(i,i)=1
next
for i=2 to 4
for j=1 to i-1
a(i,j)=a(i-1,j-1)+a(i-1,j)
next
next
'打印
for i=0 to 4
for k=0 to 20-i
str=str&space(1)
next 
for j=0 to i
str=str & a(i,j) &space(1)
next
str=str & vblf
next
msgbox str
        151Testing软件测试网]B2{2E6DmkL tFi
       1 151Testing软件测试网x6s5R$W3V3SD"G^2[
      1 2 151Testing软件测试网 ?M*?o@"A2`b [
     1 3 1
/mh.DqeQ0   
6 4 1   
**打印星号**
'打印上半部分
for i=0 to 3
for j=0 to 2-i
str=str &space(1)
next
for k=0 to 2*i
str=str &"*"
next
str=str&vbcrlf
next
'打印下半部分
for i=0 to 2
for j=0 to i
str=str &space(1)
next
for k=0 to 4-2*i
str=str &"*"
next
str=str&vbcrlf
next
msgbox str
              *
.J ~*L1kx S2t0             ***51Testing软件测试网%Tl7gjD?T
            *****
+]y1f+Wt e0             ***51Testing软件测试网}L2J5wW+A's!F
              *
**打印字母(例如输入员字母C,打印如下图形)**
c=Asc("C")-Asc("A")
for i=0 to 2*c
for j =0 to Abs(c-i)
str=str &space(1)
next
for k=0 to c-Abs(c-i)
str=str& Chr(65+k) &space(1)
next
str =str & vbcrlf
next
51Testing软件测试网,WC6um1H@NH9_'QE
msgbox str
  A
A1{2dA W0 A B
2AI S+Oc/tqi0A B C
j-js|_[ ?j!E u0 A B51Testing软件测试网X~'I&O4N;N
  A

{oK;zQ*h(Q0F$B,qw0

TAG:

 

评分:0

我来说两句

Open Toolbar