vb程序制作字母金字塔 A ABA ABCBA 详细程序?

2024-12-18 23:31:47
推荐回答(1个)
回答1:

加个label1Private Sub Command1_Click()
Dim I As Integer
Dim Hs As Integer '行数
Dim Ksstr As String
Dim Ksasc As IntegerKsstr = "A" '从哪个字符开始
Ksasc = Asc(Ksstr) 'asc码
Label1.AutoSize = True '自动显示全部文字
Label1.Alignment = 2 '居中 Label1.Caption = Ksstr
Hs = Val(InputBox("输入行数,不要太大", "行数", 5)) - 1 '行数
For I = 1 To Hs '把中间的字母换成 新字母 如:ABA 把 B 替换成 BCB 就变成 ABCBA
Ksstr = Replace(Ksstr, Chr(Ksasc + I - 1), Chr(Ksasc + I - 1) & Chr(Ksasc + I) & Chr(Ksasc + I - 1))
Label1.Caption = Label1.Caption & Chr(13) & Chr(10) & Ksstr
Next
Label1.Left = 100 '
End Sub