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!

User form information extraction 2

Status
Not open for further replies.

dvirgint

Programmer
Jun 28, 2010
85
CA
Hello, I've posted a few questions before and have always received great answers. Thanks for that.

Here is my current question:

I am trying to create a user form with 1 text boxes, and a checkbox question with 4 possible answers. I have selected the checkbox option instead of radio buttons because the users will be able to select more than one answer.

At first, I was unable to make the form appear, however after looking in the Extra! Basic manual, I figured out how to display the user form. My problem now, is extracting the answers once the "OK" button is clicked. Here is the code I have so far for the form:

Begin Dialog YearsContract 150, 82 "I N F O"
OkButton 83, 41, 50, 14
CancelButton 83, 57, 50, 14
Text 8, 4, 140, 8, "What year(s)?"
CheckBox 20, 36, 57, 9, "2008",.Y08
CheckBox 20, 51, 57, 9, "2009",.Y09
CheckBox 20, 36, 57, 9, "2010",.Y10
CheckBox 20, 36, 57, 9, "2011",.Y11
Text 20, 36, 57, 9, "What is the contract number?"
TextBox 20, 36, 57, 9, .Contract
End Dialog

dim mydialog as YearsContract
Dialog mydialog

... so that will display the user form. I am aware that a lot of the coordinates don't make sense, I'm writing this from home.

I assume that what is after the last comma in the "CheckBox" and "TextBox" lines (ex. .Y08, .Contract) are where the answers are stored. How can I display them?

Where I work has a letter writing program which I can make macros to automate, and would like to include these answers in. How would I use them?

Thanks for any help you all can provide.
 
here's one way
Code:
Sub Main

Begin Dialog YearsContract 71, 28, 250, 240, "I N F O"  

        OkButton     62, 150, 70, 24
        CancelButton 62, 180, 70, 24
        
        
        Text     8, 4, 140, 8, "What year(s)?"  

        CheckBox 5, 26, 57, 9, "2008",.Y08  
        CheckBox 5, 36, 57, 9, "2009",.Y09  
        CheckBox 5, 46, 57, 9, "2010",.Y10  
        CheckBox 5, 56, 57, 9, "2011",.Y11  

        Text    20, 76, 157, 9, "What is the contract number?"  
        TextBox 20, 86, 57,  9, .Contract

End Dialog

dim mydialog as YearsContract

    'dialog mydialog

    mydlg = Dialog(mydialog)


       i2008 = mydialog.Y08 
       i2009 = mydialog.Y09 
       i2010 = mydialog.Y10 
       i2011 = mydialog.Y11 

       msgbox i2008
       msgbox i2009
       msgbox i2010
       msgbox i2011
       
       
       iContract = mydialog.Contract
       msgbox iContract
       
       
End Sub
 
Thanks. Works perfectly.

I did run into another problem though, that I hadn't foreen:

I have since added the years 2000 to 2007 and as I mentionned earlier, I have to write a letter with the selected dates included in a sentence, so I made the new variables correspond with the year, ex.

If i2008 = then
i2008 = 2008
End if

How could I make the macro make a sentence, such as "You have a contract in years 2002, 2004 and 2010."

Thanks again for the help.
 
Begin Dialog YearsForm 150, 225, "Form?"
OkButton 83, 41, 50, 14
CancelButton 83, 57, 50, 14
Text 8, 20, 140, 8, "Form(s) required?"
CheckBox 20, 36, 57, 9, "2001", .Y01
CheckBox 20, 51, 57, 10, "2002", .Y02
CheckBox 20, 66, 57, 10, "2003", .Y03
CheckBox 20, 81, 57, 10, "2004", .Y04
CheckBox 20, 96, 57, 10, "2005", .Y05
CheckBox 20, 111, 57, 10, "2006", .Y06
CheckBox 20, 126, 57, 10, "2007", .Y07
CheckBox 20, 141, 57, 10, "2008", .Y08
CheckBox 20, 156, 57, 10, "2009", .Y09
CheckBox 20, 171, 57, 10, "2010", .Y10
CheckBox 20, 186, 57, 10, "2011", .Y11
End Dialog

dim OVPDiag as YearsForm
dialog OVPDiag

If OVPDiag.Y01 = 1 Then
OVPDiag.Y01 = Str(", 2001")
Else
OVPDiag.Y01 = Str("")
End If

If OVPDiag.Y02 = 1 Then
OVPDiag.Y02 = Str(", 2002")
Else
OVPDiag.Y02 = Str("")
End If

