Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dialog layouts and user input

Status
Not open for further replies.

dinodigital

Technical User
Jun 24, 2007
9
AU
I have spent time reading over most of the posts in this forum but am still having some trouble with dialog boxes, how to lay them out and get user input from the dialog and send the data to my attachmate screen, as i am new to extra basic.

Basically, I am wanting to get 3 values from a user from a dialog box; an int and two strings. the second string is also a long string, sometimes larger than 200 chars, so i was also wondering if there is any kind of textfield function so the user can see all that has been entered.

Once i have the three values, after validation, i would simply use the values and send them to the screen throughout various pages in attachmate after the user has clicked the ok button.

at the moment i can get the user input with inputboxes as the code runs, but it'd be easier to input all the information in one box then run the code. i was also wondering about how to declare an array of strings and step through that array comparing each string to one of the user input strings using a for loop.

any help would be greatly appreciated...

thanks
 
There is no text field option. This should answer all your questions.

Code:
Dim SomeArray(4)

Declare Sub GoGoDialog
Function FileDlgFunc(identifier$, action, suppvalue)
    FileDlgFunc = True
    Select Case action
    Case 1
    Case 2
        Select Case identifier$
        Case "ButCancel"
            FileDlgFunc = False
        Case "ButOK"
            For i = 0 To UBound(SomeArray)
                SomeString = SomeArray(i)
                If SomeString = DlgText("Field1") Then
                   MsgBox "Field 1 matches " & SomeString
                End If
                If SomeString = DlgText("Field2") Then
                   MsgBox "Field 2 matches " & SomeString
                End If
                If SomeString = DlgText("Field3") Then
                   MsgBox "Field 3 matches " & SomeString
                End If
            Next
        End Select
    End Select
End Function

Sub GoGoDialog
    SomeArray(0) = "This"
    SomeArray(1) = "That"
    SomeArray(2) = "And"
    SomeArray(3) = "The"
    SomeArray(4) = "Other"
    
    Begin Dialog ThisDlg 95, 70, "My Window", .FileDlgFunc
       Text     5,  5, 25, 10, "Field 1:"
       TextBox 35,  5, 55, 12, .Field1
       Text     5, 20, 25, 10, "Field 2:"
       TextBox 35, 20, 55, 12, .Field2
       Text     5, 35, 25, 10, "Field 3:"
       TextBox 35, 35, 55, 12, .Field3
       PushButton  5, 50, 40, 15, "OK", .ButOK
       CancelButton  50, 50, 40, 15, .ButCancel
    End Dialog
    Dim mydialog as ThisDlg
    On Error Resume Next
    Dialog mydialog
End Sub

Sub Main
    GoGoDialog
End Sub
 

Thankyou for that example, but I do have one more question however that I still can't seem to understand, as when i enter the strings from the array in your example into the textboxes, nothing happens when i hit the ok button.

How do I refence the user input data from inside the main sub, as when the user presses the OK button, I want to use each piece of data from the dialog, in the main sub, to send to the screen:

this is what i'm wanting to do: use a single dialog box to get all user input.

user input 1 is an 8 digit integer. i am also wondering if/how i can check the whole number has any alpha chars in it, like an isAlpha type function. once i've checked it's a valid 8 digit number send that value to the main sub.

user input 2 would be a group of checkboxes corresponding to strings. once the user has checked a single box, that string value is sent to the main sub after the ok button is pressed at the end.

user input 3 is just a large string, that has to be sent to the main sub.

the ok button will take the 3 user inputs as long as each has been given an appropriate value and send all the data to the main sub to run through attachmate. if the user hits cancel it will simply quit the dialog.

So far i can run the code using input boxes, but many errors can arise and it doesn't seem like the best way to do it. how do i run my error checking when the user hits ok, so the dialog box stays open and let the user know which inputs weren't successfull, ie no checkbox selected or int longer than 8 digits.

thanks


 
To get the values of the fields reference them by DlgText("id"). So .Field1 is referenced by DlgText("Field1"). You can do whatever you want with those values. If it's easier for you to understand them as variables you can send them to a subroutine or function as strings.

If you want it to be in the main sub, you can set the variables in the function and Dim them outside of a sub or function. This is like how the array works in my prior post.

I've added code that shows you how to validate data. IMO, it's going to be easiest to do this in the dialog function. That way you can notify the user of a problem without closing the dialog box.

If you're only going to allow them to select one thing for the second field, then I'd suggest using radios or drop-downs. With a drop-down you can make all the options an array and grab the selection from a DlgText. If you use radios, a dlgvalue on the OptionGroup id will tell you which is selected. It also solves the problem of them selecting multiple checkboxes.

Code:
Sub DoSomethingOnOK(sField1, sField2, sField3)
  Dim SomeArray(4)
  SomeArray(0) = "This"
  SomeArray(1) = "That"
  SomeArray(2) = "And"
  SomeArray(3) = "The"
  SomeArray(4) = "Other"    
    
  For i = 0 To UBound(SomeArray)
    SomeString = SomeArray(i)
    If SomeString = sField1 Then
      MsgBox "Field 1 matches " & SomeString
      Match = Match + 1
    End If
    If SomeString = sField2 Then
      MsgBox "Field 2 matches " & SomeString
      Match = Match + 1
    End If
    If SomeString = sField3 Then
      MsgBox "Field 3 matches " & SomeString
      Match = Match + 1
    End If
  Next
    
  MsgBox "There were " & Match & " matches."

'* Do more stuff with the fields here.
End Sub

Function FileDlgFunc(identifier$, action, suppvalue)
  FileDlgFunc = True
  Select Case action
  Case 1
  Case 2
    Select Case identifier$
    Case "ButCancel"
      FileDlgFunc = False
    Case "ButOK"
      sField = DlgText("Field1")
      If IsNumeric(sField) And Len(sField) = 8 Then
         DoSomethingOnOK DlgText("Field1"), _
           DlgText("Field2"), DlgText("Field3")
         FileDlgFunc = False
       Else
         MsgBox "Field 1 must be 8 characters and numeric"
       End If
    End Select
  End Select
End Function

Sub Main
  Begin Dialog ThisDlg 95, 70, "My Window", .FileDlgFunc
    Text     5,  5, 25, 10, "Field 1:"
    TextBox 35,  5, 55, 12, .Field1
    Text     5, 20, 25, 10, "Field 2:"
    TextBox 35, 20, 55, 12, .Field2
    Text     5, 35, 25, 10, "Field 3:"
    TextBox 35, 35, 55, 12, .Field3
    PushButton  5, 50, 40, 15, "OK", .ButOK
    CancelButton  50, 50, 40, 15, .ButCancel
  End Dialog
  Dim MyDialog as ThisDlg
  On Error Resume Next
  Dialog MyDialog
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top