06-12-2024, 10:38 PM
Hello! Former PDS 7.1 developer here, and I recently stumbled on some of my old source code files while digging through an old hard drive. That led me to qb64 and eventually here!
So I decided to take a stab at completing a little text-based map scroller that I started a few decades ago, and I'm using some of the new conventions available with QB64PE.
It brings me my first question: Can a function return a custom TYPE? If so, how?
Consider the following code:
I get the following two errors:
Expected = similar user defined type on line 10
and
User defined types in expresssions are invalid on line 21
Is this telling me that I can't use TYPEd variables as return types for functions or am I missing something more obvious?
So I decided to take a stab at completing a little text-based map scroller that I started a few decades ago, and I'm using some of the new conventions available with QB64PE.
It brings me my first question: Can a function return a custom TYPE? If so, how?
Consider the following 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"
config_item = Split_Header_line(lines$)
' Expecting config_item.Label = "title" and config_item.Value = "Main Entrance"
Function Split_Header_Line (line$)
Dim 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
Split_Header_Line = result
END FUNCTION
I get the following two errors:
Expected = similar user defined type on line 10
and
User defined types in expresssions are invalid on line 21
Is this telling me that I can't use TYPEd variables as return types for functions or am I missing something more obvious?