If OVPDiag.Y03 = 1 Then
OVPDiag.Y03 = Str(", 2003")
Else
OVPDiag.Y03 = Str("")
End If

If OVPDiag.Y04 = 1 Then
OVPDiag.Y04 = Str(", 2004")
Else
OVPDiag.Y04 = Str("")
End If

If OVPDiag.Y05 = 1 Then
OVPDiag.Y05 = Str(", 2005")
Else
OVPDiag.Y05 = Str("")
End If

If OVPDiag.Y06 = 1 Then
OVPDiag.Y06 = Str(", 2006")
Else
OVPDiag.Y06 = Str("")
End If

If OVPDiag.Y07 = 1 Then
OVPDiag.Y07 = Str(", 2007")
Else
OVPDiag.Y07 = Str("")
End If

If OVPDiag.Y08 = 1 Then
OVPDiag.Y08 = Str(", 2008")
Else
OVPDiag.Y08 = Str("")
End If

If OVPDiag.Y09 = 1 Then
OVPDiag.Y09 = Str(", 2009")
Else
OVPDiag.Y09 = Str("")
End If

If OVPDiag.Y10 = 1 Then
OVPDiag.Y10 = Str(", 2010")
Else
OVPDiag.Y10 = Str("")
End If

If OVPDiag.Y11 = 1 Then
OVPDiag.Y11 = Str(", 2011")
Else
OVPDiag.Y11 = Str("")
End If



Msgbox "You selected" + Str(OVPDiag.Y01) + Str(OVPDiag.Y02) + Str(OVPDiag.Y03) + Str(OVPDiag.Y04) + Str(OVPDiag.Y05) + Str(OVPDiag.Y06) + Str(OVPDiag.Y07) + Str(OVPDiag.Y08) + Str(OVPDiag.Y09) + Str(OVPDiag.Y10) + Str(OVPDiag.Y11) + ".
 
best i can do with my limited knowledge. there are better ways

Code:
Sub Main
BeginDial:
    Begin Dialog YearsContract 71, 28, 250, 240, "I N F O" 

        OkButton     100, 150, 70, 14
        CancelButton 100, 180, 70, 14

        Text     5,  10, 100,9, "What is the contract number?" 
        TextBox  5,  20, 57, 9, .Contract


        Text     5,  80, 90, 9, "What year(s)?" 

        CheckBox 5,  90, 57, 9, "2000",.Y00 
        CheckBox 5, 100, 57, 9, "2001",.Y01 
        CheckBox 5, 110, 57, 9, "2002",.Y02 
        CheckBox 5, 120, 57, 9, "2003",.Y03

        CheckBox 5, 130, 57, 9, "2004",.Y04 
        CheckBox 5, 140, 57, 9, "2005",.Y05 
        CheckBox 5, 150, 57, 9, "2006",.Y06 
        CheckBox 5, 160, 57, 9, "2007",.Y07 

        CheckBox 5, 170, 57, 9, "2008",.Y08 
        CheckBox 5, 180, 57, 9, "2009",.Y09 
        CheckBox 5, 190, 57, 9, "2010",.Y10 
        CheckBox 5, 200, 57, 9, "2011",.Y11

    End Dialog

    dim mydialog as YearsContract

'dialog mydialog

    mydlg = Dialog(mydialog)
    
    select case mydlg
    
        case 0 : exit sub
    
    end select

    
    i2000 = mydialog.Y00 
    i2001 = mydialog.Y01 
    i2002 = mydialog.Y02 
    i2003 = mydialog.Y03 

    i2004 = mydialog.Y04 
    i2005 = mydialog.Y05 
    i2006 = mydialog.Y06 
    i2007 = mydialog.Y07 
    
    i2008 = mydialog.Y08 
    i2009 = mydialog.Y09 
    i2010 = mydialog.Y10 
    i2011 = mydialog.Y11 
    
    iContract = mydialog.Contract

