InputBox
Hi everywhere,
surely you know the InputBox-funktion of VB. If you were missing it until now, don't hesitate it's already there. In Visual Basic 6 you are used to the InputBox-funktion like in the following code snippet:
to get a Dialog not quite the same but very similar to the VB-InputBox in Jabaco (and also in Java) you simply have to use the function
showInputDialog
of the static class JOptionPane that can be found in the namespace
javax#swing
with this knowledge you can easily write down some wrapper-functions in Jabaco to get it compatible to Visual Basic like the following:
maybe copy them into a module or where you like, now you can use it in Jabaco very near to the VB6-Syntax
until now i did not find a possibility to alter the title of the swing-InputBox but is it very important?
the InputBox-function of VB6 has this Syntax:
Function InputBox(Prompt, [Title], [Default], [XPos], [YPos], [HelpFile], [Context]) As String
so there are a few parameters missing, but you can come very far without them.
have fun with the great Jabaco!
greetings OlimilO
surely you know the InputBox-funktion of VB. If you were missing it until now, don't hesitate it's already there. In Visual Basic 6 you are used to the InputBox-funktion like in the following code snippet:
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
Private Sub Command1_Click() Dim s As String: s = InputBox("Please give me something") If StrPtr(s) <> 0 Then Command1.Caption = s Else MsgBox "The action was canceled by the user" End If End Sub Public Sub Command2_Click() Dim s As String: s = InputBox("Please give me something", , "everything") If StrPtr(s) <> 0 Then Command2.Caption = s Else MsgBox "The action was canceled by the user" End If End Sub |
to get a Dialog not quite the same but very similar to the VB-InputBox in Jabaco (and also in Java) you simply have to use the function
showInputDialog
of the static class JOptionPane that can be found in the namespace
javax#swing
with this knowledge you can easily write down some wrapper-functions in Jabaco to get it compatible to Visual Basic like the following:
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 |
Public Function InputBox(Prompt As String) As String InputBox = javax#swing#JOptionPane.showInputDialog(Prompt) End Function Public Function InputBox(Prompt As String, Title As String) As String InputBox = javax#swing#JOptionPane.showInputDialog(Prompt) End Function Public Function InputBox(Prompt As String, Title As String, Default As String) As String InputBox = javax#swing#JOptionPane.showInputDialog(Prompt, Default) End Function |
maybe copy them into a module or where you like, now you can use it in Jabaco very near to the VB6-Syntax
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
Public Sub Command1_Click() Dim s As String = InputBox("Please give me something") If s <> Nothing Then Command1.Caption = s Else MsgBox "The action was canceled by the user" End If End Sub Public Sub Command2_Click() Dim s As String = InputBox("Please give me something", "", "everything") If s <> Nothing Then Command2.Caption = s Else MsgBox "The action was canceled by the user" End If End Sub |
until now i did not find a possibility to alter the title of the swing-InputBox but is it very important?
the InputBox-function of VB6 has this Syntax:
Function InputBox(Prompt, [Title], [Default], [XPos], [YPos], [HelpFile], [Context]) As String
so there are a few parameters missing, but you can come very far without them.
have fun with the great Jabaco!
greetings OlimilO
Title
Hi maXim,
Thanks!
@Manuel: if you think this suits better into Tipps&Tricks you could move this thread if it is possible, OK? thanks
so i have tried around a little bit more and i found out that it is possible to give it a title of your own choice:
the InputBox-funktions should be then:
explanation to the third function:
the dialog is capable of validating the users input, and it also tries to do this, but it throws an error if the array of possible values is empty.
but if you fill the array the dialog shows dropdown-box aka ComboBox instead of a Edit-TextBox.
OlimilO
Thanks!
@Manuel: if you think this suits better into Tipps&Tricks you could move this thread if it is possible, OK? thanks
so i have tried around a little bit more and i found out that it is possible to give it a title of your own choice:
the InputBox-funktions should be then:
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Public Function InputBox(Prompt As String) As String InputBox = javax#swing#JOptionPane.showInputDialog(Prompt) End Function Public Function InputBox(Prompt As String, Default As String) As String InputBox = javax#swing#JOptionPane.showInputDialog(Prompt, Default) End Function Public Function InputBox(Prompt As String, Title As String, Default As String) As String Dim Obj() As Object Try: On Error Goto Catch InputBox = javax#swing#JOptionPane.showInputDialog( _ Null, Prompt, Title, JOptionPane.QUESTION_MESSAGE, Null, Obj, Default) Exit Function Catch: InputBox = Nothing End Function |
explanation to the third function:
the dialog is capable of validating the users input, and it also tries to do this, but it throws an error if the array of possible values is empty.
but if you fill the array the dialog shows dropdown-box aka ComboBox instead of a Edit-TextBox.
OlimilO
quality needs time
Quoted
But I'm not sure how to guarantee the quality for future changes...
quality can be reached through discussions of every code, and discussions need time
Maybe there should be a special board for the framework.
where...
...users can make suggestions what they miss, or what should be done.
...developers can make suggestions how to change the framework and
...developers can post code samples and discuss the code
greetings
OlimilO
InputBox minor update
VB6-code:
Jabaco code:
Jabaco framework (Basic):
OK, in the Jabaco framework it must be in Java code of the class Interaction
OlimilO
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
Private Sub Command1_Click() Dim RetVal As Variant Dim Title As String Dim Prompt As String Dim Default As Variant Title = "Please tell me your name!" Prompt = "Just write your name down here:" Default = 123456789 RetVal = InputBox(Prompt): MessRetVal RetVal RetVal = InputBox(Prompt, Title): MessRetVal RetVal RetVal = InputBox(Prompt, , Default): MessRetVal RetVal RetVal = InputBox(Prompt, "", Default): MessRetVal RetVal RetVal = InputBox(Prompt, Title, Default): MessRetVal RetVal End Sub Private Sub MessRetVal(RetVal As Variant) If RetVal <> "" Then Dim Mess As String If IsNumeric(RetVal) Then Mess = "Ah what, you are just a number?" & vbCrLf Else Mess = "Your Name is: " & vbCrLf End If MsgBox Mess & RetVal End If End Sub |
Jabaco code:
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
Private Sub Command1_Click() Dim RetVal As Variant Dim Title As String Dim Prompt As String Dim Default As Variant Title = "Please tell me your name!" Prompt = "Just write your name down here:" Default = 123456789 RetVal = InputBox(Prompt): MessRetVal(RetVal) RetVal = InputBox(Prompt, Title): MessRetVal(RetVal) retval = InputBox(Prompt, Default): MessRetVal(RetVal) retval = InputBox(Prompt, "",Default): MessRetVal(RetVal) retval = InputBox(Prompt, Title, Default): MessRetVal(RetVal) End Sub Private Sub MessRetVal(RetVal As Variant) If RetVal <> "" Then Dim Mess As String If IsNumeric(RetVal) Then Mess = "Ah what, you are just a number?" & vbCrLf Else Mess = "Your Name is: " & vbCrLf End If MsgBox Mess & RetVal End If End Sub |
Jabaco framework (Basic):
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Public Function InputBox(Prompt As String) As String InputBox = javax#swing#JOptionPane.showInputDialog(Prompt) End Function Public Function InputBox(Prompt As String, Title As String) As String InputBox = javax#swing#JOptionPane.showInputDialog( _ Null, Prompt, Title, JOptionPane.QUESTION_MESSAGE) End Function Public Function InputBox(Prompt As String, Default As Variant) As String InputBox = javax#swing#JOptionPane.showInputDialog(Prompt, Default) End Function Public Function InputBox(Prompt As String, Title As String, Default As Variant) As String Dim Obj() As Object Try: On Error Goto Catch InputBox = javax#swing#JOptionPane.showInputDialog( _ Null, Prompt, Title, JOptionPane.QUESTION_MESSAGE, Null, Obj, Default) Exit Function Catch: InputBox = Nothing End Function |
OK, in the Jabaco framework it must be in Java code of the class Interaction
OlimilO
