Universal data type Function
Comments
-
Could you explain some more? I do not fully understand. If the array contains something in particular, or just has data, not null values.Lee Justice0
-
lemster68 said:Could you explain some more? I do not fully understand. If the array contains something in particular, or just has data, not null values.
I have function which returns TRUE if num array contains specific number. Like this, for example:FUNC bool IfArrayContains(num nArray{*}, num nValue)
VAR bool contains:=FALSE;
VAR num i := 1;
WHILE i<=Dim(nArray, 1) AND contains=FALSE DO
IF nArray{i}=nValue THEN
contains:=TRUE;
ENDIF
incr i;
ENDWHILE
RETURN contains;
ENDFUNC
And my target is to make this function universal for multiple datatypes.
Something like this:FUNC bool IfArrayContains(ANYTYPE# Array{*}, ANYTYPE# Value)
IF Type(Array)=Type(Value) THEN
......
......
ELSEIF .......................
And so on.
0 -
OK, so you do not necessarily need ALL datatypes, just some? You could use switch parameters and the function Present() to see which types were passed in. I would also suggest to change your WHILE into FOR loop.Lee Justice0
-
in other words, I want ANYTYPE# as an input parameter
But it causes syntax error.0 -
lemster68 said:OK, so you do not necessarily need ALL datatypes, just some? You could use switch parameters and the function Present() to see which types were passed in. I would also suggest to change your WHILE into FOR loop.
Edit: And yes, you are right. Put RETURN into FOR loop is better.0 -
I was suggesting switch type argument, not in parameter. How many datatypes do you want? Just some or All?
Lee Justice0 -
I mean this.0 -
OK, you really got me thinking now. Let's start by making a record of all the datatypes.
A parameter reference may mean the entire parameter, an element of a parameter (array) or a component of a parameter (record).
If they are all listed in a record, then you can pass it in as a component of the record which lists all datatypes.
Next issue is the second parameter...Lee Justice0 -
So what you are seeing there is that IF you use an atomic type, THEN it can be anytype. Not that there is an anytype#. I started something in RS with the Record, man there are a lot of types! Too many and most would be of no use to check (In my opinion). It was not working like that anyway. So I went back to my earlier suggestion of using switches, you do not have to use all of them, just the one you want. As a matter of fact, you do not have to use any of them. But then the function will do nothing. I put together a little template with three common datatypes which I seem to think that you would want to check. Here it is:
FUNC bool check(\switch swbool,\switch swTRUE|switch swFALSE, \switch swnum, num nArray{*}, VAR num nValue, \switch swString, VAR string stArray{*}, VAR string stString) IF Present(swbool) THEN ! this is one way to do it with more switches ! simple for bool operation IF Present(swTRUE) THEN ! evaluate here to match the value for TRUE ELSEIF Present(swFalse) THEN ! evaluate here to match the value for FALSE ENDIF ENDIF IF Present(swnum) THEN ! evaluate here to match the value passed by nValue FOR i FROM 1 TO Dim(nArray, 1) DO IF nArray{i}=nValue THEN RETURN TRUE; ENDIF ENDFOR ENDIF IF Present(swString) THEN ! evaluate here to match the value passed by stString FOR i FROM 1 TO Dim(stArray, 1) DO IF stArray{i}=stString THEN RETURN TRUE; ENDIF ENDFOR ENDIF ENDFUNC
Lee Justice0 -
Yes, I used something similar to what you put here. Sure, there are a lot of useless types. Good point. So, commonly used atomic types (num, dnum, string - bool is useless because it has only 2 values and so there is no need to look for a specific value in the array - other types are aliases that can be interchanged or non-value data types - RECORD types like robtarget , jointtarget, etc., you usually don't need to store them in array and look for a specific value), I thought I could use some reference or implicit data type or something. But I did some research and it's not possible. Anyway, thank you for your help.0
-
You are quite welcome.Lee Justice0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 316 IRC5
- 61 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 798 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings