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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dialog looping 1

Status
Not open for further replies.

Person51

Programmer
Mar 3, 2006
16
0
0
US
I'm trying to set up a secondary dialog box, running into "procedure is too large" error. It will not compile with the last dialog in the If/Then I have. Compiles / runs fine without the largest function.

I have a simple to do box, and if a checkbox is enabled, will kick up another dialog box based upon how many different line entries are needed.

So, in a nutshell, if you click the box, a droplist enables, and has a selection amount of 1 to 7. Then, based on what number is chosen, another box appears with more fields.

Right now, I have eight different sized Begin Dialog statements in the program, making it rather large.

So my question is this : Is there a loop that I can run just one dialog box in, that will retain data entered in it, up to eight times?

There are 2 droplist boxes and 8 textboxes per entry on the secondary dialog.

I ended up making a .ebh for .Functions of every dialog I use, since it ended up around 1.5K lines of code.

Any insight to my dilemma is welcomed.
 
Based on your post, something like this would probably work for you. Basically, the ThisFileDlgFunc = True keeps the dialog box open until ThisFileDlgFunc = False. This will keep the values previously entered in the fields and skips the whole close and reopen thing. Once OK is pressed X times it'll exit. I have the information storing in a two dimensional array, because it was an easy way to grab all the info. I don't know what you're doing after an "OK" but you could easily code it into the function or make it a seperate subroutine.

Code:
Dim List1$(), List2$(), List3$(), iLoop, iStart
Dim AllTheInfo(9,6)

Function ThisFileDlgFunc(identifier$, action, suppvalue)
    ThisFileDlgFunc = True
    Select Case action
    Case 1
        DlgText "Txt1", "Looped " & CStr(iStart) & " Times"
    Case 2
        Select Case identifier$
        Case "ButCcl"
            ThisFileDlgFunc = false
        Case "ButOK"
            AllTheInfo(0,iStart) = DlgValue("Drop1")
            AllTheInfo(1,iStart) = DlgValue("Drop2")
            AllTheInfo(2,iStart) = DlgText("Box1")
            AllTheInfo(3,iStart) = DlgText("Box2")
            AllTheInfo(4,iStart) = DlgText("Box3")
            AllTheInfo(5,iStart) = DlgText("Box4")
            AllTheInfo(6,iStart) = DlgText("Box5")
            AllTheInfo(7,iStart) = DlgText("Box6")
            AllTheInfo(8,iStart) = DlgText("Box7")
            AllTheInfo(9,iStart) = DlgText("Box8")
            If iStart = iLoop Then
                ThisFileDlgFunc = false
            Else
                iStart = iStart + 1
                DlgText "Txt1", "Looped " & CStr(iStart) & " Times"
            End If
        End Select
    End Select
End Function

Sub ThisDialog
    Begin Dialog ThisDlg 95, 105, "Generic Dialog Box", .ThisFileDlgFunc
       Text 5, 5, 85, 10, "", .Txt1
       DropListBox  5, 15, 40, 42, List2(), .Drop1
       DropListBox  50, 15, 40, 42, List3(), .Drop2
       TextBox  5, 30, 40, 12, .Box1
       TextBox  50, 30, 40, 12, .Box2
       TextBox  5, 45, 40, 12, .Box3
       TextBox  50, 45, 40, 12, .Box4
       TextBox  5, 60, 40, 12, .Box5
       TextBox  50, 60, 40, 12, .Box6
       TextBox  5, 75, 40, 12, .Box7
       TextBox  50, 75, 40, 12, .Box8
       PushButton  5, 90, 40, 12, "OK", .ButOK
       CancelButton  50, 90, 40, 12, .ButCcl
    End Dialog

    Dim MyDlg as ThisDlg
    On Error Resume Next
    Dialog MyDlg
End Sub


Function ThatFileDlgFunc(identifier$, action, suppvalue)
    Select Case action
    Case 1

    Case 2
        Select Case identifier$
        Case "ButCcl","ButOK"
            iLoop = DlgValue(Drop1)
        End Select
    End Select
End Function


