VB learns to judge the prime number in week 10 and generates a random number.

Source: Internet
Author: User
Public class form1 private sub textbox1_keypress (byval sender as object, byval e as system. windows. forms. keypresseventargs) handles textbox1.keypress if ASC (E. keychar) = 13 then dim I, m as integer, tag as Boolean M = Val (textbox1.text) Tag = true I = 2 do if (M MoD I) = 0 then tag = false label2.text = M & "not a prime number" exit do end if I = I + 1 loop while (2 <= I and I <= m-1) if I = m then label2.text = M & "is a prime number" end if end sub private sub textbox1_textchanged (byval sender as system. object, byval e as system. eventargs) handles textbox1.textchanged end subend class

Random Number Generation!

Public Class Form1    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        Dim i, a, s, max, min As Integer        max = 1 : min = 100        Label1.Text = ""        For i = 1 To 10            a = Int(Rnd() * 100 + 1)            Label1.Text &= a & "  "            If a > max Then max = a            If a < min Then min = a            s = s + a        Next        Label3.Text = max & Space(15) & min & Space(15) & s / 10    End SubEnd Class

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.