R Roger Garstang Well-Known Member Licensed User Longtime User May 15, 2012 #1 Other languages might call it something like Self or This...although rare in a BASIC language in the area I'm wondering since it is the Return value, but is something like this possible (Lame example, but gets the point across): Code: Copy Sub CustomButton(btnText As String) As Button CustomButton.Initialize("btnClick") CustomButton.Text = btnText CustomButton.Typeface = Typeface.DEFAULT_BOLD CustomButton.Gravity = Gravity.CENTER End Sub The sub returns a button, so I'm just curious if it is an object yet or is it always required to dim a button in the function and then return it. Typing the code above makes it look like it is possible since the list comes up when I type "CustomButton.", but on compile it reports missing () like it is only a sub.
Other languages might call it something like Self or This...although rare in a BASIC language in the area I'm wondering since it is the Return value, but is something like this possible (Lame example, but gets the point across): Code: Copy Sub CustomButton(btnText As String) As Button CustomButton.Initialize("btnClick") CustomButton.Text = btnText CustomButton.Typeface = Typeface.DEFAULT_BOLD CustomButton.Gravity = Gravity.CENTER End Sub The sub returns a button, so I'm just curious if it is an object yet or is it always required to dim a button in the function and then return it. Typing the code above makes it look like it is possible since the list comes up when I type "CustomButton.", but on compile it reports missing () like it is only a sub.
W wl Well-Known Member Licensed User Longtime User May 15, 2012 #2 Guess this is impossible because you are using a sub as an object ... I think you need to dim a new button, sets its properties etc and return it. Upvote 0
Guess this is impossible because you are using a sub as an object ... I think you need to dim a new button, sets its properties etc and return it.
R Roger Garstang Well-Known Member Licensed User Longtime User May 15, 2012 #3 Yeah that is what I figured. It would be cool and more object oriented if it worked. Main thing odd was that the IDE makes it appear to be valid. Upvote 0
Yeah that is what I figured. It would be cool and more object oriented if it worked. Main thing odd was that the IDE makes it appear to be valid.
J Jost aus Soest Active Member Licensed User Longtime User May 16, 2012 #4 You must write it in this way: Code: Copy Sub CustomButton(btnText As String, EventName As String) As Button Dim b As Button b.Initialize(EventName) b.Text = btnText b.CustomButton.Typeface = Typeface.DEFAULT_BOLD b.CustomButton.Gravity = Gravity.CENTER Return b End Sub Upvote 0
You must write it in this way: Code: Copy Sub CustomButton(btnText As String, EventName As String) As Button Dim b As Button b.Initialize(EventName) b.Text = btnText b.CustomButton.Typeface = Typeface.DEFAULT_BOLD b.CustomButton.Gravity = Gravity.CENTER Return b End Sub
R Roger Garstang Well-Known Member Licensed User Longtime User May 16, 2012 #5 Yeah, I know how it normally is done. I was just curious if it could be done another way since the IDE was making it look like it could. The way I wrote it out is actually like how my other main language PowerBASIC allows. Upvote 0
Yeah, I know how it normally is done. I was just curious if it could be done another way since the IDE was making it look like it could. The way I wrote it out is actually like how my other main language PowerBASIC allows.
Erel B4X founder Staff member Licensed User Longtime User May 16, 2012 #6 What happens is that the code editor ignores the missing parenthesis and shows the list based on the return value. This code for example is correct (outside the sub): Code: Copy CustomButton("aaa", "bbb").Text = "ccc" Upvote 0
What happens is that the code editor ignores the missing parenthesis and shows the list based on the return value. This code for example is correct (outside the sub): Code: Copy CustomButton("aaa", "bbb").Text = "ccc"