|
Forum Index : Microcontroller and PC projects : Parameters for Subs and Functions
| Author | Message | ||||
| vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1185 |
I have two questions about parameters passed to subroutines and functions. 1) The manual says However, it seems you can not skip an array. Changing the example from the manual slightly: DIM arg2$(10) generates the error "Error in line 9: Incompatible type:"SUB MYSUB arg1, arg2$(), arg3 arg1 = arg1 + 1 arg3 = arg3 + 3 END SUB ' call the subroutine MYSUB 23, , 55 END 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: GermanyPosts: 1769 |
IMHO yes! Until Peter or Geoff changed that. I don't see why you don't just use an array of strings in both cases? Kind regards Michael ‚My name is Ozymandias, king of kings Look on my works, ye Mighty, and despair!‘ Nothing beside remains. Round the decay Of that colossal wreck, boundless and bare The lone and ... |
||||
| mkopack73 Senior Member Joined: 03/07/2020 Location: United StatesPosts: 261 |
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. |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |