欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    VB常见20道编程代码.doc

    • 资源ID:33521982       资源大小:152.50KB        全文页数:14页
    • 资源格式: DOC        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    VB常见20道编程代码.doc

    -作者xxxx-日期xxxxVB常见20道编程代码【精品文档】哈哈哈20道编程代码1.1000以内的所有完数Private Sub Command1_Click() Dim n As Integer Dim i As Integer Dim s As Long For n = 1 To 1000 s = 1 For i = 2 To n - 1 If n Mod i = 0 Then s = s + i Next i If s = n Then Text1 = Text1 & n & " " If k Mod 5 = 0 Then Text1 = Text1 & vbCrLf End If Next nEnd SubPrivate Sub Command2_Click() EndEnd Sub2.百元买百鸡Private Sub Command1_Click()Dim i As IntegerDim j As IntegerFor i = 0 To 20 For j = 0 To 33 If 5 * i + 3 * j + (100 - i - j) * 1 / 3 = 100 Then Text1 = Text1 & "买" & CStr(i) & "只公鸡" & CStr(j) & "只母鸡" & CStr(100 - i - j) & "只小鸡" Text1 = Text1 & Chr(13) & Chr(10) End If Next jNext iEnd SubPrivate Sub Command2_Click() EndEnd Sub3. 不靠边元素和Private Sub Command1_Click()ClsRandomizeDim a(5, 5) As Integer, s%For i = 0 To 5 For j = 0 To 5 a(i, j) = Int(Rnd * 9) Print a(i, j) & "," Sum = Sum + a(i, j) Next j PrintNext ik = SumSum = 0For i = 0 To 5Sum = Sum + a(i, 0) + a(i, 5) + a(0, i) + a(5, i)Next iSum = Sum - a(0, 0) - a(5, 0) - a(5, 5) - a(0, 5)Text1 = k - SumEnd SubPrivate Sub Command2_Click() EndEnd Sub4.递归函数求斐波拉契数列Option ExplicitPrivate Sub Command1_Click() Dim a1, a2, b As Integer Dim i, n As Integer n = InputBox("显示数列的前N项") a1 = 1 For i = 1 To n b = a1 + a2 Text1.SelText = b & " " a1 = a2 a2 = b Next iEnd SubPrivate Sub Command2_Click() EndEnd Sub5.各位数之和Private Sub Command1_Click() Dim i As String Dim j% Dim s% i = Text1 For j = 1 To Len(i) st = Mid(i, j, 1) s = s + Val(st) Next j Text2 = sEnd SubPrivate Sub Command2_Click() EndEnd Sub6.回文数Private Sub Command1_Click() Dim x$, y$, c$, i% x = Text1 For i = 1 To Len(x) c = Mid(x, i, 1) y = c + y Next i If y = x Then Text2 = "x是回文数" Else Text2 = "x不是回文数" End IfEnd SubPrivate Sub Command2_Click() Text1 = "" Text2 = ""End SubPrivate Sub Command3_Click() EndEnd Sub7.级数求和Private Sub Command1_Click() Dim i As Integer, t As Long, s As Singlei = 0: s = o: t = 1Dos = s + 1 / ti = i + 1t = t * iText1 = sEnd SubPrivate Sub Command2_Click() EndEnd Sub8.矩阵的转置Option ExplicitOption Base 1Dim i As IntegerDim j As IntegerDim a() As IntegerDim n As IntegerPrivate Sub Command1_Click()n = Val(Text3)ReDim a(n, n) '动态数组For i = 1 To n For j = 1 To n a(i, j) = Int(10 * Rnd + 0) '随机数 Text1 = Text1 & a(i, j) & " " '一行 Next j Text1 = Text1 & Chr(13) & Chr(10) '多行Next iEnd SubPrivate Sub Command2_Click()Dim b() As Integern = Val(Text3)ReDim b(n, n)For i = 1 To n For j = 1 To n b(i, j) = a(j, i) '转置 Text2 = Text2 & b(i, j) & " " '一行 Next j Text2 = Text2 & Chr(13) & Chr(10) '多行Next iEnd SubPrivate Sub Command3_Click()Text1 = ""Text2 = ""Text3 = "" '清除End SubPrivate Sub Command4_Click()End '结束End SubPrivate Sub Form_Load()Text1 = ""Text2 = ""Text3 = "" '清除End Sub9.靠边元素和Private Sub Command1_Click()ClsRandomizeDim a(5, 5) As IntegerFor i = 0 To 5 For j = 0 To 5 a(i, j) = Int(Rnd * 9) Print a(i, j) & "," Sum = Sum + a(i, j) Next j PrintNext iSum = 0For i = 0 To 5Sum = Sum + a(i, 0) + a(i, 5) + a(0, i) + a(5, i)NextSum = Sum - a(0, 0) - a(5, 0) - a(5, 5) - a(0, 5)Text1 = SumEnd SubPrivate Sub Command2_Click() EndEnd Sub10.冒泡排序Option ExplicitOption Base 1Dim a(10) As IntegerDim i As IntegerPrivate Sub Command1_Click()For i = 1 To 10 a(i) = Int(90 * Rnd + 10) Text1 = Text1 & Str(a(i) & " " If i Mod 5 = 0 Then Text1 = Text1 & Chr(13) & Chr(10)Next iEnd SubPrivate Sub Command2_Click()Dim j As IntegerDim t As IntegerFor i = 1 To 9 For j = 1 To 10 - i If a(j) < a(j + 1) Then t = a(j) a(j) = a(j + 1) a(j + 1) = t End If Next jNext iFor i = 1 To 10 Text2 = Text2 & Str(a(i) & " " If i Mod 5 = 0 Then Text2 = Text2 & Chr(13) & Chr(10)Next iEnd SubPrivate Sub Command3_Click()Text1 = ""Text2 = ""End SubPrivate Sub Command4_Click()EndEnd Sub11.逆序数Private Sub Command1_Click() Dim a As String Dim i% Dim s As String a = Text1 For i = 1 To Len(a) st = Mid(a, i, 1) s = st + s Next i Text2 = sEnd SubPrivate Sub Command2_Click() EndEnd Sub12.判断素数Private Sub Command1_Click() Dim n As Integer Dim i As Integer n = Val(Text1) If n = 1 Then MsgBox (CStr(n) & "是素数") Else For i = 2 To n - 1 If n Mod i = 0 Then Exit For Next i If i = n Then MsgBox (CStr(n) & "是素数") Else MsgBox (CStr(n) & "不是素数") End If End IfEnd SubPrivate Sub Command2_Click() Text1 = ""End SubPrivate Sub Command3_Click() EndEnd Sub13.求阶乘(递归)Private Function f(ByVal n As Long) As Long Dim i As Integer f = 1 If n = 0 Or n = 1 Then f = 1 Else For i = 1 To n f = f * i Next i End IfEnd FunctionPrivate Sub Command1_Click() Dim n As Long n = Val(Text1) Text2 = f(n)End SubPrivate Sub Command2_Click() Text1 = "" Text2 = ""End SubPrivate Sub Command3_Click() EndEnd Sub14.求质因子Private Sub Command1_Click() Dim n%, i%, m% n = Val(Text1) For i = 1 To n If i = 1 Then Else If n Mod i = 0 Then For m = 2 To i - 1 If i Mod m = 0 Then Exit For Next m If m = i Then Picture1.Print i, End If End If End If Next iEnd SubPrivate Sub Command2_Click() Text1 = ""End SubPrivate Sub Command3_Click() EndEnd Sub15.水仙花数Private Sub Command1_Click()Dim a, b, c As Integer For a = 0 To 9 For b = 0 To 9 For c = 1 To 9 If a 3 + b 3 + c 3 = a + 10 * b + 100 * c Then MsgBox 100 * c + 10 * b + a End If Next c Next b Next a End SubPrivate Sub Command2_Click() EndEnd Sub16.顺序查找Option ExplicitOption Base 1Dim a(10) As IntegerDim i As IntegerPrivate Sub Command1_Click()For i = 1 To 10 a(i) = Int(90 * Rnd + 10) Text1 = Text1 & Str(a(i) If i Mod 5 = 0 Then Text1 = Text1 & Chr(13) & Chr(10)Next iEnd SubPrivate Sub Command2_Click()Dim x As Integerx = Val(Text2)For i = 1 To 10 If a(i) = x Then Exit ForNext iIf i <= 10 Then Text3 = Str(x) + "在第" + Str(i) + "个位置"Else Text3 = "没有找到"End IfEnd SubPrivate Sub Command3_Click()Text1 = ""Text2 = ""Text3 = ""End SubPrivate Sub Command4_Click()EndEnd Sub17.随机10个整数最值,均值,和Dim i As IntegerDim a(10) As IntegerPrivate Sub Command1_Click()RandomizeFor i = 1 To 10 a(i) = Int(90 * Rnd + 10)Next iFor i = 1 To 10 Text1 = Text1 & a(i) & " "Next iEnd SubPrivate Sub Command2_Click()Dim k As IntegerDim l As IntegerDim s As Integerk = a(1)For i = 2 To 10 If a(i) > k Then k = a(i)Next iText2 = kl = a(1)For i = 2 To 10 If a(i) < l Then l = a(i)Next iText3 = ls = 0For i = 1 To 10 s = s + a(i)Next iText5 = sText4 = s / 10End SubPrivate Sub Command3_Click()EndEnd SubPrivate Sub Form_Load()End Sub18.字符统计Private Sub Command1_Click() Dim s As String, i%, m As String, n% s = Text1 n = 0 For i = 1 To Len(s) m = Mid(s, i, 1) If m >= "a" And m <= "z" Then n = n + 1 End If Next i Text2 = nEnd SubPrivate Sub Command2_Click() EndEnd Sub19.最大公约数Private Sub Command1_Click() Dim m As Integer Dim n As Integer Dim k As Integer m = Val(Text1) n = Val(Text2) Do k = m Mod n m = n n = k Loop Until k = 0 Text3 = CStr(m)End SubPrivate Sub Command2_Click() Text1 = "" Text2 = "" Text3 = ""End SubPrivate Sub Command3_Click() EndEnd Sub20.最小公倍数Option ExplicitPrivate Sub Command1_Click() Dim m%, n%, k% Dim m1%, n1% Dim s% m = Val(Text1): n = Val(Text2) m1 = m: n1 = n Do k = m Mod n m = n n = k Loop Until k = 0 s = m1 * n1 / m Text3 = s End SubPrivate Sub Command2_Click() Text1 = "" Text2 = "" Text3 = ""End SubPrivate Sub Command3_Click() EndEnd Sub【精品文档】

    注意事项

    本文(VB常见20道编程代码.doc)为本站会员(豆****)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开