Sub Main
    ReDim List1(6)
    List1(0) = "1"
    List1(1) = "2"
    List1(2) = "3"
    List1(3) = "4"
    List1(4) = "5"
    List1(5) = "6"
    List1(6) = "7"

    Begin Dialog ThatDlg 50, 50, "DlgBox", .ThatFileDlgFunc
       DropListBox  5, 5, 40, 42, List1(), .Drop1
       PushButton  5, 20, 40, 12, "OK", .ButOK
       CancelButton  5, 35, 40, 12, .ButCcl       
    End Dialog

    Dim MyDlg as ThatDlg
    On Error Resume Next
    Dialog MyDlg

    iStart = 0
    ThisDialog
    For i = 0 to 6
       For j = 0 to 9
           MsgBox str(j) & "," & str(i) & " = " & AllTheInfo(j,i)
       Next
    Next
End Sub
 
Skie, sorry for not getting back to you, posted this on Friday right before leaving work, was in a hurry to get out.

Should've given you the code to begin with, so you had more to go on. What you have is perfect though, cheers.

Code:
Declare Function FileDlgFunction(identifier$, action, suppvalue)

Declare Function FileDlgFunc2(identify$, act, supvalue)

First Dialog
Code:
Begin Dialog MainProg 190, 175, 416, 217, "Main Dialog", .FileDlgFunction        
  CheckBox  14, 6, 41, 14, "N", .CheckBox0
  CheckBox  14, 18, 27, 14, "P", .CheckBox1
  TextBox  12, 34, 31, 14, .TextBox1            
  GroupBox  1, 1, 64, 50, ""            
  Text  78, 8, 47, 8, "Date"
  TextBox  75, 20, 41, 14, .TextBox2
  Text  76, 36, 40, 9, "Date Format"
  Text  156, 8, 47, 8, "#"
  TextBox  123, 20, 84, 14, .TextBox3
  Text  231, 8, 47, 8, "List Box 1", .Listing
  DropListBox  212, 20, 95, 44, "Choice 1"+chr$(9)+"Choice 2"+chr$(9)+"Choice 3", .DropListBox1
  GroupBox  67, 1, 246, 50, ""            
  TextBox  8, 76, 94, 14, .TextBox4
  Text  29, 62, 56, 8, "C"
  GroupBox  1, 50, 110, 50, ""            
  Text  125, 62, 47, 8, "H"
  TextBox  117, 76, 36, 14, .TextBox5
  Text  166, 62, 47, 8, "D."
  TextBox  159, 76, 24, 14, .TextBox6
  Text  210, 62, 47, 8, "S"
  TextBox  188, 76, 81, 14, .TextBox7
  Text  273, 62, 47, 8, "St"
  TextBox  272, 76, 31, 14, .TextBox8
  GroupBox  113, 50, 200, 50, ""            
  Text  10, 106, 47, 8, "U"
  TextBox  5, 119, 24, 14, .TextBox9
  Text  49, 106, 47, 8, "F"
  TextBox  45, 119, 24, 14, .TextBox10
  Text  87, 106, 47, 8, "B"
  TextBox  83, 119, 24, 14, .TextBox11
  GroupBox  1, 99, 110, 40, ""            
  Text  147, 106, 47, 8, "City"
  TextBox  120, 119, 72, 14, .City
  Text  217, 106, 34, 8, "State"
  TextBox  216, 119, 19, 14, .State
  Text  274, 105, 17, 9, "Zip "
  TextBox  263, 119, 31, 14, .Zip
  GroupBox  113, 99, 200, 40, ""                                    
  CheckBox  13, 145, 66, 8, "C", .CheckBox2
  TextBox  17, 158, 36, 14, .TextBox12                                                
  CheckBox  95, 145, 50, 8, "E", .CheckBox3
  TextBox  99, 158, 36, 14, .TextBox13            
  GroupBox  1, 137, 155, 40, ""                                    
  CheckBox  164, 155, 80, 8, "Add More", .CheckBox4
  DropListBox  252, 158, 54, 84, "1"+chr$(9)+"2"+chr$(9)+"3"+chr$(9)+"4"+chr$(9)+"5"+chr$(9)+"6"+chr$(9)+"7", .DropListBox2            
  Text  254, 145, 56, 8, "How Many", .AddLine                        
  GroupBox  158, 137, 155, 40, ""                                    
  Text  29, 184, 55, 8, "ListBox 1"
  DropListBox  5, 197, 137, 64, "Choice 1"+chr$(9)+"Choice 2"+chr$(9)+"Choice 3"+chr$(9)+"Choice 4", .DropListBox3
  Text  202, 184, 61, 8, "ListBox 2"
  DropListBox  164, 197, 143, 64, "Choice 1"+chr$(9)+"Choice 2"+chr$(9)+"Choice 3"+chr$(9)+"Choice 4"+chr$(9)+"Choice 5", .DropListBox4
  GroupBox  1, 176, 312, 38, ""            
  PushButton  338, 136, 55, 19, "OK"
  CancelButton  338, 160, 55, 19
  GroupBox  318, 99, 96, 115, ""            
  Picture  326, 11, 84, 80, "C:\random.bmp", 0
  GroupBox  318, 1, 96, 99, ""                        
