包含vb点虐 中loop的词条
VB中如何同时运行2个Do...Loop until...语句
真正同时运行两个Do Loop循环,只能靠多线程或者多进程来实现。若你正在用VB.Net里的Do Loop,那么可以很简单就能实现多线程了。 但如果你是在VB6里,只能用ActiveX.exe方式通过多个进程来实现这个同时Do Loop循环。
网站建设哪家好,找成都创新互联!专注于网页设计、网站建设、微信开发、成都微信小程序、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了思明免费建站欢迎大家使用!
说起来其实并不复杂,但需要你会写VB6的Class类里的那点知识即可。
VB点虐 Do ... Loop Until循环和Do Until ... Loop循环
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sum As Integer = 0
Dim i As Integer = 0
Do
i = i + 1
sum = sum + i
Loop Until sum 6000
MsgBox(i)
Debug.Print(sum)
End Sub
vb点虐 利用doloop until 计算从1开始的素数之和直到和不大于989为止
Module Module1
Sub Main()
Dim sum As Integer = 0
Dim Bound As Integer = 989
Dim num As Integer = 0
Dim cprime As Integer = 0
Do
num += 1
If IsPrame(num) Then
sum += num
cprime = num
End If
Loop Until sum Bound
Console.WriteLine(sum - cprime)
Console.ReadKey()
End Sub
'判断一个数是不是素数
Public Function IsPrame(ByVal num As Integer) As Boolean
If num = 1 Then Return False '素数的定义是大于1
For i = 2 To CType(Int(Math.Sqrt(num)), Integer)
If num Mod i = 0 Then Return False
Next
Return True
End Function
End Module
vb点虐 中如何设置进程的基本优先级
下面的代码示例说明了更改线程优先级的结果。创建两个线程,其中一个线程的优先级设置为 BelowNormal。两个线程在 while 循环中都增加一个变量,并运行一段设定的时间。
Option Explicit
Option Strict
Imports System
Imports System.Threading
Public Class Test
MTAThread _
Shared Sub Main()
Dim priorityTest As New PriorityTest()
Dim threadOne As Thread = _
New Thread(AddressOf priorityTest.ThreadMethod)
threadOne.Name = "ThreadOne"
Dim threadTwo As Thread = _
New Thread(AddressOf priorityTest.ThreadMethod)
threadTwo.Name = "ThreadTwo"
threadTwo.Priority = ThreadPriority.BelowNormal
threadOne.Start()
threadTwo.Start()
' Allow counting for 10 seconds.
Thread.Sleep(10000)
priorityTest.LoopSwitch = False
End Sub
End Class
Public Class PriorityTest
Dim loopSwitchValue As Boolean
Sub New()
loopSwitchValue = True
End Sub
WriteOnly Property LoopSwitch As Boolean
Set
loopSwitchValue = Value
End Set
End Property
Sub ThreadMethod()
Dim threadCount As Long = 0
While loopSwitchValue
threadCount += 1
End While
Console.WriteLine("{0} with {1,11} priority " _
"has a count = {2,13}", Thread.CurrentThread.Name, _
Thread.CurrentThread.Priority.ToString(), _
threadCount.ToString("N0"))
End Sub
End Class
文章标题:包含vb点虐 中loop的词条
文章来源:http://ybzwz.com/article/ddspsjc.html