This is a very simple example on how to organize your code as a multipagewith multiple classes, while transpiled it is a SPA.
main:
Sub Process_Globals
Private BANano As BANano
Dim myPage1 As Page1
Dim myPage2 As Page2
End Sub
Sub AppStart (Form1 As Form, Args() As String)
#if Debug
' MUST be literally this line if you want to use the B4J Logs jump to code feature!
Log("BANanoLOGS")
#End if
BANano.Initialize("BANano", "BANanoMinimal",DateTime.Now)
BANano.Header.Title="BANano Minimal"
BANano.JAVASCRIPT_NAME = "app" & DateTime.Now & ".js"
BANano.TranspilerOptions.MergeAllCSSFiles = True
BANano.TranspilerOptions.MergeAllJavascriptFiles = True
BANano.TranspilerOptions.RemoveDeadCode = True
BANano.TranspilerOptions.ShowWarningDeadCode = True
BANano.TranspilerOptions.EnableLiveCodeSwapping = True
BANano.Build(File.DirApp)
#if Release
ExitApplication
#End if
End Sub
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub BANano_Ready()
myPage1.Initialize
myPage2.Initialize
myPage1.Load
End Sub
SharedData module:
Sub Process_Globals
Dim CurrentPage As String
Dim Page1TextBox As String
Dim Page2TextBox As String
End Sub
Public Sub SavePreviousPage()
Select Case CurrentPage
Case "Page1"
Page1TextBox = Main.MyPage1.SKTextBox1.Text
Case "Page2"
Page2TextBox = Main.MyPage2.SKTextBox1.Text
End Select
End Sub
public Sub LoadThisPage()
Select Case CurrentPage
Case "Page1"
Main.MyPage1.SKTextBox1.Text = Page1TextBox
Case "Page2"
Main.MyPage2.SKTextBox1.Text = Page2TextBox
End Select
End Sub
Page1 class with its Layout Page1. Note that its SKButton_Click event is raised right here in the class.
Sub Class_Globals
Dim BANano As BANano
Public SKButton1 As SKButton
Public SKTextBox1 As SKTextBox
End Sub
Public Sub Initialize
End Sub
public Sub Load()
SharedData.SavePreviousPage
Dim body As BANanoElement
body.Initialize("body")
body.Empty
body.LoadLayout("Page1")
SharedData.CurrentPage = "Page1"
SharedData.LoadThisPage
End Sub
Private Sub SKButton1_Click (event As BANanoEvent)
Main.myPage2.Load
End Sub
Page2 class (same system)
Sub Class_Globals
Dim BANano As BANano
Public SKButton1 As SKButton
Public SKTextBox1 As SKTextBox
End Sub
Public Sub Initialize
End Sub
public Sub Load()
SharedData.SavePreviousPage
Dim body As BANanoElement
body.Initialize("body")
body.Empty
body.LoadLayout("Page2")
SharedData.CurrentPage = "Page2"
SharedData.LoadThisPage
End Sub
Private Sub SKButton1_Click (event As BANanoEvent)
Main.myPage1.Load
End Sub
I like doing it like this as all is well organized: every page it's own events, layout and logic, all data available in a shared module and main is still uncluthered.
Alwaysbusy