06-12-2024, 11:16 PM
You can't use User Defined Types as the function return itself, but you can use them as a parameter and pass the value back and forth.
An example with your code:
As you can see, you can pass those values via parameter; just not as a return through the function itself. (Which might make it just easier to use a SUB, as I've included above as a demo for you, as well. )
An example with your code:
Code: (Select All)
' Split a "label:value" string in to two parts, stored as a custom TYPE
TYPE config_item_type
Label AS STRING
Value AS STRING
END TYPE
DIM config_item AS config_item_type
line$ = "title: Main Entrance"
junk = Split_Header_Line(line$, config_item)
' Expecting config_item.Label = "title" and config_item.Value = "Main Entrance"
PRINT config_item.Label, config_item.Value
Split_2 line$, config_item
PRINT config_item.Label, config_item.Value
FUNCTION Split_Header_Line (line$, result AS config_item_type)
i% = INSTR(line$, ":")
IF i% THEN
result.Label = LCASE$(LEFT$(line$, i%))
result.Value = LTRIM$(MID$(line$, i% + 1))
END IF
END FUNCTION
SUB Split_2 (line$, result AS config_item_type)
i% = INSTR(line$, ":")
IF i% THEN
result.Label = LCASE$(LEFT$(line$, i%))
result.Value = LTRIM$(MID$(line$, i% + 1))
END IF
END SUB
As you can see, you can pass those values via parameter; just not as a return through the function itself. (Which might make it just easier to use a SUB, as I've included above as a demo for you, as well. )