June 26, 2024, 06:42:19 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Unexpected RETURN Warning upon compiling a SUB

Started by EvangelMike, March 04, 2009, 04:44:40 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

EvangelMike

March 04, 2009, 04:44:40 PM Last Edit: March 04, 2009, 04:55:06 PM by EvangelMike
Greetings! When I compiled the following code as a DLL, Unexpected RETURN Warning, which surprised me since I do not want my Sub to return a value. There were no other errors indicated in the compilation (as shown below).


export GetMaxInvComp
SUB GetMaxInvComp(MaxInsInv:Double BYREF, SrCount:Double BYREF, K:INT BYREF, InsiderInv01:Double, InsiderInv02:Double, InsiderInv03:Double, InsiderInv04:Double, InsiderInv05:Double, InsiderInv06:Double, InsiderInv07:Double, InsiderInv08:Double,InsiderInv09:Double,InsiderInv10:Double,InsiderInv11:Double,InsiderInv12:Double, InsiderInv13:Double, InsiderInv14:Double, InsiderInv15:Double, InsiderInv16:Double, InsiderInv17:Double, InsiderInv18:Double, InsiderInv19:Double, InsiderInv20:Double, InsiderJrSr01:String, InsiderJrSr02:String, InsiderJrSr03:String, InsiderJrSr04:String, InsiderJrSr05:String, InsiderJrSr06:String, InsiderJrSr07:String, InsiderJrSr08:String, InsiderJrSr09:String, InsiderJrSr10:String, InsiderJrSr11:String, InsiderJrSr12:String, InsiderJrSr13:String, InsiderJrSr14:String, InsiderJrSr15:String, InsiderJrSr16:String, InsiderJrSr17:String, InsiderJrSr18:String, InsiderJrSr19:String, InsiderJrSr20:String, LstRowData:Int)

TYPEDEF bool INT
Dim J As Int
Dim JMax As Int
Dim MaxSrFlgOK As bool
Dim MaxInsJrSr As String
Dim InsiderInv[1, 20] As Double
Dim InsiderJrSr[1, 20] As String

InsiderInv[1] = InsiderInv01
InsiderInv[2] = InsiderInv02
InsiderInv[3] = InsiderInv03
InsiderInv[4] = InsiderInv04
InsiderInv[5] = InsiderInv05
InsiderInv[6] = InsiderInv06
InsiderInv[7] = InsiderInv07
InsiderInv[8] = InsiderInv08
InsiderInv[9] = InsiderInv09
InsiderInv[10] = InsiderInv10
InsiderInv[11] = InsiderInv11
InsiderInv[12] = InsiderInv12
InsiderInv[13] = InsiderInv13
InsiderInv[14] = InsiderInv14
InsiderInv[15] = InsiderInv15
InsiderInv[16] = InsiderInv16
InsiderInv[17] = InsiderInv17
InsiderInv[18] = InsiderInv18
InsiderInv[19] = InsiderInv19
InsiderInv[20] = InsiderInv20

InsiderJrSr[1] = InsiderJrSr01
InsiderJrSr[2] = InsiderJrSr02
InsiderJrSr[3] = InsiderJrSr03
InsiderJrSr[4] = InsiderJrSr04
InsiderJrSr[5] = InsiderJrSr05
InsiderJrSr[6] = InsiderJrSr06
InsiderJrSr[7] = InsiderJrSr07
InsiderJrSr[8] = InsiderJrSr08
InsiderJrSr[9] = InsiderJrSr09
InsiderJrSr[10] = InsiderJrSr10
InsiderJrSr[11] = InsiderJrSr11
InsiderJrSr[12] = InsiderJrSr12
InsiderJrSr[13] = InsiderJrSr13
InsiderJrSr[14] = InsiderJrSr14
InsiderJrSr[15] = InsiderJrSr15
InsiderJrSr[16] = InsiderJrSr16
InsiderJrSr[17] = InsiderJrSr17
InsiderJrSr[18] = InsiderJrSr18
InsiderJrSr[19] = InsiderJrSr19
InsiderJrSr[20] = InsiderJrSr20

MaxInsInv = 0.0
' Initialize MaxInsJrSr to "DIR"
MaxInsJrSr = "DIR"
MaxSrFlgOK = False

