Sign in to follow this  
Followers 0
Anonymouse

Data for One Combo Depends On Another

6 posts in this topic

#1 ·  Posted (edited)

I tried searching for this, but I don't even know how to explain it. Sorry.

What I'm Attempting is this:

I have a 5 combo boxes, they all read from an .ini (because they have to be edited after compilation)

4 Of the Combo boxes Selection Choices depend on the Selection choice of the 1st one.

So, say Combo #1 has 2 different selections, "ABC" and "123"

If you select "ABC" then the next 4 combo boxes will be filled with all 26 letters of the alphabet to choose from (read from ini section [ABC])

If you select "123" then numbers 1-26 will be listed (read from ini section [123])

-----------

So how would I go about this?

#include <GUIConstantsEx.au3>
#include <ExcelCOM_UDF.au3>

Opt('MustDeclareVars', 1)

Global $PAIGVEC, $PAICOS, $msg, $Company, $Export, $CI, $var1, $var2

Dim $combo[4], $b

GUICreate("My GUI combo")
$PAIGVEC = IniReadSection("C:\\myfile.ini", "GVEC-Assembly")
$PAICOS = IniReadSection("C:\\myfile.ini", "COS-Assembly")
$CI = IniReadSection("C:\\myfile.ini", "Company")
$combo[0] = GuiCtrlCreateCombo("", 10, 10)
$combo[1] = GuiCtrlCreateCombo("", 10, 50)
$combo[2] = GuiCtrlCreateCombo("", 10, 90)
$combo[3] = GuiCtrlCreateCombo("", 10, 130)
$Company = GUICtrlCreateCombo("", 10, 250)
$Export = GuiCtrlCreateButton("Excel", 10, 170)


For $a = 1 To $CI[0][0]
    GUICtrlSetData($Company, $CI[$a][1])
Next
GUISetState()

$var1 = IniRead("C:\myfile.ini", "Company", "C1", "NotFound")
$var2 = IniRead("C:\myfile.ini", "Company", "C2", "NotFound")

If $Company = $var1 Then
    For $a = 1 To $PAIGVEC[0][0]
        For $b = 0 To Ubound($combo) -1
        GUICtrlSetData($combo[$b], $PAIGVEC[$a][1])
        Next
    Next
    GUISetState()
ElseIf $Company = $var2 Then
    For $a = 1 To $PAICOS[0][0]
        For $b = 0 To Ubound($combo) -1
        GUICtrlSetData($combo[$b], $PAICOS[$a][1])
        Next
    Next
    GUISetState()
EndIf




While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
        Exit
        Case $Export
            _Export()
    EndSwitch   
WEnd
    
Func _Export()
    Dim $PAU0, $PAU1, $PAU2, $PAU3
    $PAU0 = GUICtrlRead($combo[0])
    $PAU1 = GUICtrlRead($combo[1])
    $PAU2 = GUICtrlRead($combo[2])
    $PAU3 = GUICtrlRead($combo[3])
    Local $oExcel = _ExcelBookOpen("C:\Documents and Settings\Nicker\Desktop\template.xls")
    _ExcelWriteCell($oExcel, "Unit 1", 13, 1)
    _ExcelWriteCell($oExcel, $PAU1, 14, 1)
    _ExcelWriteCell($oExcel, $PAU2, 15, 1)
    _ExcelWriteCell($oExcel, $PAU3, 16, 1)
EndFunc

Sorry if this is difficult to understand, let me know if you need anymore information.

Edited by Anonymouse

children may smile; the wise ponder- Dr. Holmes of Hardvard Medical School on an Ether BingeLove Makes The World Go Round?So does five shots of tequila. What's your point?[quote name='Valik' date='Jun 5 2008, 05:13 PM']wraithdu, 24 hours. Said I have a bad attitude, just driving the point home with a ban.[/quote]This is classic. :)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Create a function using the following logic:

Func Combo1Change() ; function called when something is changing in the combobox
    Select
        Case GUICtrlRead($combo1) = "ABC"
            ;set data in the other 4 combo's (A,B,C, ...)
        Case GUICtrlRead($combo1) = "123"
            ;set data in the other 4 combo's (1,2,3, ...)
        Case Else
            MsgBox(0, "Error", "Unknown Content")
    EndSelect
EndFunc

You will have to create a new Case for each different content.

This is all you need; you will work a little on it but that's the idea.

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

hi!

where does the #include <ExcelCOM_UDF.au3> comes from?

also, use [ autoit ] and [ / autoit ] tags to put the code in a small block.

Global $Value, $index,$tempString