'//-----------------------------------

    nbryr = ""
    
    if i2000 = 1 then nbryr = 2000
    
    if i2001 = 1 then 
        if nbryr = "" then 
            nbryr = 2001
        else
            nbryr = nbryr & ", " & 2001
        end if 
    end if

    if i2002 = 1 then 
        if nbryr = "" then 
            nbryr = 2002
        else
            nbryr = nbryr & ", " & 2002
        end if 
    end if
    
    if i2003 = 1 then 
        if nbryr = "" then 
            nbryr = 2003
        else
            nbryr = nbryr & ", " & 2003
        end if 
    end if
    
    if i2004 = 1 then 
        if nbryr = "" then 
            nbryr = 2004
        else
            nbryr = nbryr & ", " & 2004
        end if  
    end if
    
    if i2005 = 1 then 
        if nbryr = "" then 
            nbryr = 2005
        else
            nbryr = nbryr & ", " & 2005
        end if 
    end if
    
    if i2006 = 1 then 
        if nbryr = "" then 
            nbryr = 2006
        else
            nbryr = nbryr & ", " & 2006
        end if 
    end if
    
    if i2007 = 1 then 
        if nbryr = "" then 
            nbryr = 2007
        else
            nbryr = nbryr & ", " & 2007
        end if 
    end if
    
    if i2008 = 1 then 
        if nbryr = "" then 
            nbryr = 2008
        else
            nbryr = nbryr & ", " & 2008
        end if 
    end if
    
    if i2009 = 1 then 
        if nbryr = "" then 
            nbryr = 2009
        else
            nbryr = nbryr & ", " & 2009
        end if 
    end if
    
    if i2010 = 1 then 
        if nbryr = "" then 
            nbryr = 2010
        else
            nbryr = nbryr & ", " & 2010
        end if 
    end if
    
    if i2011 = 1 then 
        if nbryr = "" then 
            nbryr = 2011
        else
            nbryr = nbryr & ", " & 2011
        end if 
    end if    
    
    if iContract = "" then goto BeginDial
    
    if nbryr = "" then goto BeginDial
    
    msgbox "You have a contract " & iContract & " in year(s) : " & nbryr
    
    

End Sub


i feel hard coding the years is not the best way to go.

 
I see what you did. Makes so much sense.

Thanks for helping me on this.
 
Know you got an answer, but this can make things easier in the future.

Code:
Sub Main
BeginDial:
    Begin Dialog YearsContract 71, 28, 250, 240, "I N F O" 

    OkButton 100, 150, 70, 14
    CancelButton 100, 180, 70, 14

    Text 5, 10, 100,9, "What is the contract number?" 
    TextBox 5, 20, 57, 9, .Contract


    Text 5, 80, 90, 9, "What year(s)?" 

    CheckBox 5, 90, 57, 9, "2000",.Y00 
    CheckBox 5, 100, 57, 9, "2001",.Y01 
    CheckBox 5, 110, 57, 9, "2002",.Y02 
    CheckBox 5, 120, 57, 9, "2003",.Y03

    CheckBox 5, 130, 57, 9, "2004",.Y04 
    CheckBox 5, 140, 57, 9, "2005",.Y05 
    CheckBox 5, 150, 57, 9, "2006",.Y06 
    CheckBox 5, 160, 57, 9, "2007",.Y07 

    CheckBox 5, 170, 57, 9, "2008",.Y08 
    CheckBox 5, 180, 57, 9, "2009",.Y09 
    CheckBox 5, 190, 57, 9, "2010",.Y10 
    CheckBox 5, 200, 57, 9, "2011",.Y11

    End Dialog

    dim mydialog as YearsContract

'dialog mydialog

    mydlg = Dialog(mydialog)

    select case mydlg

        case 0 : exit sub

    end select

    Dim i(11) as integer
    i(0) = mydialog.Y00 
    i(1) = mydialog.Y01 
    i(2) = mydialog.Y02 
    i(3) = mydialog.Y03 

    i(4) = mydialog.Y04 
    i(5) = mydialog.Y05 
    i(6) = mydialog.Y06 
    i(7) = mydialog.Y07 

    i(8) = mydialog.Y08 
    i(9) = mydialog.Y09 
    i(10) = mydialog.Y10 
    i(11) = mydialog.Y11 

    iContract = mydialog.Contract

'//-----------------------------------

    nbryr = ""
    For iterator = 0 To 11
        If i(iterator) = 1 Then 
            If nbryr = "" Then
                nbryr = 2000 + iterator
            Else
                nbryr = nbryr & ", " & 2000 + iterator
            End If
        End If
    Next

    if iContract = "" then goto BeginDial

    if nbryr = "" then goto BeginDial

    msgbox "You have a contract " & iContract & " in year(s) : " & nbryr

End Sub
 
Thanks Lakare, I'll make these changes right away. They will make things a lot easier, and the code a lot shorter.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top