Share My Creation B4J PlugIn: What If?

Discussion in 'B4J Share Your Creations' started by Mashiane, Dec 6, 2017.

  1. Mashiane

    Mashiane Well-Known Member Licensed User

    Hi there


    The fact that on the Files tab, one is able to open a file with an external program got me thinking this morning. What if I can write a B4J app, that can get passed the file name I selected, then process something inside the file and save it back.

    So I wrote a small script for something that I do almost often. Add a new page to my existing B4J app. To test my theory I created a form with a text area and created a UI app called NewPage...

    #Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
    #End Region

    Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private txtData As TextArea
    End Sub

    Sub AppStart (Form1 As Form, Args() As String)
        MainForm = Form1
    If Args.Length = 0 Then
    Log("File Name is missing.")
        End If
    'get the file name
        Dim fName As String = Args(0)
    "File Name",fName)
    'read the contents
        Dim contents As String = File.ReadString("",fName)
        txtData.Text = contents
    'New Page Content...
        Dim npc As StringBuilder
    "Sub Process_Globals").Append(CRLF)
    "Private fx As JFX").Append(CRLF)
    "Private frm As Form").Append(CRLF)
    "End Sub").append(CRLF).Append(CRLF)
    "Sub Close").Append(CRLF)
    "End Sub").Append(CRLF)
    "Public Sub Show(ParentForm As Form)").Append(CRLF)
    $"frm.Initialize("frm",400, 550)"$).Append(CRLF)
    "frm.Resizable = False").Append(CRLF)
    "frm.Title = <Change>").Append(CRLF)
    "End Sub").Append(CRLF)
        txtData.Text = txtData.Text & 
    CRLF & npc.tostring
    End Sub

    'Return true to allow the default exceptions handler to handle the uncaught exception.
    Sub Application_Error (Error As Exception, StackTrace As StringAs Boolean
    Return True
    End Sub
    What the code above does is to open the selected file, read its contents, display the contents in a text area in a form after appending the code to Show and Close a form.

    After compiling this app, I needed to configure the external viewers..


    Then I right clicked on the file, selected Open with NewPage and yippiee!! See the gif.

    Now, what if the functionality to Open With could be available on the Modules tab? Me thinks the possibilities are endless..

    Attached Files:

    Harris, UFOCoder13 and alwaysbusy like this.
  2. Mashiane

    Mashiane Well-Known Member Licensed User

    Code for NewPage...

    Attached Files:

    joulongleu likes this.
  3. Cableguy

    Cableguy Expert Licensed User

    Interesting... Following
    joulongleu and Mashiane like this.
  4. Mashiane

    Mashiane Well-Known Member Licensed User

    Just made a feauture request for this, would be a great value add. #imagining