DarkAngelBGE Posted June 3, 2007 Share Posted June 3, 2007 Hi there, I am making a little program for a company to ellect a manager. It basically goes like this: The user adds candidates. Votes are counted and saved. At the end of the election the winner is determined by a set of rules. What I am doing is having a hash of candidates. I create a list view to show the added candidates. Now when I click on a candidate in the ListView, I want a textfield to update with his number of votes. Also when I put in a new number and hit a save button the selected candidate's number of votes is updated. Here is the source code I have so far. Sorry that the captions are in german. Attached is the source code. The problem is the saving of the votes. I have no idea to access the selected element of the list view. Could you please help?vertreter_wahl.rar Link to comment Share on other sites More sharing options...
GEOSoft Posted June 3, 2007 Share Posted June 3, 2007 Hi there, I am making a little program for a company to ellect a manager. It basically goes like this:The user adds candidates. Votes are counted and saved. At the end of the election the winner is determined by a set of rules.What I am doing is having a hash of candidates. I create a list view to show the added candidates. Now when I click on a candidate in the ListView, I want a textfield to update with his number of votes. Also when I put in a new number and hit a save button the selected candidate's number of votes is updated.Here is the source code I have so far. Sorry that the captions are in german.Attached is the source code. The problem is the saving of the votes. I have no idea to access the selected element of the list view. Could you please help?For the list view element see the UDFs portion of the help file and look for GUIListView Management>_GUICtrlListViewGetCurSelAlso a script like this is probably better done using a database with 2 tablesThe first table has the list of candidates in the first column and the votes received in the secondThe second table should have a list of all of the elegible voters in the first column and the second column will just show if they have already voted or not. All you need here is to fill the second row with 0's. When an elegible voter votes the 0 is changed to a 1.The concept behind the second table is;If the voters name is not in the first column then they are not elegible to vote. (prevents padding by inelegible voters)If the second column for the elegible voter is set to 1 then they can not vote again. (prevents padding by multiple votes)In either case you disable the vote submission button.You can just use the SQL functions in the AutoIt include files or you can use an Access database if Acess is installed.Also when the Vote is submitted, there should be a refresh function that can just use _GUICtrlListViewGetText() and _GUICtrlListViewSetText()You can also look at the examples for GUIListView by following the link in my signature and then clicking on the UDF's3 WebHelp link near the bottom of the TOC frame on the left. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
DarkAngelBGE Posted June 4, 2007 Author Share Posted June 4, 2007 Ah cool, thank you. Will try the sql functions in the autoit include file. Thank you! Link to comment Share on other sites More sharing options...
DarkAngelBGE Posted June 16, 2007 Author Share Posted June 16, 2007 (edited) Okay I am now at it but I am getting a syntax error here: GUICtrlSetData($success,"Kandidat " & GUICtrlRead($inputVorname) & " " & GUICtrlRead($inputName) & " hinzugefügt!") $vorname = GUICtrlRead($inputVorname) $nachname = GUICtrlRead($inputName) $anschrift = GUICtrlRead($inputAnschrift) $plz = GUICtrlRead($inputPLZ) $stadt = GUICtrlRead($inputStadt) $stimmen = 0 $sqlstring = "INSERT INTO candidates (vorname,nachname,anschrift,plz,stadt,stimmen) VALUES ('"$vorname&"','"&$nachname&"','"&$anschrift&"','"&$plz&"','"&$stadt&"','"&$stimmen&"');" _SQLite_Exec(-1, $sqlstring) Syntax error is on the line where I set $sqlString. What is the problem? Edited June 16, 2007 by DarkAngelBGE Link to comment Share on other sites More sharing options...
The Kandie Man Posted June 16, 2007 Share Posted June 16, 2007 You forgot to add the first ampersand:$sqlstring = "INSERT INTO candidates (vorname,nachname,anschrift,plz,stadt,stimmen) VALUES ('"&$vorname&"','"&$nachname&"','"&$anschrift&"','"&$plz&"','"&$stadt&"','"&$stimmen&"');" - The Kandie Man ;-) "So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire Link to comment Share on other sites More sharing options...
DarkAngelBGE Posted June 17, 2007 Author Share Posted June 17, 2007 Ah thanks. Now my problem is that order by does not seem to work. Func _showWinners($aRow) global $h_winnerlist $vorname = $aRow[0] $nachname = $aRow[1] $stimmen = $aRow[5] ;Do not show column names if $vorname <> "vorname" AND $nachname <> "nachname" then GUICtrlSetData($h_winnerlist,$stimmen&" -- "&$vorname&" "&$nachname) EndIf EndFunc func calculateWinnerlist() $d = _SQLite_Exec(-1,"Select * From candidates ORDER BY stimmen ASC","_showWinners") endfunc ..does not sort them by stimmen (number of votes). Instead they come out into $h_winnerlist unordered. :/ Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now