While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
        Exit
        Case $Export
            _Export()
            
        case $combo[0];if combo is used
            ;read Value from combo
            $Value = GUICtrlRead($combo[0])
            If $Value = "123" Then
                $tempString = ""
                for $index = 1 to 26 ;one example
                    $tempString = $tempString & $index & "|"
                Next
                ;trim the last "|"
                $tempString = StringTrimRight($tempString,1)
                
                for $index = 1 to 3 
                        GUICtrlSetData($combo[$index],"");Clean
                        GUICtrlSetData($combo[$index],$tempString,"1");fill the combos
                Next
            Elseif $Value = "ABC" Then
                for $index = 1 to 3 ;other example
                        GUICtrlSetData($combo[$index],"");Clean
                        GUICtrlSetData($combo[$index],"A|B|C|D|E|F|G|H","A")
                Next
            EndIf
    EndSwitch    
WEnd

hope it helps


You can help! Donate to AutoIt! or, visit ClimatePREDICTION.netMy posts:Travian Bot Example (100+ servers) BETAHow to Host you code/app for free! (unlimited team number) (Public or Private)"Sir, we're surrounded!" "Excellent. We can attack in any direction!"

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

http://www.autoitscript.com/forum/index.ph...02&hl=excel

for the excel UDF made by:

SEO aka Locodarwin, DaLiMan, Stanley Lim, MikeOsdx, MRDev, big_daddy, PsaltyDS

Also, thank both of you. I understand more and more every day, I think writing and reading code for hours on end tends to make me overlook simple solutions -.-

[Edit] I don't use autoit tags because I've seen people complain about them on occasion[/edit]

Edited by Anonymouse

children may smile; the wise ponder- Dr. Holmes of Hardvard Medical School on an Ether BingeLove Makes The World Go Round?So does five shots of tequila. What's your point?[quote name='Valik' date='Jun 5 2008, 05:13 PM']wraithdu, 24 hours. Said I have a bad attitude, just driving the point home with a ban.[/quote]This is classic. :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

[solved] Sorta... I had to add a button to make it functional, is there any other way? Anyways, here is final code - just in case it's helpful to anyone searching the forums.

#include <GUIConstantsEx.au3>
#include <ExcelCOM_UDF.au3>

Opt('MustDeclareVars', 1)

Global $PAIGVEC, $PAICOS, $msg, $Company, $Export, $CI, $var1, $var2, $Select, $Value

Dim $combo[4], $b


GUICreate("My GUI combo")
$PAIGVEC = IniReadSection("C:\\myfile.ini", "GVEC-Assembly")
$PAICOS = IniReadSection("C:\\myfile.ini", "COS-Assembly")
$CI = IniReadSection("C:\\myfile.ini", "Company")
$combo[0] = GuiCtrlCreateCombo("", 10, 10)
$combo[1] = GuiCtrlCreateCombo("", 10, 50)
$combo[2] = GuiCtrlCreateCombo("", 10, 90)
$combo[3] = GuiCtrlCreateCombo("", 10, 130)
$Company = GUICtrlCreateCombo("", 10, 250)
$Export = GuiCtrlCreateButton("Excel", 10, 170)
$Select = GuiCtrlCreateButton("Select", 50, 170)



For $a = 1 To $CI[0][0]
    GUICtrlSetData($Company, $CI[$a][1])
Next
GUISetState()




While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Export
            _Export()
        Case $Select
            For $b = 0 To Ubound($combo) -1
                GUICtrlSetData($combo[$b], "")
            Next
            GUISetState()
            $var1 = IniRead("C:\myfile.ini", "Company", "C1", "NotFound")
            $var2 = IniRead("C:\myfile.ini", "Company", "C2", "NotFound")
            $Value = GUICtrlRead($Company)
            If $Value = $var1 Then
                For $a = 1 To $PAIGVEC[0][0]
                    For $b = 0 To Ubound($combo) -1
                    GUICtrlSetData($combo[$b], $PAIGVEC[$a][1])
                    Next
                Next
                GUISetState()
            Elseif $Value = $var2 Then
                For $a = 1 To $PAICOS[0][0]
                    For $b = 0 To Ubound($combo) -1
                    GUICtrlSetData($combo[$b], $PAICOS[$a][1])
                    Next
                Next
                GUISetState()
            EndIf
    EndSwitch   
WEnd    

    
Func _Export()
    Dim $PAU0, $PAU1, $PAU2, $PAU3
    $PAU0 = GUICtrlRead($combo[0])
    $PAU1 = GUICtrlRead($combo[1])
    $PAU2 = GUICtrlRead($combo[2])
    $PAU3 = GUICtrlRead($combo[3])
    Local $oExcel = _ExcelBookOpen("C:\template.xls")
    _ExcelWriteCell($oExcel, "Unit 1", 13, 1)
    _ExcelWriteCell($oExcel, $PAU1, 14, 1)
    _ExcelWriteCell($oExcel, $PAU2, 15, 1)
    _ExcelWriteCell($oExcel, $PAU3, 16, 1)
EndFunc
Edited by Anonymouse

children may smile; the wise ponder- Dr. Holmes of Hardvard Medical School on an Ether BingeLove Makes The World Go Round?So does five shots of tequila. What's your point?[quote name='Valik' date='Jun 5 2008, 05:13 PM']wraithdu, 24 hours. Said I have a bad attitude, just driving the point home with a ban.[/quote]This is classic. :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0