Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:15 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Parameters for Subs and Functions

Author Message
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1132
Posted: 07:52pm 11 Oct 2020
Copy link to clipboard 
Print this post

I have two questions about parameters passed to subroutines and functions.

1) The manual says
  Quote  When calling a subroutine you can supply less than the required number of values and in that case the missing values will be assumed to be either zero or an empty string. You can also leave out a value in the middle of the list and the same will happen.
However, it seems you can not skip an array.

Changing the example from the manual slightly:
DIM arg2$(10)

SUB MYSUB arg1, arg2$(), arg3
arg1 = arg1 + 1
arg3 = arg3 + 3
END SUB

' call the subroutine
MYSUB 23, , 55

END
generates the error "Error in line 9: Incompatible type:"

Is that just the way it is?

2) It seems the parameters must strictly match on dimension. If the sub or function declares a parameter as, say, a string, then there is no way to optionally pass a string _array_. (It would be up to the routine to figure out if the passed parameter is a simple variable or an array variable.)

Is that just the way it is? Is there a work around?

In my case, I want a routine that will return a string of data if a string is passed, or an array of strings if that is passed.

Perhaps I must change the simple string to "DIM a$(1)"
Visit Vegipete's *Mite Library for cool programs.
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1593
Posted: 08:41pm 11 Oct 2020
Copy link to clipboard 
Print this post

  vegipete said  Is that just the way it is?


IMHO yes! Until Peter or Geoff changed that.

  vegipete said  In my case, I want a routine that will return a string of data if a string is passed, or an array of strings if that is passed."

I don't see why you don't just use an array of strings in both cases?

Kind regards
Michael
causality ≠ correlation ≠ coincidence
 
mkopack73
Senior Member

Joined: 03/07/2020
Location: United States
Posts: 261
Posted: 10:07pm 11 Oct 2020
Copy link to clipboard 
Print this post

  twofingers said  
  vegipete said  Is that just the way it is?


IMHO yes! Until Peter or Geoff changed that.

  vegipete said  In my case, I want a routine that will return a string of data if a string is passed, or an array of strings if that is passed."

I don't see why you don't just use an array of strings in both cases?

Kind regards
Michael


You have to match the parameter list. You can't send it an array if it's expecting a singleton or vice versa.

I would say make your parameter take an array and then just pass in the string AS an array of size 1 and make the return value also an array of size 1.
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025