IS THERE A Simple means of converting a PERL script into VBA?


Posted by Rob Miller on November 09, 2001 9:38 AM

Hello,

I am currently utilizing a PERL script to run a randomizer, which I have as yet been unable to create in VBA (where it pulls unique numbers for all numbers generated randomly), so I seperately use this PERL randomizer script to randomly pull a specific number of ID numbers out of a listing of numbers.

If there is not a way, is there a simple means of having VBA automatically open and EXECUTE a PERL script.. as opposed to simply opening up the Perl script as a text document as it does.

Ok, here is the PERL script I use for this randomizer (again it prompts you for a Text file that is in the same directory as this program, and then generates a seperate text file with the randomly generated numbers):

#*************
#* PROGRAM: sampler.pl *
#* This program requests an input file, and *
#* sample size. *
#* It creates a sample file, 'sample.txt' contain *
#* the records from the input file equal to sample.*
#***********************************************

print "Enter name of file to sample...................";
chomp($fl = <STDIN>);
open (FILE,$fl) or die "Unable to open input file $fl";
print "Enter number of samples desired................";
chomp($sample_size = <STDIN>);
while (<FILE>){
$universe++;
}
close(FILE);
open (FILE,$fl);
open (SAMPLE,">sample.txt") or die "Unable to open sample.txt";

srand();
$sample_cnt=$claim_cnt=0;

while (<FILE>){
$inrec = $_;
&sampler();
if ($sflag){
print SAMPLE $inrec;
}
}
print "universal file read..........$fl\n";
print "sample file written to....sample.txt\n";
print "universe record count........$universe\n";
print "sample records written.....$sample_cnt\n";


sub sampler {
$sflag = 0;
$ratio = ($sample_size - $sample_cnt) / ($universe - $claim_cnt);
$rand = rand();

if ($rand < $ratio){
$sample_cnt++;
$sflag = 1;
}

$claim_cnt++;
}



Posted by Pianchai Ongsritragul on February 15, 2002 2:35 AM

Re: Too Many Cell Formats

Try this! It 's OK but It will delete used format custom number as well.

Sub DeleteAllCustomFormat()

SendKeys ("%oe")
SendKeys "{tab}{end}{tab 2}{end}"
SendKeys ("%d")

For I = 1 To 4000
SendKeys "{end}"
SendKeys ("%d")
Next I

SendKeys "{enter}"

End Sub

Pianchai@hotmail.com