You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

1

Wednesday, January 28th 2009, 12:54pm

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:

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

maXim

Trainee

  • "maXim" is male

Posts: 51

Date of registration: Jan 5th 2009

Location: Sesto Fiorentino, Florence (ITALY)

Occupation: design & development (HW, SW & FW)

Hobbies: chess, fly fishing, good wine and beautiful women!

  • Send private message

2

Wednesday, January 28th 2009, 2:21pm

Hi OlimilO,

very good solution and good explanation! :thumbup:

OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

3

Wednesday, January 28th 2009, 2:34pm

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:

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

Manuel

Administrator

  • "Manuel" is male

Posts: 256

Date of registration: Jul 16th 2008

Location: Erlangen, Germany

Occupation: Software Developer

Hobbies: Jabaco, game theory, text-mining

  • Send private message

4

Wednesday, January 28th 2009, 6:43pm

Quoted

@Manuel: if you think this suits better into Tipps&Tricks you could move this thread if it is possible, OK? thanks
This function should be moved to the framework. I would like to publish svn-access for the framework. But I'm not sure how to guarantee the quality for future changes...

OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

5

Friday, January 30th 2009, 11:20am

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

OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

6

Wednesday, February 4th 2009, 7:31pm

InputBox minor update

VB6-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 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

Rate this thread
WoltLab Burning Board