非常简单的vb编程题,不确定规范的写法,请高手指点~~3Q

1.输出100~200之间不能被3整除的数。
2.任意输入一个自然数n,求1到n之间所有偶数的和。
3.随机产生8个1~100之间的正整数,按升序排出。
4.编写程序,在窗体中输出菱形图形
*
* * *
* * * * *
* * * * * * *
* * * * *
* * *
*
谢谢高手指教,有赏分的,3、4题最好写一下每步的意义,非常感谢~~~

Private Sub Command8_Click()
Dim i As Integer
Dim s As String
For i = 100 To 200
If (i Mod 3) <> 0 Then
If s <> "" Then s = s & ","
s = s & i
End If
Next i
Text1.Text = s
End Sub

Private Sub Command9_Click()
Dim intEnd As Integer
Dim i As Integer, intSum As Integer
Dim strEnd As String
strEnd = Text1.Text
If IsNumeric(strEnd) = False Then
Text2.Text = "非法输入"
Exit Sub
End If
intEnd = CInt(strEnd)
If intEnd < 1 Then
Text2.Text = "非法输入"
Exit Sub
End If
intSum = 0
For i = 1 To intEnd - 1
If (i Mod 2) = 0 Then
intSum = intSum + i
End If
Next i
Text2.Text = "1到" & intEnd & "之间偶数和为" & intSum
End Sub

Private Sub Command10_Click()
Dim sTempCode() As String, sTemp As String
Dim intCodeNum As Integer
Dim dbLow As Double, dbUpper As Double, Random As Double
Dim i As Integer, j As Integer
intCodeNum = 8 '随机数个数
dbLow = 1 '随机数下限
dbUpper = 100 '随机数上限
ReDim sTempCode(0 To intCodeNum - 1)
'生成随机数保存在数组中
For i = 0 To intCodeNum - 1
Randomize
Random = dbLow + (dbUpper - dbLow) * Rnd()
sTempCode(i) = Right("000" & CInt(Random), 3)
Next i
'冒泡法排序
For j = 0 To intCodeNum - 1
For i = intCodeNum - 1 To j + 1 Step -1
If CInt(sTempCode(i)) < CInt(sTempCode(i - 1)) Then
sTemp = sTempCode(i - 1)
sTempCode(i - 1) = sTempCode(i)
sTempCode(i) = sTemp
End If
Next i
Next j
'输出结果
Text2.Text = ""
For i = 0 To intCodeNum - 1
Text2.Text = Text2.Text & sTempCode(i)
If i <> intCodeNum - 1 Then
Text2.Text = Text2.Text & ","
End If
Next i
End Sub

Private Sub Command11_Click()
Dim StarNum As Integer
Dim i As Integer, j As Integer
Dim LineNum As Integer
Dim s As String

Dim xLine As Integer, yLine As Integer
xLine = 6
yLine = 6
For j = 0 To yLine
s = " " '左边距
If j <= (xLine \ 2) Then
For i = 0 To xLine
If Abs((xLine \ 2) - i) <= j Then
s = s & "*"
Else
s = s & " "
End If
Next i
Else
For i = 0 To xLine
If Abs((xLine \ 2) - i) <= (xLine \ 2) - (j - (xLine \ 2)) Then
s = s & "*"
Else
s = s & " "
End If
Next i
End If
Debug.Print s
Form1.Print s
Next j

End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-08-12
Delphi版本代码.测试可以达到效果!

function TForm1.topic1(plural, minV, maxV: Integer): string;
var
iLoop:Integer;
begin
Result:='';
for iLoop:=minv to maxv do
begin
if iLoop mod plural >0 then
begin
Result:=Result+ IntToStr(iLoop)+',';
end;
end;
end;

function TForm1.topic2(plural: Integer): Integer;
var
iLoop:Integer;
begin
result:=0;
for iLoop:=1 to plural do
begin
if iLoop mod 2 =0 then
begin
Result:=Result+iLoop;
end;
end;
end;

function TForm1.topic3(): string;
var
randomArray:array [0..7] of Integer;
iLoop,jLoop:Integer;
buf:Integer;
begin
for iLoop:=0 to 7 do
begin
Randomize;
randomArray[iLoop]:= Random(100);
end;
// 冒泡法排序
for jLoop:=1 to 7-1 do
begin
for iLoop:=0 to 7-jLoop do
begin
if randomArray[iLoop]>randomArray[iLoop+1] then
begin
buf:=randomArray[iLoop];
randomArray[iLoop]:=randomArray[iLoop+1];
randomArray[iLoop+1]:=buf;
end;
end;
end;

result:='';

//输出结果
for iLoop:=0 to 7 do
begin
Result:=Result+ IntToStr(randomArray[iLoop])+',';
end;
end;

procedure TForm1.topic4;
const
xPlural=14;
yPlural=14;
LoopCount=9;
var
x,y:Integer;
i,j:Integer;
xbuf,ybuf:Integer;
begin
y:=50;
ybuf:=LoopCount*yPlural+50;
for i:=1 to LoopCount do
begin
x:=50;
if i mod 2=1 then
begin
x:=x+(LoopCount-i)*round(xPlural/2);
y:=y+yPlural;
xbuf:=x;
for j:=1 to i do
begin
Self.Canvas.TextOut(x,y,'*');
x:=x+xPlural;
end;
for j:=1 to i do
begin
Self.Canvas.TextOut(xbuf,ybuf,'*');
xbuf:=xbuf+xPlural;
end;
ybuf:=ybuf-yPlural;
end;
end;
end;

procedure TForm1.btn_TestClick(Sender: TObject);
begin
ShowMessage(topic1(3,100,200));
ShowMessage(IntToStr(topic2(100)));
ShowMessage(topic3());
topic4();
end;