End Dialog
     
Dim Source as MainProg
On Error Resume Next
Dialog Source
CheckBox4 = Source.CheckBox4

So, if the Checkbox4 is clicked, it would kick up the Additional Dialog, and loop based on how many the user selected.

Add on Dialog
Code:
If (CheckBox4 = 1) Then        
Begin Dialog SecondProg 57, 71, 418, 78, "Additional Dialog Box", .FileDlgFunc2        
 Text  6, 8, 34, 9, "#"            
 TextBox  27, 7, 50, 14, .NumberBox            
 CheckBox  4, 24, 66, 8, "Add Info", .CheckBox2                                                
 Text 99, 24, 55, 8, "ListBox 1"            
 DropListBox  82, 8, 106, 64, "Choice 1"+chr$(9)+"Choice 2"+chr$(9)+"Choice 3"+chr$(9)+"Choice 4", .DropListBox1            
 Text 220, 24, 61, 8, "List Box 2"
 DropListBox  192, 8, 134, 64, "Choice 1"+chr$(9)+"Choice 2"+chr$(9)+"Choice 3"+chr$(9)+"Choice 4"+chr$(9)+"Choice 5", .DropListBox2                                    
 TextBox  5, 39, 27, 14, .TB1
 TextBox  40, 39, 18, 14, .TB2
 TextBox  64, 39, 66, 14, .TB3
 TextBox  138, 39, 28, 14, .TB4
 TextBox  192, 39, 28, 14, .TB5
 TextBox  226, 39, 28, 14, .TB6
 TextBox  260, 39, 28, 14, .TB7                                                
 Text  10, 55, 21, 8, "H", .T1            
 Text  44, 55, 12, 8, "D", .T2
 Text  85, 55, 34, 8, "S", .T3
 Text  143, 55, 19, 8, "T", .T4
 Text  201, 55, 14, 8, "A", .T5
 Text  232, 55, 14, 8, "B", .T6
 Text  269, 55, 18, 8, "F", .T7
 GroupBox  0, 0, 330, 67, ""
 PushButton  347, 14, 55, 19, "OK"
 CancelButton  347, 38, 55, 19
End Dialog

Dim Source2 as SecondProg
On Error Resume Next
Dialog Source2                
End If

Function controls
Code:
'--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------                
Function FileDlgFunction(identifier$, action, suppvalue)
'--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------                
                 
    Select Case action
        Case 1
             DlgEnable ("CheckBox0"),1
             DlgEnable ("CheckBox1"),1
             DlgEnable ("TextBox1"),0                            
        Case 2
            Select Case identifier$
            Case "CheckBox1"            
              If DlgValue("CheckBox1") = 1 Then
                  DlgEnable "TextBox1",1
                  DlgEnable "CheckBox0",0                               
              Else
                  DlgEnable "TextBox1",0
                  DlgEnable "CheckBox0",1
              End If                                                                   
            End Select                                         
    End Select 
    
'--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------                
    
    Select Case action
        Case 1
             DlgEnable ("CheckBox0"),1
             DlgEnable ("CheckBox1"),1
             DlgEnable ("TextBox1"),0 
        Case 2
            Select Case identifier$
            Case "CheckBox0"
              If DlgValue("CheckBox0") = 1 Then
                  DlgEnable "CheckBox1",0
              Else
                  DlgEnable "CheckBox1",1
              End If
            End Select
    End Select
    
'--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------                
    
    Select Case action
        Case 1        
            DlgEnable("CheckBox2"),1
            DlgEnable("TextBox12"),0                                          
        Case 2                
            Select Case identifier$            
            Case "CheckBox2"            
              If DlgValue("CheckBox2") = 1 Then
                  DlgEnable "TextBox12",1
              Else
                  DlgEnable "TextBox12",0
              End If        
            End Select
    End Select
    
