# Thread: Randomly genrate a number in XX-XXXXXXX format

1. ## Re: Randomly genrate a number in XX-XXXXXXX format

Hi Sai,

Declare Function getRandom( ) as Integer
Declare Function getRandomNum( iDigits as Long) as String

Sub Main
Dim Result As Integer,myString1 as String,myString2 as String,myString as String

'Initially Recorded: 6/28/2006 3:45:04 PM
'Script Name: Test

myString1=getRandomNum(2)
myString2=getRandomNum(7)
myString=myString1 & "-" & myString2
MSgbox myString

End Sub

Function getRandom( ) as Integer

Randomize( ( ( 2^16 ) * Timer / 86400 )-( 2^15 ) )
getRandom = Int( 10 * Rnd )

End Function

'================================================= ========================

Function getRandomNum( iDigits as Long) as String

Dim sNum as String
Dim j as Integer

For j = 1 to iDigits
DelayFor 30
sNum = sNum + CStr( getRandom( ) )
Next j

getRandomNum = sNum

End Function

Thanks,
Kanth

2. ## Randomly genrate a number in XX-XXXXXXX format

Using Robot Random function I need to generate a number in xx-xxxxxxx format that is 9 numbers like Tax ID Number.
I appreciate if somebody can help me to do this.

Thanks
Sai

3. ## Re: Randomly genrate a number in XX-XXXXXXX format

Thanks a lot Kanth.
I did it in a different way before I checked your reply and it worked for me . I will try your way too.
Declare Function TIN_exFunction() as String
Sub main

DIM TIN as String
Call TIN_exFunction()
TIN = TIN_exFunction
Print TIN
End Sub

Function TIN_exFunction() as String
DIM X as Integer
DIM Y as Variant
DIM Str1 as String
DIM Str2 as String
DIM NUM1 as Variant
DIM NUM2 as Variant
DIM msgtext
DIM randomvalue
DIM TIN as String
For X = 1 to 3
Randomize timer()
randomvalue= Int(100*Rnd)
Num1 = randomvalue
Next X
For Y = 1 to 3
Randomize timer()
randomvalue= Int(11111110*Rnd)
Num2 = randomvalue
Next Y

Str1 = CStr(Num1)
Str2 = CStr(Num2)

TIN = Str1 + "-" +Str2
TIN_exFunction = TIN
End Function

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 06:59 AM.