For J = 1 To K
   If (InsiderInv[J] - MaxInsInv > 0.0) And (InsiderJrSr[J] <> "DIR") Then
      JMax = J
      MaxInsInv = InsiderInv[J]
      MaxInsJrSr = InsiderJrSr[J]
   End If
Next J
SrCount = 0.0
For J = 1 To K
  If (InsiderInv[J] >= 15000.0) Then
     If (InsiderJrSr[J] = "SR") Or (InsiderJrSr[J] = "xc") Then
        SrCount = SrCount + 1.0
     Else
        SrCount = SrCount + 0.5
     End If
  End If
Next J

' Set the Max amount found to 0 and repeat search for find next
' bigger Insider activity. I do not want to invest more than the
' 2nd largest insider 7 month purchase.
InsiderInv[JMax] = 0.0
MaxSrFlgOK = (MaxInsJrSr = "SR") Or (MaxInsJrSr = "xc")
MaxInsInv = 0.0
' The following logic ensures that if the largest purchases were made by a DIR,
' then we will invest no more than the largest amount invested by a SR or xc.
If MaxSrFlgOK Then   ' Largest purchase was by a SR
    For J = 1 To K
       If (InsiderInv[J] - MaxInsInv > 0.0) And (InsiderJrSr[J] <> "DIR") Then
          MaxInsInv = InsiderInv[J]
       End If
    Next J
Else   ' Largest purchase was by a DIR
    For J = 1 To K
       If InsiderInv[J] - MaxInsInv > 0.0 And ((InsiderJrSr[J] = "SR") Or (InsiderJrSr[J] = "xc")) Then
          MaxInsInv = InsiderInv[J]
       End If
    Next J
End If
ENDSUB


When I did a BUILD > Build Single, the result was:

Compiling...
GetMaxInvComp.eba
File: C:\ExcelDLLs\GetMaxInvComp.eba (99) Warning: RETURN value expected. - ENDSUB
No Errors
Generating Exports

Linking...
Emergence Linker v1.11 Copyright ÂÃ,© 2006 Ionic Wind Software
Generating C:\ExcelDLLs\GetMaxInvComp.dll
Build completed

Why did I get the RETURN warning? My Sub does not return a value. Thanks!
Also is there a prettier way of writing the parameter list? I tried breaking it up by using _ (underscore, space) but that gave all sorts of compillation errors.
Perhaps I am supposed to leave a space before or after the underscore--I was not sure.
May you have a blessed day.

Sincerely,

Michael D Fitzpatrick

jsanders

Michael,

Do you have a declare statement for the subroutine somewhere?  I believe there is a limit on the number of parameters a subroutine may have, but you would have to wait until tomorrow when Paul returns to ask.   If this is related to your previous questions then you should be using the proper array definitions, using the API functions that Paul gave you to access a SafeArray is not very difficult once you learn how.

I have edited your post to put the code into proper forum code tags, otherwise it is extremely difficult to read.  Please use this feature of the forum when posting code sections.

Regards,
James Sanders

EvangelMike

March 04, 2009, 05:06:35 PM #2 Last Edit: March 04, 2009, 05:12:59 PM by EvangelMike
Hi James:
According to the User's Guide: "Emergence BASIC uses a two pass compiler so it is not strictly necessary to declare a SUB only used in a single source file. It is supported both for backwards compatibility and readability." Since I only have a single source file, I did not think I needed a DECLARE. This current SUB does not import or export any arrays. That will have to wait until I get up to speed on SAFEARRAYS (unless someone on the list wants to volunteer how my EXCEL VBA code and/or Emergence Basic code needs to be modified to pass an array from Excel to my Emergence Basic DLL). Also How would I find out the limit on the number of subroutine parameters?

Sincerely,

Michael D Fitzpatrick

PS: Re the number of sub parameters, the user's guide only says: "The variables defined in your subroutine, or defined in the SUB statement are called local variables. A local variable is only accessible while your subroutine is being executed. Once control is returned to the code that called the subroutine the local variables do not exist. All local variables are stored in a special area of memory called the stack.

The stack size is set by the 'Advanced' tab on the Executable Options dialog or the Project Options dialog.  The default stack commit size is set to 32K and indicates how large the size of the local variables in any one subroutine can be.  If you exceed this size the compiler will generate a warning message so you can adjust as needed.

