napa6101 2009-2-5 21:08
用VB畫出方格??
習題,不知道錯什麼= = ..................
問題是, 例如 輸入5 出現
*****
* *
* *
* *
*****
輸入2 出現
**
**
如此類推
以下是我自已寫的~
Dim x As Integer
x = InputBox("Enter value for number (1~10)", "Input x")
Dim i As Integer = 0
Dim j As Integer = 1
While i < x
j = 1
While j <= x
Print("*")
j += j
End While
Print(vbCrLf)
i += i
End While
[[i] 本帖最后由 napa6101 于 2009-2-5 22:36 编辑 [/i]]
Nothing 2009-2-6 19:07
[color=#000000]下面是VB6的代码[/color]
[color=#000000] [color=#0000ff]Dim[/color] x As Integer[color=#0000cc],[/color] i As Integer
x [color=#0000cc]=[/color] [color=#ff0000]InputBox[/color][color=#0000cc]([/color][color=#ff00ff]"Enter value for number (1~10)"[/color][color=#0000cc],[/color] [color=#ff00ff]"Input x"[/color][color=#0000cc])[/color]
[color=#0000ff]For[/color] i [color=#0000cc]=[/color] 1 [color=#0000ff]To[/color] x
Print [color=#ff0000]String[/color][color=#0000cc]([/color]x[color=#0000cc],[/color] [color=#ff00ff]"*"[/color][color=#0000cc])[/color]
[color=#0000ff]Next[/color][/color]
Nothing 2009-2-6 19:11
VB.Net的
Dim x As Integer, i As Integer
x = InputBox("Enter value for number (1~10)", "Input x")
For i = 1 To x
Print StrDup(x, "*")
Next
napa6101 2009-2-7 19:30
寫到了~
Dim x, i, j As Integer
x = InputBox("Enter value for number (1~10)", "Input x")
laloutput.Text = ""
For i = 1 To x
For j = 1 To x
If (i = 1 Or i = x) Or (j = 1 Or j = x) Then
laloutput.Text += "*"
Else
laloutput.Text += " "
End If
Next j
laloutput.Text += vbCrLf
Next i
End Sub