subroutine

Subroutine unexpectedly ends when a Workbook is closed

故事扮演 提交于 2019-12-24 13:08:22
问题 my problem today is a part of a subroutine that inexplicably breaks its execution when a Workbook is closed. I have written the following code: Public Const Pi As Double = 3.14159265358979 Public Const Rad As Double = Pi / 180 Public CalcBook As Workbook Public FilePath As String, Files() As String Public FreqArray() As Integer Sub Main() Dim ChooseFolder As Object, FilePath As String, StrFile As String Dim i As Integer, j As Integer, k As Integer, x As Integer Dim DirNum As Integer, HNum As

How to pass a subroutine as a parameter to another subroutine

会有一股神秘感。 提交于 2019-12-24 08:38:43
问题 I want to pass a subroutine as a parameter to another subroutine. Subroutine question should be passed as parameter to subroutine answer ? How can I do it with Perl? question(); sub question { print "question the term"; return(); } sub answer() { print "subroutine question is used as parameters"; return(); } 回答1: You can take subroutine reference using \&subname syntax and then, you can easily pass it to other subroutine as arguments like a scalar. This is documented in perlsub and perlref.

Fortran Subroutine Pointers for Mismatching Array Dimensions

99封情书 提交于 2019-12-24 02:22:27
问题 I'm having a problem with Fortran and function/subroutine pointers. I have two functions that take an array as an argument. In f1 it is a(n,n), in f2 it's a(n*n). When I call the subroutine manually, I can do this with the same array: real :: a(5, 5) call f1(a, 5) call f2(a, 5) But when I try to do this with a pointer, the compiler throws it back at me with this error: ptr => f2 1 Error: Interface mismatch in procedure pointer assignment at (1): Type/rank missmatch in argument 'a' Is there a

Redim Preserve gives 'subscript out of range'

折月煮酒 提交于 2019-12-23 23:17:10
问题 I want to Redim Preserve an array I keep getting the error 'subscript out of range'. I am aware of the fact that only the size of the last dimension can be changed. That is exactly what I am doing. What is going wrong over here? The type of the array is Variant . BmMatrix = Sheets("BENCH").Range("a60", ActiveSheet.Range("a60").End(xlDown).End(xlToRight)) 'totaal gewicht per subdeel in array wegschrijven Dim aBmMatrix() aBmMatrix = BmMatrix rij = UBound(BmMatrix, 1) kol = UBound(BmMatrix, 2) +

How to call and use a subroutine inside another subroutine in fortran?

狂风中的少年 提交于 2019-12-23 18:30:32
问题 I am doing a program in which the main contains many subroutines and functions. For constructing one of these subroutines of the main (let's say subroutine A) I need to make use of another subroutine (let's say B). My question is, how can I make subroutine A call and use subroutine B? I am a beginner and I have searched a lot but found nothing that I understand clearly... Any help would be appreciated, thanks in advance! 回答1: Example of layout, in one file: module MySubs contains subroutine A

Global Variable, subroutine variable Question in Perl

久未见 提交于 2019-12-23 12:27:22
问题 How can I transfer the subroutine variable value into another subroutine variable, Can I use global variable. sub foo(){ my $myvar = "Hello"; } sub foo1(){ my $myvar1 = $myvar; # how can I get the "Hello" from $myvar. } I tried to use package and global variable, but failed. Package Bar; our $bar; Thank you. 回答1: You could declare the variable in a scope that includes the 2 functions: { my $myvar sub foo{ $myvar = "Hello"; } sub foo1{ my $myvar1 = $myvar; } } That is not really elegant though

Common block and subroutine argument

六眼飞鱼酱① 提交于 2019-12-23 03:41:42
问题 If I have a variable called var which is in a common block named myCB may I use the same name to pass an argument between two other subroutines which are not using the common block myCB ? The code is like below. Subroutine SR1(Var) !something here using Var end Subroutine SR1 Subroutine SR2() .... Call SR1(B) .... end Subroutine SR2 Subroutine SR3() common \myCB\ Var ... ! something using the other Var shared with SR4 ...... end Subroutine SR3 Subroutine SR4() common \myCB\ Var .... ... !

How can I distinguish between an argument that was not passed and one that was passed with a false value?

倾然丶 夕夏残阳落幕 提交于 2019-12-22 04:37:06
问题 I am trying to figure the best way to differeniate in Perl between cases where an argument has not been passed, and where an argument has been passed as 0, since they mean different things to me. (Normally I like the ambiguity, but in this case I'm generating SQL so I want to replace undefined args with NULL, but leave 0 as 0.) So this is the ambiguity: sub mysub { my $arg1 = shift; if ($arg1){ print "arg1 could have been 0 or it could have not been passed."; } } And so far, this is my best

Using a variable from outer scope in a sub called in foreach

♀尐吖头ヾ 提交于 2019-12-22 00:52:39
问题 I am using cygwin. What this script does is load the iphone pics that I have loaded into a directory on the desktop. It opens it up in image viewer, to let me take a look at the picture. system("cygstart $dirname/$oldfile") ; Then it gives me the option to rename the picture. It is throwing errors though, and not renaming the picture. Use of uninitialized value $oldfile in concatenation (.) or string at ./rename_image.pl line 29, <STDIN> line 6. oldfile is a global varaible, the functions

Append a new column to file in perl

孤者浪人 提交于 2019-12-22 00:47:33
问题 I've got the follow function inside a perl script: sub fileSize { my $file = shift; my $opt = shift; open (FILE, $file) or die "Could not open file $file: $!"; $/ = ">"; my $junk = <FILE>; my $g_size = 0; while ( my $rec = <FILE> ) { chomp $rec; my ($name, @seqLines) = split /\n/, $rec; my $sec = join('',@seqLines); $g_size+=length($sec); if ( $opt == 1 ) { open TMP, ">>", "tmp" or die "Could not open chr_sizes.log: $!\n"; print TMP "$name\t", length($sec), "\n"; } } if ( $opt == 0 ) {