The RETURN statement can be omitted from the subroutine if the subroutine does not return a value.   EBASIC will insert the return statement when it encounters the ENDSUB statement."

EvangelMike

Greetings! I was wondering if the parameter list might have parameters of the same type grouped by type as in the following or something similar. This looks much nicer and shorter. Thanks! May you have a blessed day.

SUB GetMaxInvComp(MaxInsInv:Double BYREF, SrCount:Double BYREF, K:INT BYREF, InsiderInv01, InsiderInv02, InsiderInv03, InsiderInv04, InsiderInv05, InsiderInv06, InsiderInv07, InsiderInv08,InsiderInv09,InsiderInv10,InsiderInv11,InsiderInv12, InsiderInv13, InsiderInv14, InsiderInv15, InsiderInv16, InsiderInv17, InsiderInv18, InsiderInv19, InsiderInv20:Double, InsiderJrSr01, InsiderJrSr02, InsiderJrSr03, InsiderJrSr04, InsiderJrSr05, InsiderJrSr06, InsiderJrSr07, InsiderJrSr08, InsiderJrSr09, InsiderJrSr10, InsiderJrSr11, InsiderJrSr12, InsiderJrSr13, InsiderJrSr14, InsiderJrSr15, InsiderJrSr16, InsiderJrSr17, InsiderJrSr18, InsiderJrSr19, InsiderJrSr20:String, LstRowData:Int)

Sincerely,

Michael Fitzpatrick

LarryMc

Quote from: EvangelMike on March 04, 2009, 05:28:51 PM
.. I was wondering if the parameter list might have parameters of the same type grouped by type as in the following or something similar. This looks much nicer and shorter

No

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

EvangelMike

Greetings! Re the number of parameters a function may take, I found the following in one of the Forum Postings:

"   CALL
ÂÃ,« on: December 22, 2006, 11:45:03 AM ÂÃ,»   
________________________________________
hello,
i want call a function in memory, like CALL(functionsadress, param1....paramx).
is there a way in the API ? the callwindowproc - function only has 4 parameters,
but i need more.



Paul Turley
Administrator
Hero Member
     
           Re: CALL
ÂÃ,« Reply #1 on: December 22, 2006, 12:39:10 PM ÂÃ,»   
________________________________________
Just use an indirect function.  You have to declare it first.

declare mymemfunc(a as int, b as float, c as word)

Then tell Emergence to call an address using that template.

!<mymemfunc>functionsaddress( 1, 2.2, 3)

You can use as many parameters as you want, I used three just for demonstration purposes."

So it may be that there is no limitation (other than stack size) on the number of parameters a function can take.

May you have a blessed day.

Sincerely,

Michael D Fitzpatrick

EvangelMike

Greetings! Although there probably is no limit on the max number of parameters in a function, there may well be a limitation on the number of characters in the parameter list. Is anyone aware of such a limit? Thanks in advance for your help. May you have a blessed day.

Sincerely,

Michael D Fitzpatrick

Ionic Wind Support Team

You know, I was sleeping when James called, but since you REFUSE to wait until tomorrow....

James is correct, there is a limit of 25 parameters for a subroutine, and in the many years I have made these languages (since 1991) no one has ever exceeded it, or needed to exceed it.  You are approaching the problem completely the wrong way and need to take the time to learn how to do it correctly.  Or perhaps if you ask nicely Sapero will help you out.

Passing 40+ parameters to a subroutine is just insane, and will slow your program down to the speed of an interpreter since pushing parameters onto the stack takes an amount of time equal to O(n)  Whereas passing a pointer to a SafeArray takes an amount of time equal to O(1), look it up in a software engineering book, or search google to see what I am talking about.

Use Sapero's include files to get the declares needed for accessing SafeArrays and be done with the problem! 

And the next time someone tells you to wait until tomorrow, please listen to them. I get annoyed easily when I am sick, and people don't use the information I have given them.

Paul.





Ionic Wind Support Team

EvangelMike

Dear Sapero,
   Paul said that if I ask nicely that you would provide me with the Include files I need to get the declares needed for accessing SafeArrays.
When you have the opportunity, please point me to these Include files (hopefully with instructions on how to use them). Thanks! May you have a blessed day.

Sincerely,

Michael Fitzpatrick