Bug? B4A v5 - End Sub bug

Discussion in 'Bugs & wishlist' started by Robert Valentino, Jun 8, 2015.

  1. Robert Valentino

    Robert Valentino Well-Known Member Licensed User

    I do a lot of these single line routines

    Sub sAdd_Modify_Courses_Click : StartActivity("aCourses") : End Sub
    Sub sAdd_Modify_Players_Click : StartActivity("aPlayers") : End Sub
    Sub sPlayer_ScoreCards_Click : StartActivity("aScoreCards") : End Sub
    Sub sPlayer_Stats_Click : StartActivity("aStats") : End Sub
    In all my single line routines I am getting a B4A v5 Error - End Sub missing


    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    Starting from v5.00 Sub and End Sub keywords must start on a new line.
    LucaMs, NJDude and klaus like this.
  3. Robert Valentino

    Robert Valentino Well-Known Member Licensed User

    Really... WOW
  4. Robert Valentino

    Robert Valentino Well-Known Member Licensed User

    Is this restriction ever going to be removed?

    I have a lot lines of code like this that I prefer not to have to convert
  5. NJDude

    NJDude Expert Licensed User

    One line SUBs is a very unorthodox way of writing a sub (read bad way), same goes for one line If..Then...ElseIF...Else blocks.
    Last edited: Jun 18, 2015
  6. thedesolatesoul

    thedesolatesoul Expert Licensed User

    But but...
    What about
    If coolguy = NJDude then coolguy = null
  7. NJDude

    NJDude Expert Licensed User

    Still bad.
  8. Robert Valentino

    Robert Valentino Well-Known Member Licensed User

    I'm a C++ guy and in header templates there are always a ton of
    Bool Something(int IfSomething) {  return IfSomething = -1 ? false : true }
    Now just because you do not like it does not make it wrong.

    Personal Style
  9. LucaMs

    LucaMs Expert Licensed User

    Fortunately, I did not know you could do that with B4A 4, otherwise... I would not have done that anyway :D
  10. imbault

    imbault Well-Known Member Licensed User

    I agree with Erel, and Luca, pretty unreadable, but as it was OK in previous version, that Erel choice to maintain that.

    If coolguy = NJDude then coolguy = null
    That funny code works on the new release, don't worry
    lemonisdead and thedesolatesoul like this.
  11. LucaMs

    LucaMs Expert Licensed User


    I meant...

    Se io avessi saputo che in B4A 4.x esisteva la possibilità di mettere "End Sub" su una riga non vuota... io non l'avrei fatto comunque.

    I hope that now it is more readable :p
  12. Erel

    Erel Administrator Staff Member Licensed User

    I'm not sure that it will be supported in the future. The reason is technical.

    The IDE parser needs to very quickly build the page structure. In order to avoid parsing all the code text it looks for the first word in each line to check whether it is "Sub" or "End Sub" (or #If, etc...).
    Peter Simpson, asales and NJDude like this.
  13. LucaMs

    LucaMs Expert Licensed User

    ok, I do not speak English well, but I think you understand that, in my opinion, put an "End Sub" in a non-blank line is deprecable.

    I "don't like" also "End If" at the end of "an empty line":

    If sdf and adflj or (adlfj and fjlla).... End If !!!

    It is hardly readable and maintainable.


    is a "good news" ;)
  14. sorex

    sorex Expert Licensed User

    @Robert Valentino,

    I don't know if C++ allows it but some languages even allow you to leave out the { } brackets if it is a single line if statement which makes even more sense.
  15. Erel

    Erel Administrator Staff Member Licensed User

    My post was an answer to post #4.
  16. Robert Valentino

    Robert Valentino Well-Known Member Licensed User

    Erel. I understand your position. But this is a major change in style for me and currently stops me from upgrading to 5.x

    To everyone else:

    Much as many may not like my style (as I do not like tabs in my code - but prefer spaces) to me coding is more like an artist painting a picture no two artists paint the same way and usually do not have the same style. But in the end they all have beautiful works to look at.

    My style may be different, but wrote some code in the 1980's for mainframes that a friend of mine still supports (now that is a long time for some code to be around) was even coded back then to handle the 1999-2000 change because I new some day it was coming (and I got picked on for that), and the code is still running in 2015

    I love one line coding. I can look at twenty or thirty lines at once and know all the functions in a module as seen below

    #Region Single Line Grid Commands
    Sub SetGridBGColor(Color As Int)  : mGridBGColor  = Color  :  End Sub

    Sub SetGridSize(Size As Int)  : mGridSize  = (Size * 1dip)  :  SetHeaderHeight(mFixedDataHeight)  :  End Sub
    Sub SetGridSizeColor(Color As Int)  : mGridSizeColor  = Color  :  End Sub

    Sub SetGridSpacing(Spacing As Int)  : mGridSpacing  = (Spacing * 1dip)  :  SetHeaderHeight(mFixedDataHeight)  :  End Sub
    Sub SetGridSpacingColor(Color As Int)  : mGridSpacingColor = Color  :  End Sub

    Sub GridSize()  As Int  : Return mGridSize  :  End Sub
    Sub GridSizeColor() As Int  : Return mGridSizeColor  :  End Sub

    Sub GridSpacing() As Int  : Return mGridSpacing  :  End Sub
    Sub GridSpacingColor() As Int  : Return mGridSpacingColor  :  End Sub

    Sub NumberRows  As Int  : Return mRowsCols.Size  :  End Sub
    #End Region
    Now the above lines of code may look like crap here (because of Tabs) but you can see what they look like in the editor from the attached pictures.

    Everything lines up nice, easy to C (Oops did I really mean C++) easy to read (my opinion)

    All my code lines up. I am a fast typist and hitting the space bar is not a problem.

    But thanks for all the feeback guys.

    CodeStyle.png CodeStyle2.png
  17. thedesolatesoul

    thedesolatesoul Expert Licensed User

    To be fair to you, I feel this is a step backwards because it is an IDE imposed restriction on coding style rather than a compiler imposed restriction. I'm sure the code is compilable in command line mode.
    It makes B4A 5 to be not backwards compatible, but if that needs to be done then it should be made more clear, documented and not be incremental.
    Peter Simpson and RandomCoder like this.
  18. LucaMs

    LucaMs Expert Licensed User

    1) those "are" (should be, if their name started with a lower case "set") Properties, and one line of code only;
    2) you can be an artist when you design your sw, but to keep the code maintainable and readable, perhaps even by other people, it is better to be at all artistic;
    3) if your routines would consist of many lines, you may see them listed, each in a single line, collapsing the page (module). Use Regions to group routines is another big advantage.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice