Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with User Defined Function
#1
When I try to compile this snippet

Code: (Select All)
Type ButtonT
    x As Integer        'Position left top
    y As Integer
    w As Integer        'Height
    h As Integer        'Width
    text As String        'label
End Type

Function Button(x As Integer, y As Integer, w As Integer, h As Integer, Text As String) As ButtonT                                    
  'Defines and draws a new button

    Dim As ButtonT btn
    
    btn.x = x
    btn.y = y
    btn.h = h
    btn.w = w
    btn.text = text
        
    'Button_Draw(btn, ButtonColor)
    
  Return btn
    
End Function
I get the following error:

------------------------
Expected )
Caused by (or after):
Line 9:
Function Button_New(x As Integer, y As Integer, w As Integer, h As Integer, Text As String) As Button
------------------------

Can someone clarify what I am doing wrong.
Reply
#2
Code: (Select All)
Function Button(x As Integer, y As Integer, w As Integer, h As Integer, Text As String) As ButtonT

"As Button" on end is trying to make a Function return a ButtonT. As I said in Simple GIU thread, QB64 Functions can not return UDT's like FreeBasic can. It's not a simple translation from FB because, again, FB can do UDT arrays and Functions can return UDT's neither of which QB64 can do directly.

You'd have to change it to a sub and "output" the btn in the parameters:
Code: (Select All)
Type ButtonT
    x As Integer 'Position left top
    y As Integer
    w As Integer 'Height
    h As Integer 'Width
    text As String 'label
End Type



Sub Button (x As Integer, y As Integer, w As Integer, h As Integer, Text As String, btn As ButtonT)
    'Defines and draws a new button

    'Dim As ButtonT btn

    btn.x = x
    btn.y = y
    btn.h = h
    btn.w = w
    btn.text = Text

    'Button_Draw(btn, ButtonColor)

End Sub
b = b + ...
Reply
#3
@bplus
Yes, that's solved it.
Reply




Users browsing this thread: 1 Guest(s)