Tool B4a Source Code Formatter (now open source)

SOURCE CODE FORMATTER
Cleans up your Basic4Android project source code

As a programmer I tend to write code without too much regard for neatness with the intention of cleaning it up at a later date. As my projects became longer it could take quite a while to correctly space and indent my code - so I wrote a VB program to take care of this for me.

The program is available free of charge and all comments and suggestions are welcomed. Erel has since uploaded this to the website, you can download this to a pc from here:

www.b4x.com/android/files/B4ACoderSetup.zip

************************** Version 1.9 now available. ****************************

B4aCoder.jpg


1) Source code is formatted neatly in a user configurable manner.
2) Wrongly scoped and unused declared variables are listed.
3) Dead code is listed.
4) Fault listings appear in a datagridview on screen and can be printed to the printer.

So far we have tested it on a 22 module program and it has worked faultlessly. The interface has recently been updated to reduce flickering and additional functions handle public and private subs. Wrongly scoped variables are now noted and recommendations given to reduce a variables scope where appropriate.
Please leave a comment if you find the program useful.

Hope you like it.

UPDATE: Visual Studio (VB 2008) original source code is now available for programmers who would like to go on to improve this program for the benefit of the B4A community. www.b4x.com/android/files/B4ACoder.zip. Download the zip file and place the contents in your Visual Studio projects directory.
 
Last edited:

CidTek

Active Member
Licensed User
Longtime User
Hi Tom,

Any chance you consider making this open source because as a developer I would like to totally customize it to my formatting preferences including ideas I submitted earlier in this thread.

Plus some other ideas are a paste window to format just a module or sub.

Ideas such running minimized and a hot key invokes searching for the B4A IDE edit window hWnd and formatting the text within it.
 

daemon

Active Member
Licensed User
Longtime User
I get Unhandled exception with projects that use shared modules.
Have you tested with such?
 

Tom Law

Active Member
Licensed User
Longtime User
B4A Coder Source Code
OK - I have tried to upload the original Visual Studio source code to allow users to modify the program for their own (and others) benefit but unfortunately the website restricts uploads to 512KB (its about 3 meg). If Erel would be happy to help with uploading this file I would be happy to make this publically available.
 

CidTek

Active Member
Licensed User
Longtime User
B4A Coder Source Code
OK - I have tried to upload the original Visual Studio source code to allow users to modify the program for their own (and others) benefit but unfortunately the website restricts uploads to 512KB (its about 3 meg). If Erel would be happy to help with uploading this file I would be happy to make this publically available.

What about using Github?
 

Tom Law

Active Member
Licensed User
Longtime User
What about using Github?

Hi CidTek

Unfortunately I don't have a Github account and really the code is more likely to be of use to members if accessed directly from this site. What I have done is to email Erel directly and attached the code so that he can attach it to this entry. Assuming that happens I would make the following requests:

1) That all copies and modifications be provided free of charge to the B4A community.

2) That due credit be given in your code to my contribution.

3) That no-one laughs at my original code - which I am sure can be greatly improved upon by some of the experts here.

I look forward to seeing how you (and others) improve it. (Remember that this is Visual Studio VB code).


Regards

Tom Law
 

Marco Nissen

Active Member
Licensed User
Longtime User
Hi Marco, it looks like some kind of string handling problem. If this is reproducible would you like to send me a copy of the program code so that I can fix it?

Email [email protected]


Hi

I could detect the problematic section, but the issue is somehow invisible

See below .. it might have been there because of the word "schmäler", but only the second part of "...enratio>imgratio Then ' bild schmäler, oben + unten..." caused your program to exit

Marco

B4X:
Public Sub getWidgetThumbnail ( b As Bitmap) As Bitmap
    Try
        Dim bx As BitmapExtended
        Dim screenratio As Float = 80/125
        bx.Initialize("bx")
        Dim w As Int=b.Width
        Dim h As Int=b.Height
        Dim x As Int=0
        Dim y As Int=0
        Dim imgratio As Float = w/h