'--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------                

    Select Case action
        Case 1
            DlgEnable("CheckBox3"),1
            DlgEnable("TextBox13"),0
        Case 2                
            Select Case identifier$
            Case "CheckBox3"
              If DlgValue("CheckBox3") = 1 Then
                  DlgEnable "TextBox13",1
              Else
                  DlgEnable "TextBox13",0
              End If
            End Select
    End Select
    
'--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------                

    Select Case action
        Case 1
            DlgEnable("CheckBox4"),1
            DlgEnable("DropListBox2"),0
            DlgEnable("AddLine"),0
        Case 2
            Select Case identifier$
            Case "CheckBox4"
              If DlgValue("CheckBox4") = 1 Then
                  DlgEnable "DropListBox2",1
                  DlgEnable "AddLine",1
              Else
                  DlgEnable "DropListBox2",0
                  DlgEnable "AddLine",0
              End If
            End Select
    End Select                                     
End Function


'--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Function FileDlgFunc2(identify$, act, supvalue)
'--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Select Case act
        Case 1
            DlgEnable("CheckBox2"),1            
            DlgEnable("TB1"),0
            DlgEnable("T1"),0            
            DlgEnable("TB2"),0
            DlgEnable("T2"),0            
            DlgEnable("TB3"),0
            DlgEnable("T3"),0            
            DlgEnable("TB4"),0
            DlgEnable("T4"),0            
            DlgEnable("TB5"),0
            DlgEnable("T5"),0            
            DlgEnable("TB6"),0
            DlgEnable("T6"),0            
            DlgEnable("TB7"),0
            DlgEnable("T7"),0           
        Case 2
            Select Case identify$
            Case "CheckBox2"
              If DlgValue("CheckBox2") = 1 Then
                  DlgEnable "TB1",1
                  DlgEnable "T1",1
                  DlgEnable "TB2",1
                  DlgEnable "T2",1
                  DlgEnable "TB3",1
                  DlgEnable "T3",1
                  DlgEnable "TB4",1
                  DlgEnable "T4",1
                  DlgEnable "TB5",1
                  DlgEnable "T5",1
                  DlgEnable "TB6",1
                  DlgEnable "T6",1
                  DlgEnable "TB7",1
                  DlgEnable "T7",1
              Else
                  DlgEnable "TB1",0
                  DlgEnable "T1",0
                  DlgEnable "TB2",0
                  DlgEnable "T2",0
                  DlgEnable "TB3",0
                  DlgEnable "T3",0
                  DlgEnable "TB4",0
                  DlgEnable "T4",0
                  DlgEnable "TB5",0
                  DlgEnable "T5",0
                  DlgEnable "TB6",0
                  DlgEnable "T6",0
                  DlgEnable "TB7",0
                  DlgEnable "T7",0
              End If
            End Select
    End Select
End Function
'--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Based on what you wrote, would I need to change to an array for the droplistbox to enable the loop?

Again, thank you for the help.
 
Based on what you wrote, would I need to change to an array for the droplistbox to enable the loop?

Nope. You can still use strings with Chr(9) to seperate the items in your list boxes.
 
What are the parameters of a header file to include your Dim statements along with their variables?

Example in header:
Code:
Sub Anyname 
Dim Hello
Hello = "Hi!"
End Sub

And then in the macro file, have
Code:
Anyname

to reference that string, and use it with a PutString command.

Out of the secondary Dialog box I have, there were 1 droplist with 4 choices, 1 droplist with 5 choices, and 8 text entries per loop. So, for just one loop, I'm looking at 17 variables to assign, and then concatenate with other strings and use later on in the program through many If / then's.
Basically, I've ran out of room in the main program and have to break it up.
 
Do you want a sub that can change the value of the variables for like the list boxes? If you Dim the values outside of a Sub/Function and before any Sub/Function that will use them, the variables will pass to any Sub/Function.

Code:
'Header File
Dim X, Y, Z
Sub SetVarsAsX
    X = "X"
    Y = "X"
    Z = "X"
End Sub

Sub SetVarXasY
    X = "Y"
    Y = "Y"
    Z = "Y"
End Sub

Code:
'Main File
'$include "Header.ebh"
Sub Main
    SetVarXasX
    MsgBox X & Y & Z
    SetVarXasY
    MsgBox X & Y & Z
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top