Jump to content

Input Box to Combo Box


Recommended Posts

I want to start by appologizing if this has previously been covered, I tried searching - but I don't really know what I'm looking for.

Just started working with this and am attempting at a few simple (or seems to be) commands to brush up on AutoIt, but seems I have come to a sort of problem. (I haven't worked with autoit since one of the first versions, :))

I'll start by giving you some coding to show what I'm attempting, (Used Koda for this to make a super fast example, kudos to koda :))

#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form = GUICreate("GETVariable", 187, 118, 436, 356)
$PageControl1 = GUICtrlCreateTab(8, 8, 172, 104)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
; I want the number to be input here between 1-1500
$Input1 = GUICtrlCreateInput("", 40, 64, 121, 22, BitOR($ES_NUMBER))
GUICtrlSetLimit(-1, 4)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Label1 = GUICtrlCreateLabel("Input Variable Here", 40, 48, 96, 18)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
GUICtrlSetState(-1,$GUI_SHOW)
; I want the number sent here, in a list of 1, 2, 3, etc. all the way up to number entered
$Combo1 = GUICtrlCreateCombo("", 40, 64, 113, 25)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Label2 = GUICtrlCreateLabel("Select Variable 1-????", 40, 48, 114, 18)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Now, what I wish to attempt is this:

Ability to go to Tab1 and insert a 4 digit number (I wish to make this from 1-1500, but can only do 1-9999?)

Get that number from Input1, and insert into Combo1 a dropdown of 1, 2, 3, 4, etc (up to number entered, 1-20, 1-100, etc)

A few other things I will be attempting after this part is tackled is to take each number, (ie: 1, 2, 3, 4, etc up to inputted number) and have other drop down menus (combo boxes) where you select an item (ie: starbucks coffee) and it automatically says on a third tab, for instance [Day 1: Starbucks coffee - $6, McDonalds - $8, Fill up Gas tank - $60, Total: $74] And maybe insert this into a table on Excel.

I do not wish to have the prices listed on the combo boxes, just the name (ie: Starbucks Coffee)

I would also like to have maybe (A save button might be needed?) Where it keeps data for each Day(# selected from 1st combo box)

But you're able to scroll to DAY2 from DAY1 and it has all of the values from DAY1 still saved as you input DAY2, then when you click TAB3 you can scroll from DAY1 at the top to DAY2 and get final results (what each value is, quantity had, and total) from both. And a selection for All days Total, broken down (ie: DAY1: $74, DAY2:$30, DAY3:$100, Total:$204)

Then maybe send to excel [i saw a post for this already so I'll read up on that when I get to this point]

If any of this is un-understandable (teehee, call me G.W. Bush, I can make up words, too!) please feel free to ask questions. If I just need to re-read the help file, or read all 300 pages of search results, also let me know. Or are commands like this even easily available without writing 1500 times, If=20 Goto? which lists a combo box result of 1,2 ,3 ,4 etc to 20?

Calling me a newb. Oh yeah, idiotic flaming will be tolerated, because I feel I am making this seem harder than it is and already read over my answer without noticing it. (>.<)

[Atleast I use proper grammer and spelling though, doesn't that count for something?)

Happy coding and thank you all very much in advance. Kudos.

(Editted to include full coding)

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. :)
Link to comment
Share on other sites

#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GuiComboBox.au3>

#Region ### START Koda GUI section ### Form=
$Form = GUICreate("GETVariable", 187, 118, 436, 356)
$PageControl1 = GUICtrlCreateTab(8, 8, 172, 104)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
; I want the number to be input here between 1-1500
$Input1 = GUICtrlCreateInput("", 40, 64, 121, 22, $ES_NUMBER)
GUICtrlSetLimit(-1, 4)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Label1 = GUICtrlCreateLabel("Input Variable Here", 40, 48, 96, 18)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$TabSheet2 = GUICtrlCreateTabItem("TabSheet2")
GUICtrlSetState(-1,$GUI_SHOW)
; I want the number sent here, in a list of 1, 2, 3, etc. all the way up to number entered
$Combo1 = GUICtrlCreateCombo("", 40, 64, 113, 25)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Label2 = GUICtrlCreateLabel("Select Variable 1-????", 40, 48, 114, 18)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $nCurVar, $nLastVar = ""

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    $nCurVar = Int(GUICtrlRead($Input1))
    If $nCurVar <> $nLastVar And $nCurVar > 0 Then
        _GUICtrlComboBox_ResetContent($Combo1)
        For $i=1 To $nCurVar
            _GUICtrlComboBox_AddString($Combo1, $i)
        Next
        $nLastVar = $nCurVar
    EndIf
WEnd

Edited by zorphnog
Link to comment
Share on other sites

<3 Fear and Loathing, BTW

How? What exactly am I missing, here? Do I need to thoroughly examine the readme a few times to understand all of these different things I am attempting? Is there any files I can download to help expedite my expedition? Would you mind explaining this to me so I am actually learning instead of just copy/paste?

I actually just really want hints to all of these things I'm attempting so I'm not totally lost saying "fu..orget this". I really want to learn (believe it or not, I know you all get asked to do someone elses work for them all the time).

:) Also, thank you so very much - if you don't reply I guess I will find myself playing around with this alot.

Also, is there something I could do about making the max number 1500 instead of 9999? maybe a function of 'ifvariable =+1500' msgbox saying only integers between 1-1500. or maybe a helptool box like the one that pops up if you attempt to enter a letter.. I guess it would be easier to have it pop a msgbox when you switch tabs. Hmmm.. Now my gears are turning, thanks :)

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. :)
Link to comment
Share on other sites

