in reply to Flat File Database
I am providing below a code snippet replacement for the JOINT DATABASE TECHNOLOGY - DEMO, KJV Bible Navigator software. I have rewritten the TreeView Double Click EVENT so that instead of reading in each verse of a chapter individually (a read executed for each verse), I now have the code read in the entire chapter in one read execution. I use the unpack statement to separate out the individual verses. This I'm guessing is more efficient code? and may work faster across a Network? Anyway, it is here if you want to use it. Just delete the TVDblClick event from the original code and replace with the TVDblClick event code provided here. If anyone has access to a Network drive and wants to performance test the two different read methods (1 read per chapter vs. 1 read for each verse of a chapter), then that would be helpful for us to know which is faster.
################ sub TVDblClick { ################ my ($self, $x, $y) = @_; my $node = $self->HitTest($x,$y); $self->Select($node); my $parent_node = $self->GetParent($node); if ($node == 0 || $parent_node == 0) { return; } $RE->Text(""); my %parentinfo = $self->ItemInfo($parent_node); my ($bk, $bkname) = split(/:/,$parentinfo{-text}); my %nodeinfo = $self->ItemInfo($node); my ($abbrev, $string) = split(/ /,$nodeinfo{-text}); my ($chp, $range) = split(/:/,$string); my $outputfile="$PWD\\KJV_Bible_" . $bkname . "_Chp_" . $chp . ".rtf"; my $ret=0; open(BibleRTF,"> $outputfile") || do {$ret=1;}; if (! $ret) { BibleRTF->autoflush(1); #-- flush the output buffer each print } else { Win32::GUI::MessageBox($W1,"Can't open file\n$outputfile\nfor outpu +t\n$!", "KJV Bible Navigator - Error",16,); return; } my $key=$bk . "|" . $chp; my ($offset, $nbr_verses) = split(/,/,$BibleIDX{$key}); my $pos=SetFilePointer( $hFILE, $offset, [], FILE_BEGIN); #-- random a +ccess unless ( $pos ) { my $error = fileLastError(); my $msg = "Can't set file pointer at byte offset $offset within:\n" + . "$PWD\\KJV_Bible_SDBM.dat" . "\nat Book of $bkname chapter $chp verse 1\n" . $error; Win32::GUI::MessageBox($W1,$msg,"KJV Bible Navigator - Error",16,); close(BibleRTF); return; } my $BIB_Tmpl = ""; #-- build a template to unpack an entire chapter o +f verses for (my $i=1; $i<= $nbr_verses; $i++) { $BIB_Tmpl = $BIB_Tmpl . "A528, "; } chop $BIB_Tmpl; chop $BIB_Tmpl; #-- remove trailing ", " $nbr_chars=(528 * $nbr_verses); my $buff = "Hello Dolly"; $ret=ReadFile( $hFILE, $buff, $nbr_chars, [], [] ); #-- read in a whol +e chapter unless ( $ret ) { my $error = fileLastError(); my $msg = "Can't read input file:\n" . "$PWD\\KJV_Bible_SDBM.dat" . + "\nat Book of $bkname chapter $chp verses 1 to $nbr_verses\n" . + $error; Win32::GUI::MessageBox($W1,$msg,"KJV Bible Navigator - Error",16,); close(BibleRTF); return; } my @verses=(); @verses=unpack($BIB_Tmpl,$buff); print BibleRTF '{\rtf1\ansi\ansicpg1252\deff0\deflang1033\deflangfe103 +3' . '{\fonttbl{\f0\fswiss\fcharset0 Tahoma;}}' . '{\colortbl ;\red255\green0\blue0;}' . '\viewkind4\uc1\pard\f0\fs18' . "\n"; for (my $j=0; $j<$nbr_verses; $j++) { Win32::GUI::DoEvents(); #-- keep window from perhaps freezing u +p $verses[$j]=~s/ *$//; #-- remove trailing spaces from ea. ver +se $ver=$j+1; #print BibleRTF '\ul\b\i0\highlight1 ' print BibleRTF '\ul\b0\i\highlight0 ' . "$bkname $chp:$ver (KJV)" . '\par\ulnone\b\i0\highlight0' . $verses[$j] . '\par\par' . " +\n"; } print BibleRTF '}' . "\n"; close(BibleRTF); $RE->Load("$outputfile"); #-- Perform some Window Maintenance. #-- We don't want to Maximize Window because end-user may have adjuste +d size. Window1_Maint(); }