B4J Question Inputbox using B4XDialog.ShowTemplate called in 1 line

jroriz

Active Member
Licensed User
Longtime User
I would like to use B4XDialog's ShowTemplate to create an InputBox, but I would like to do that using only 1 line of code to call the function.
It would be possible?
Below is as far as I got.

B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.Show

    Dim ib As ResumableSub = InputBox("Informe local do servidor", "127.0.0.1", MainForm)
    Wait For (ib) complete (resp As String)
    Log(resp)
    
    ' I'd like just 1 line: resp = inputbox(...)
    ' Is it possible?

End Sub

Sub InputBox(Mensagem As String, Default As String, f As Form) As ResumableSub
    
    Dim dialog As B4XDialog, Input As B4XInputTemplate, xui As XUI, ret As String
    
    Input.Initialize
    Input.lblTitle.Text = Mensagem
    dialog.Initialize(f.RootPane)
    Input.RegexPattern = ".+" 'require at least one character
    Input.Text = Default
    
    Wait For (dialog.ShowTemplate(Input, "OK", "", "CANCELAR")) Complete (Result As Int)
    
    If Result = xui.DialogResponse_Positive Then ret = Input.Text Else ret = ""

    Return ret
    
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
B4X:
    Wait For (InputBox("Informe local do servidor", "127.0.0.1", MainForm)) complete (resp As String)
 
Upvote 0

jroriz

Active Member
Licensed User
Longtime User
B4X:
    Wait For (InputBox("Informe local do servidor", "127.0.0.1", MainForm)) complete (resp As String)
It's halfway there ...
But I was not clear on my question.
What I wanted to know is what will be the necessary changes for the call to be as follows:

dim resp as string = InputBox("Informe local do servidor", "127.0.0.1", MainForm)

So I would also use

if InputBox("Informe local do servidor", "127.0.0.1", MainForm) = "" ...
 
Upvote 0
Top