Haha. I feel like half the time nobody even gets the fear and loathing thing. Finally, another fan!!

I guess I'll start by saying that GuiGetMsg is not a blocking function (as i think is a common misconception of most noobs), meaning that it does not wait until a gui message is generated to return. It simply returns whats in the message queue. That being said, your While...WEnd loop is constantly looping. So I added a conditional check. $nCurVar stores what is in the $Input1 field, then compares it to what was previously in that same field ($nLastVar). If they're not equal (<>) AND the number is not negative, then I erase the contents of the combobox (_GUICtrlComboBox_ResetContent) and add the new numbers via a For...To loop.

So if we wanted to ensure that the number is not greater than 1500, we could add another condition to our statement (And $nCurVar <= 1500). Now if you want to have an error message pop-up to tell the user to enter a number less than 1500 then we can add a ElseIf clause to display a MsgBox. And the resulting code will look like so:

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    $nCurVar = Int(GUICtrlRead($Input1))
    If $nCurVar <> $nLastVar And $nCurVar > 0 And $nCurVar <= 1500 Then
        _GUICtrlComboBox_ResetContent($Combo1)
        For $i=1 To $nCurVar
            _GUICtrlComboBox_AddString($Combo1, $i)
        Next
        $nLastVar = $nCurVar
    ElseIf $nCurVar > 1500 Then
        MsgBox(0, "Error", "You must enter a number between 1 and 1500.")
        GUICtrlSetData($Input1, "")
    EndIf
WEnd

Hope that helps a little.

Link to comment
Share on other sites

You answered this question before I finished typing code :)

I do not have these GUI commands in my helpfile. Did it not automatically overwrite the helpfile when I installed a new version, or are these GUI functions not in the helpfile?

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. :)
Link to comment
Share on other sites

They should be in the help file as long as you installed the UDFs when you installed AutoIt. Try re-opening the help file.

I re-installed it through self-extract and everythings great now :)

But... (instead of opening a new thread and wasting valuable space)

Why do I have to click the button (sometimes) multiple times for it to transfer data with this code?

#Region ### START Koda GUI section ### Form=
$Form3 = GUICreate("Form3", 163, 115, 311, 345)
$Input1 = GUICtrlCreateInput("Input1", 24, 16, 121, 21, 0)
GUICtrlSetLimit(-1, 26)
$Label1 = GUICtrlCreateLabel("Label1", 24, 48, 124, 17)
$Save = GUICtrlCreateButton("Save", 40, 80, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $Answer, $msg, $nMsg
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Form3
    EndSwitch
    $msg = GUIGetMsg()
    Select
    Case $msg = $Save
        $Answer = GUICtrlRead($Input1)
        GUICtrlSetData($Label1, $Answer)
    EndSelect   
WEnd

also, what kind of program is OnEvent most desirable for?

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. :)
Link to comment
Share on other sites

You only want to call GUIGetMsg once in a loop. Move your "Case $msg = Save" into your switch statement.

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form3 = GUICreate("Form3", 163, 115, 311, 345)
$Input1 = GUICtrlCreateInput("Input1", 24, 16, 121, 21, 0)
GUICtrlSetLimit(-1, 26)
$Label1 = GUICtrlCreateLabel("Label1", 24, 48, 124, 17)
$Save = GUICtrlCreateButton("Save", 40, 80, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $Answer, $msg, $nMsg
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Save
            $Answer = GUICtrlRead($Input1)
            GUICtrlSetData($Label1, $Answer)
    EndSwitch
WEnd
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...