-Register for Learning.
-Read forum rules before register.
-Register for see full topics.
*Active on Forum*

vBasic - Get Random Number

Share

Binushacker
member
member

Jumlah posting : 35
Reputation : 0
Join date : 17.05.13

vBasic - Get Random Number

Post by Binushacker on Thu Aug 28, 2014 5:07 pm

Buat module baru, namanya bebas, trus copy paste script berikut :


Code:
Option Explicit
Public Declare Function GetTickCount Lib "kernel32.dll" () As Long

Public Function GetRandomNumber(LowerVal As Long, UpperVal As Long, Optional EnableRepeat As Boolean = False) As Long
On Error Resume Next
Static LastRnd As Long
    GetRandomNumber = 1
    If UpperVal < LowerVal Then
          Dim TmpVal As Long
          TmpVal = UpperVal
          UpperVal = LowerVal
          LowerVal = UpperVal
    End If
    If UpperVal - LowerVal < 4 And EnableRepeat = False Then EnableRepeat = True
MakeRnd:
    Randomize GetTickCount * Timer
    GetRandomNumber = Int((UpperVal - LowerVal + 1) * Rnd + LowerVal)
    If EnableRepeat = False And GetRandomNumber = LastRnd Then GoTo MakeRnd
    LastRnd = GetRandomNumber
End Function

    Waktu sekarang Mon Dec 05, 2016 7:26 am