Last active
August 29, 2015 13:56
-
-
Save first087/8846033 to your computer and use it in GitHub Desktop.
RandomNumberEx on VB.NET 3.5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ | |
Partial Class frmRandomNumber | |
Inherits System.Windows.Forms.Form | |
'Form overrides dispose to clean up the component list. | |
<System.Diagnostics.DebuggerNonUserCode()> _ | |
Protected Overrides Sub Dispose(ByVal disposing As Boolean) | |
Try | |
If disposing AndAlso components IsNot Nothing Then | |
components.Dispose() | |
End If | |
Finally | |
MyBase.Dispose(disposing) | |
End Try | |
End Sub | |
'Required by the Windows Form Designer | |
Private components As System.ComponentModel.IContainer | |
'NOTE: The following procedure is required by the Windows Form Designer | |
'It can be modified using the Windows Form Designer. | |
'Do not modify it using the code editor. | |
<System.Diagnostics.DebuggerStepThrough()> _ | |
Private Sub InitializeComponent() | |
Me.Label1 = New System.Windows.Forms.Label() | |
Me.GroupBox1 = New System.Windows.Forms.GroupBox() | |
Me.nudMax = New System.Windows.Forms.NumericUpDown() | |
Me.nudMin = New System.Windows.Forms.NumericUpDown() | |
Me.Label2 = New System.Windows.Forms.Label() | |
Me.nudInterval = New System.Windows.Forms.NumericUpDown() | |
Me.Label4 = New System.Windows.Forms.Label() | |
Me.btnRun = New System.Windows.Forms.Button() | |
Me.lvResult = New System.Windows.Forms.ListView() | |
Me.ColumnHeader1 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) | |
Me.ColumnHeader2 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) | |
Me.GroupBox2 = New System.Windows.Forms.GroupBox() | |
Me.lblSummary = New System.Windows.Forms.Label() | |
Me.GroupBox1.SuspendLayout() | |
CType(Me.nudMax, System.ComponentModel.ISupportInitialize).BeginInit() | |
CType(Me.nudMin, System.ComponentModel.ISupportInitialize).BeginInit() | |
CType(Me.nudInterval, System.ComponentModel.ISupportInitialize).BeginInit() | |
Me.GroupBox2.SuspendLayout() | |
Me.SuspendLayout() | |
' | |
'Label1 | |
' | |
Me.Label1.Anchor = System.Windows.Forms.AnchorStyles.Top | |
Me.Label1.AutoSize = True | |
Me.Label1.Location = New System.Drawing.Point(22, 21) | |
Me.Label1.Name = "Label1" | |
Me.Label1.Size = New System.Drawing.Size(33, 13) | |
Me.Label1.TabIndex = 0 | |
Me.Label1.Text = "Min =" | |
' | |
'GroupBox1 | |
' | |
Me.GroupBox1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _ | |
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) | |
Me.GroupBox1.Controls.Add(Me.nudMax) | |
Me.GroupBox1.Controls.Add(Me.nudMin) | |
Me.GroupBox1.Controls.Add(Me.Label2) | |
Me.GroupBox1.Controls.Add(Me.Label1) | |
Me.GroupBox1.Location = New System.Drawing.Point(12, 12) | |
Me.GroupBox1.Name = "GroupBox1" | |
Me.GroupBox1.Size = New System.Drawing.Size(278, 52) | |
Me.GroupBox1.TabIndex = 1 | |
Me.GroupBox1.TabStop = False | |
Me.GroupBox1.Text = "Random range" | |
' | |
'nudMax | |
' | |
Me.nudMax.Anchor = System.Windows.Forms.AnchorStyles.Top | |
Me.nudMax.Location = New System.Drawing.Point(183, 19) | |
Me.nudMax.Maximum = New Decimal(New Integer() {100000, 0, 0, 0}) | |
Me.nudMax.Name = "nudMax" | |
Me.nudMax.Size = New System.Drawing.Size(74, 20) | |
Me.nudMax.TabIndex = 3 | |
Me.nudMax.Value = New Decimal(New Integer() {9999, 0, 0, 0}) | |
' | |
'nudMin | |
' | |
Me.nudMin.Anchor = System.Windows.Forms.AnchorStyles.Top | |
Me.nudMin.Location = New System.Drawing.Point(61, 19) | |
Me.nudMin.Maximum = New Decimal(New Integer() {100000, 0, 0, 0}) | |
Me.nudMin.Name = "nudMin" | |
Me.nudMin.Size = New System.Drawing.Size(74, 20) | |
Me.nudMin.TabIndex = 2 | |
' | |
'Label2 | |
' | |
Me.Label2.Anchor = System.Windows.Forms.AnchorStyles.Top | |
Me.Label2.AutoSize = True | |
Me.Label2.Location = New System.Drawing.Point(141, 21) | |
Me.Label2.Name = "Label2" | |
Me.Label2.Size = New System.Drawing.Size(36, 13) | |
Me.Label2.TabIndex = 1 | |
Me.Label2.Text = "Max =" | |
' | |
'nudInterval | |
' | |
Me.nudInterval.Anchor = System.Windows.Forms.AnchorStyles.Top | |
Me.nudInterval.Location = New System.Drawing.Point(102, 73) | |
Me.nudInterval.Maximum = New Decimal(New Integer() {1000000, 0, 0, 0}) | |
Me.nudInterval.Name = "nudInterval" | |
Me.nudInterval.Size = New System.Drawing.Size(74, 20) | |
Me.nudInterval.TabIndex = 2 | |
Me.nudInterval.Value = New Decimal(New Integer() {1000, 0, 0, 0}) | |
' | |
'Label4 | |
' | |
Me.Label4.Anchor = System.Windows.Forms.AnchorStyles.Top | |
Me.Label4.AutoSize = True | |
Me.Label4.Location = New System.Drawing.Point(45, 75) | |
Me.Label4.Name = "Label4" | |
Me.Label4.Size = New System.Drawing.Size(51, 13) | |
Me.Label4.TabIndex = 0 | |
Me.Label4.Text = "Interval =" | |
' | |
'btnRun | |
' | |
Me.btnRun.Anchor = System.Windows.Forms.AnchorStyles.Top | |
Me.btnRun.Location = New System.Drawing.Point(182, 70) | |
Me.btnRun.Name = "btnRun" | |
Me.btnRun.Size = New System.Drawing.Size(75, 23) | |
Me.btnRun.TabIndex = 3 | |
Me.btnRun.Text = "Run" | |
Me.btnRun.UseVisualStyleBackColor = True | |
' | |
'lvResult | |
' | |
Me.lvResult.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _ | |
Or System.Windows.Forms.AnchorStyles.Left) _ | |
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) | |
Me.lvResult.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2}) | |
Me.lvResult.Location = New System.Drawing.Point(12, 99) | |
Me.lvResult.Name = "lvResult" | |
Me.lvResult.Size = New System.Drawing.Size(278, 218) | |
Me.lvResult.TabIndex = 4 | |
Me.lvResult.UseCompatibleStateImageBehavior = False | |
Me.lvResult.View = System.Windows.Forms.View.Details | |
' | |
'ColumnHeader1 | |
' | |
Me.ColumnHeader1.Text = "Round" | |
' | |
'ColumnHeader2 | |
' | |
Me.ColumnHeader2.Text = "Random value" | |
Me.ColumnHeader2.Width = 184 | |
' | |
'GroupBox2 | |
' | |
Me.GroupBox2.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _ | |
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) | |
Me.GroupBox2.Controls.Add(Me.lblSummary) | |
Me.GroupBox2.Location = New System.Drawing.Point(12, 323) | |
Me.GroupBox2.Name = "GroupBox2" | |
Me.GroupBox2.Size = New System.Drawing.Size(278, 58) | |
Me.GroupBox2.TabIndex = 5 | |
Me.GroupBox2.TabStop = False | |
Me.GroupBox2.Text = "Summary" | |
' | |
'lblSummary | |
' | |
Me.lblSummary.AutoSize = True | |
Me.lblSummary.Location = New System.Drawing.Point(6, 16) | |
Me.lblSummary.Name = "lblSummary" | |
Me.lblSummary.Size = New System.Drawing.Size(60, 13) | |
Me.lblSummary.TabIndex = 0 | |
Me.lblSummary.Text = "lblSummary" | |
' | |
'Form1 | |
' | |
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) | |
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font | |
Me.ClientSize = New System.Drawing.Size(302, 393) | |
Me.Controls.Add(Me.GroupBox2) | |
Me.Controls.Add(Me.lvResult) | |
Me.Controls.Add(Me.btnRun) | |
Me.Controls.Add(Me.nudInterval) | |
Me.Controls.Add(Me.Label4) | |
Me.Controls.Add(Me.GroupBox1) | |
Me.Name = "Form1" | |
Me.Text = "Random Number Example" | |
Me.GroupBox1.ResumeLayout(False) | |
Me.GroupBox1.PerformLayout() | |
CType(Me.nudMax, System.ComponentModel.ISupportInitialize).EndInit() | |
CType(Me.nudMin, System.ComponentModel.ISupportInitialize).EndInit() | |
CType(Me.nudInterval, System.ComponentModel.ISupportInitialize).EndInit() | |
Me.GroupBox2.ResumeLayout(False) | |
Me.GroupBox2.PerformLayout() | |
Me.ResumeLayout(False) | |
Me.PerformLayout() | |
End Sub | |
Friend WithEvents Label1 As System.Windows.Forms.Label | |
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox | |
Friend WithEvents nudMax As System.Windows.Forms.NumericUpDown | |
Friend WithEvents nudMin As System.Windows.Forms.NumericUpDown | |
Friend WithEvents Label2 As System.Windows.Forms.Label | |
Friend WithEvents nudInterval As System.Windows.Forms.NumericUpDown | |
Friend WithEvents Label4 As System.Windows.Forms.Label | |
Friend WithEvents btnRun As System.Windows.Forms.Button | |
Friend WithEvents lvResult As System.Windows.Forms.ListView | |
Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader | |
Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader | |
Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox | |
Friend WithEvents lblSummary As System.Windows.Forms.Label | |
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Class frmRandomNumber | |
Public Sub New() | |
' This call is required by the designer. | |
InitializeComponent() | |
' Add any initialization after the InitializeComponent() call. | |
lblSummary.ResetText() | |
End Sub | |
Private Sub btnRun_Click(sender As Object, e As EventArgs) Handles btnRun.Click | |
Enabled = False | |
lvResult.Items.Clear() | |
lblSummary.ResetText() | |
Refresh() | |
Dim intMinRange As Integer = nudMin.Value | |
Dim intMaxRange As Integer = nudMax.Value + 1 | |
Dim intInterval As Integer = nudInterval.Value | |
Dim rnd As New Random() | |
Dim intMin As Integer = 0, intMax As Integer = 0 | |
For i As Integer = 1 To intInterval | |
Dim intRandom As Integer = rnd.Next(intMinRange, intMaxRange) | |
If i = 1 Then intMin = intRandom : intMax = intRandom | |
intMin = If(intMin > intRandom, intRandom, intMin) | |
intMax = If(intMax < intRandom, intRandom, intMax) | |
Dim item As New ListViewItem() | |
item.Text = i.ToString("#,##0") | |
item.SubItems.Add(intRandom.ToString("#,##0")) | |
lvResult.Items.Add(item) | |
lvResult.EnsureVisible(lvResult.Items.Count - 1) | |
lvResult.Update() | |
Next | |
lblSummary.Text = String.Format("Min value : {0:#,##0}{2}Max value : {1:#,##0}", intMin, intMax, vbCrLf) | |
Enabled = True | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment