Private Sub Command1_Click()
Dim a%, n%, i%, Sn$
n = InputBox(请输入n的值)
Randomize
a = Int(9 * Rnd + 1)
Print Tab(30); "n=" & n, " a = " & a; ""
Temp = a
Picture1.Print "Sn="; a;
For i = 1 To n - 1
Temp = Temp * 10 + a
Picture1.Print "+"; Temp;
Next
Print
End Sub
(这样比较合适吧)
dim Sn,a,n,i,m
m=0
Sn=0
a=int(rnd()*10)
n=text1.text
for i=1 to n
m=10^(i-1) *a+m
Sn=Sn+m
next i
(应该就是这样了,有点久没用VB,有点忘了)
Private Sub Command1_Click()
Dim n%, a%, Sn&, Tmp$, i%
n = InputBox("Input N= ")
Randomize
a = Int(Rnd * 10) + 1
Print "n=" & n, " a = " & a; ""
For i = 1 To n
Tmp = String(i, CStr(a))
Print Tmp
Sn = Sn + CInt(Tmp)
Next i
Print "Sn=" & Sn
End Sub
Private Sub Form_Click()
Dim sn&
a = Int(Rnd * (9 - 1 + 1) + 1)
n = Int(Rnd * (10 - 5 + 1) + 5)
Randomize
t = a
sn = t
For i = 1 To n - 1
t = t * 10 + a
sn = sn + t
Next i
Print "a="; a; ",n="; n; ",sn="; sn
End Sub
Dim a%, n%, i%, Sn%, Temp%
n = InputBox("Input N= ")
Randomize()
a = Int(9 * Rnd() + 1)
Temp = a
Sn = Temp
For i = 1 To n - 1
Temp = Temp * 10 + a
Sn = Sn + Temp
Next
Console.WriteLine(a)
Console.WriteLine(Sn)
运行了是OK的