'        Dim cutlength As Int
       
        Log ("check " & w & "x" & h)
           
        If h>w Then
       
            If screenratio<imgratio Then ' bild schmäler, oben + unten schneiden
               
                y= (h-h/imgratio*screenratio )/2
                h=h/imgratio*screenratio
'                Log ("1: cropped to " & x & "/" & y & "/" & w &"/" & h)
                Return bx.createBitmap3(b,x,y,w,h)
           
            Else
                x= (w-w/imgratio*screenratio )/2
                w=w/imgratio*screenratio
'                Log ("2: cropped to " & x & "/" & y & "/" & w &"/" & h)
                Return bx.createBitmap3(b,x,y,w,h)
           
            End If
       
        Else
            If screenratio>imgratio Then ' bild schmäler, oben + unten schneiden
               
                y= (h-h/imgratio*screenratio )/2
                h=h/imgratio*screenratio
'                Log ("3: cropped to " & x & "/" & y & "/" & w &"/" & h)
                Return bx.createBitmap3(b,x,y,w,h)
           
            Else
                x= (w-w/imgratio*screenratio )/2
                w=w/imgratio*screenratio
'                Log ("4: cropped to " & x & "/" & y & "/" & w &"/" & h)
                Return bx.createBitmap3(b,x,y,w,h)
           
            End If
        End  If
       
       
        'Return b
    Catch
   
        Log("issue in getWidgetThumbnail " & LastException)
        Return b
    End Try
End Sub
 

Tom Law

Active Member
Licensed User
Longtime User
Hi

I could detect the problematic section, but the issue is somehow invisible

See below .. it might have been there because of the word "schmäler", but only the second part of "...enratio>imgratio Then ' bild schmäler, oben + unten..." caused your program to exit

Marco

B4X:
Public Sub getWidgetThumbnail ( b As Bitmap) As Bitmap
    Try
        Dim bx As BitmapExtended
        Dim screenratio As Float = 80/125
        bx.Initialize("bx")
        Dim w As Int=b.Width
        Dim h As Int=b.Height
        Dim x As Int=0
        Dim y As Int=0
        Dim imgratio As Float = w/h
'        Dim cutlength As Int
   
        Log ("check " & w & "x" & h)
       
        If h>w Then
   
            If screenratio<imgratio Then ' bild schmäler, oben + unten schneiden
           
                y= (h-h/imgratio*screenratio )/2
                h=h/imgratio*screenratio
'                Log ("1: cropped to " & x & "/" & y & "/" & w &"/" & h)
                Return bx.createBitmap3(b,x,y,w,h)
       
            Else
                x= (w-w/imgratio*screenratio )/2
                w=w/imgratio*screenratio
'                Log ("2: cropped to " & x & "/" & y & "/" & w &"/" & h)
                Return bx.createBitmap3(b,x,y,w,h)
       
            End If
   
        Else
            If screenratio>imgratio Then ' bild schmäler, oben + unten schneiden
           
                y= (h-h/imgratio*screenratio )/2
                h=h/imgratio*screenratio
'                Log ("3: cropped to " & x & "/" & y & "/" & w &"/" & h)
                Return bx.createBitmap3(b,x,y,w,h)
       
            Else
                x= (w-w/imgratio*screenratio )/2
                w=w/imgratio*screenratio
'                Log ("4: cropped to " & x & "/" & y & "/" & w &"/" & h)
                Return bx.createBitmap3(b,x,y,w,h)
       
            End If
        End  If
   
   
        'Return b
    Catch

        Log("issue in getWidgetThumbnail " & LastException)
        Return b
    End Try
End Sub

Hi Marco,

I think that you might be right about the foreign characters (ä in schmäler). If I am not mistaken this is an extended ascii character rather than standard ascii. I have only ever tested the program using my own code which is in English. The program has a facility to allow you to comment out (i.e. ignore) a difficult section of code. Try this on the section that you believe may be troublesome :

'#Coderoff

your code here

'#Coderon

If necessary you can ask it to ignore entire subroutines (although usually one line is sufficient).


Regards

Tom
 
Last edited:
Top