ZKX's LAB

VB编程:要求程序能从2010300401~2010300430中随机抽取一个数字,并在窗体上打印出来。 vb编程随机抽取数字 不重复

2020-07-24知识9

VB随机抽取不重复数据如何实现? 用个数组每生成一个新数字的时候与前几个做比较如果重复的话返回重新生产如何用VB从几个文字中随机不重复抽取三个文字组成一个名字 Dim str As String,tmp As String,strx As StringDim n As Integer,i As IntegerRandomizestr=\"澳三地附近哦啊决定For i=0 To 2n=Int(Rnd()*Len(str))+1tmp=Mid(str,n,1)str=Replace(str,tmp,\"\")strx=strx&tmpNextMsgBox strxVB 点击命令按钮1,从1-10中随机抽取3个不重复的数,如何写代码 Private Sub Command1_Click()Dim a(2),i,jLabel1.Caption=\"For i=0 To 2Doa(i)=Int(Rnd*9)+1For j=0 To iIf i<;>;j And a(i)=a(j)Then Exit ForNextLoop Until j>;iLabel1.Caption=Label1.Caption&a(i)&IIf(i,;NextEnd Sub1楼 对的 只是两个地方 没注意 可能是太着急了用vb怎样生成10个不重复的(1到10)随机数? Private Sub Command1_Click()Dim a(9)As IntegerFor i=0 To 9way1:Randomizea(i)=Int(Rnd()*10)+1If i>;1 ThenFor p=0 To i-1If a(p)=a(i)Then‘与前面的对比,如果有重复,重新随机GoTo way1End IfNext pEnd IfPrint a(i)’打印Next iEnd Sub

#dim#随机数

随机阅读

qrcode
访问手机版