Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/24/2014 in all areas

  1. Hello Here is my network UDF. Do not yell at me if it already exists ... I hope it will be useful to someone. Please, let me know if you have any problem. All functions that perform modifications required administrator rights Functions list : Internal functions only : Examples : #Include "network.au3" ; List of availables connections/cards #Include <array.au3> ; only for _ArrayDisplay() $infos = _GetNetworkAdapterList() _ArrayDisplay($infos) ; Network card informations for the network connection called "Local Area Network" $infos = _GetNetworkAdapterInfos("Local Area Network") _ArrayDisplay($infos) ; Disable a network connection _DisableNetAdapter("Broadcom NetLink (TM) Gigabit Ethernet") ; OR _DisableNetAdapter("Local Area Network") ; Enable a network connection _EnableNetAdapter("Local Area Network") ; OR _EnableNetAdapter("Broadcom NetLink (TM) Gigabit Ethernet") ; Enable DHCP (for IP Address) _EnableDHCP("Broadcom NetLink (TM) Gigabit Ethernet") ; OR _EnableDHCP("Local Area Network") ; Configure a static IP adress _EnableStatic("Broadcom NetLink (TM) Gigabit Ethernet", "192.168.10.11", "255.255.255.0") ; OR _EnableStatic("Local Area Network", "192.168.10.11", "255.255.255.0") ; Configure the default gateway _SetGateways("Broadcom NetLink (TM) Gigabit Ethernet", "192.168.10.1") ; OR _SetGateways("Local Area Network", "192.168.10.1") ; Configure DNS servers Local $DNS_SERVERS[4] = [ "192.168.100.1", "192.168.100.2", "192.168.100.3", "192.168.100.4" ] _SetDNSServerSearchOrder("Local Area Network", $DNS_SERVERS) ; OR _SetDNSServerSearchOrder("Broadcom NetLink (TM) Gigabit Ethernet", $DNS_SERVERS) ; Configure the DNS domain name _SetDNSDomain ("Local Area Network", "mondomain.loc") ; OR _SetDNSDomain ("Broadcom NetLink (TM) Gigabit Ethernet", "mondomain.loc") ; Configure the DNS suffixes for all connections : Local $DNS_SUFFIXES[2] = [ "mondomain.loc", "mydomain.priv" ] _SetDNSSuffixSearchOrder($DNS_SUFFIXES) ; Clear the DNS cache (like ipconfig /flushdns) _FlushDNS() ; Remove an entry from the DNS cache _FlushDNSEntry("www.autoitscript.com") ; Configure the WINS servers (very old, now ...) _SetWINSServer("Local Area Network", "192.168.100.251", "192.168.100.252") ; OR _SetWINSServer("Broadcom NetLink (TM) Gigabit Ethernet", "192.168.100.251", "192.168.100.252") ; Enable the two options : ; - Register this connection's address in DNS ( first parameter) ; - Use this connection's DNS suffix in DNS registration (second parameter) _SetDynamicDNSRegistration("Local Area Network", True, True) ; Release the DHCP lease _ReleaseDHCPLease() ; Renew the DHCP lease _RenewDHCPLease() ; Sets the Private category to the network connection called "LAN" _SetCategory("LAN", 1) Download link : Network.au3
    1 point
  2. For the SQLite developers... New version 1.0.0.6 This is a Report Generator for SQLite Database. The script supports up to two dynamic parameters per report, see the 'SQLite Reports.ini' file for more details. Single Date, period, string or number input are possible I provide a full functional example using the Chinook Demo Database (http://chinookdatabase.codeplex.com), so everyone can test it. All required files are contained in the zip file. You can download the zipfile in the link hereunder. I created 20 different reports, from which 4 are system reports and one is not linked to any table. Features: Up to 2 dynamic Parameters via input dialog box per reportMulti-line fields will display in a separate Window when you click on the cell containing multiline data (which cannot be displayed in a listview, if you click on a normal cell, the window will disapearDouble click on a row and a new Window will display the row vertically, usefull for rows with many columns.Export to ExcelFast, even with several thousands of rows (see Track report)SQL that do not deliver data (no rows, no columns) will display a popup message instead (for example using the VACUUM command)Of course you have to know SQL but I guess that everyone who programs SQLite will, right? The SQL scripts are stored in the ini file, where 3 sections ‘Titles, SQL and Parameters’ contain all the elements required for a report. For simplicity, I decided to store the SQL script in the ini file as a single line. The drawback is that the SQL is not easy to read or to maintain, but look at the example ' Invoice with details' where I join 8 tables. It's absolutely functional. Read the [sql readme] section for more details about dynamic parameters. I think its usage is pretty obvious. Know issues: When compiled as 64bit, double click does not function in the main menu, I don't know why but I cannot get this fixed. If anyone knows, I would be pleased to get some help on this. All the other functions, including the double click in the ListView do work. The script will use SQLite3.dll or SQLite3_x64.dll if compiled as a x64 App. The script is a simplified version of my multi-platform Database Report Generator using Active-X DB connection. This SQLite report script (1600 lines) has very basic features compared to the latter (for example it fully integrates the ExcelChart UDF developed by water) but it has 13000 lines and is not provided has open source (sorry L, an early version was released on this forum in 2009 but for Oracle only) I hope this one will be useful for you, I had some fun with it, took me 3 evenings to do the job. Enjoy. GreenCan Updates 1.0.0.6: Bug fixes (thanks jpm)Better GUI windows managementExcel export optimized_COMError implementedFull package: http://users.telenet.be/GreenCan/AutoIt/SQLite_Reports_1.0.0.6.zip (If you downloaded the full package of the previous version, you don't have to download it again) SQLite Reports 1.0.0.6.au3 SQLite Reports.ini : [General] ;Database=Chinook_Sqlite.sqlite Database=Chinook_Sqlite_AutoIncrementPKs.sqlite DateFormat=YYYY-MM-DD [Titles] Report=Album Report=sqlite_sequence (shows number of records for each table) Report=Artist Report=Customer Report=All Employees Report=Employees birthday - period Report=Employees birthday - Name contains Report=Genre Report=Invoice Report=Invoice - amount between Report=Track Report=MediaType Report=Invoice with details - one invoice selection Report=Playlist Report=PlaylistTrack Report=Non-Database - Date formats examples Report=System - Tables and fields (sqlite_master) Report=System - List Tables of DataBase (sqlite_master) Report=System - SQLite version Report=System - Database cleanup (Vacuum) [SQL] Report=SELECT AlbumId, Title, ArtistId FROM Album Report=SELECT name,seq FROM sqlite_sequence Report=SELECT ArtistId, Name FROM Artist ORDER BY Name Report=SELECT CustomerId, FirstName, LastName, Company, Address, City, State, Country, PostalCode, Phone, Fax, Email, SupportRepId FROM Customer ORDER BY CustomerId Report=SELECT EmployeeId, LastName, FirstName, Title, ReportsTo, BirthDate, HireDate, Address, City, State, Country, PostalCode, Phone, Fax, Email FROM Employee Report=SELECT EmployeeId, LastName, FirstName, Title, ReportsTo, date(BirthDate) as BirthDate, date(HireDate), Address, City, State, Country, PostalCode, Phone, Fax, Email FROM Employee WHERE BirthDate between '%d1%' AND '%d2%' Report=SELECT EmployeeId, LastName, FirstName, Title, ReportsTo, date(BirthDate) as BirthDate, date(HireDate), Address, City, State, Country, PostalCode, Phone, Fax, Email FROM Employee WHERE LastName || ' ' || FirstName like '%%1%%' Report=SELECT GenreId, Name FROM Genre Report=SELECT InvoiceId, CustomerId, InvoiceDate, BillingAddress, BillingCity, BillingState, BillingCountry, BillingPostalCode, Total FROM Invoice Report=SELECT InvoiceId, CustomerId, Date(InvoiceDate), BillingAddress, BillingCity, BillingState, BillingCountry, BillingPostalCode, Total FROM Invoice WHERE Total between %1% AND %2% Report=SELECT TrackId, Name, AlbumId, MediaTypeId, GenreId, Composer, Milliseconds, Bytes, UnitPrice FROM Track Report=SELECT MediaTypeId, Name FROM MediaType Report=SELECT Invoice.InvoiceId, Date(Invoice.InvoiceDate) as "Invoice Date", Customer.FirstName, Customer.LastName, Invoice.BillingAddress, Invoice.BillingCity, Invoice.BillingState, Invoice.BillingCountry, Invoice.BillingPostalCode, Track.Name as "Track Name", Album.Title as "Album", MediaType.Name as "Media", Genre.Name as "Genre", Artist.Name as "Artist", Track.Composer, InvoiceLine.UnitPrice, InvoiceLine.Quantity, Invoice.Total FROM Invoice INNER JOIN InvoiceLine ON Invoice.InvoiceId = InvoiceLine.InvoiceId INNER JOIN Customer ON Invoice.CustomerId = Customer.CustomerId INNER JOIN Track ON InvoiceLine.TrackId = Track.TrackId INNER JOIN Album ON Track.AlbumId = Album.AlbumId INNER JOIN Artist ON Album.ArtistId = Artist.ArtistId INNER JOIN Genre ON Track.GenreId = Genre.GenreId INNER JOIN MediaType ON Track.MediaTypeId = MediaType.MediaTypeId WHERE Invoice.InvoiceId = %1% Report=SELECT * FROM Playlist Report=SELECT * FROM PlaylistTrack Report=SELECT date('now') as "today", date('now','start of month','+1 month','-1 day') as "last day current month", datetime(1092941466, 'unixepoch') as "unix timestamp", datetime(1092941466, 'unixepoch', 'localtime') as "unix timestamp, compensate for, local timezone", strftime('%s','now') as "current unix timestamp", julianday('now') - julianday('1776-07-04') as "days since US Independence", strftime('%s','now') - strftime('%s','2004-01-01 02:34:56') as "Time elapsed", date('now','start of year','+9 months','weekday 2') as "first Tuesday in October", (julianday('now') - 2440587.5)*86400.0 Report=select * from sqlite_master Report=SELECT name FROM sqlite_master WHERE type='table' Report=SELECT sqlite_version() as "sqlite version" --, sqlite_source_id() as "sqlite source_id" Report=VACUUM [Parameters] Report= Report= Report= Report= Report= Report= Report=Name contains|string will match any position in FirstName or LastName Report= Report= Report=Total between|For fraction use a dot (eg: 5.95),and|For fraction use a dot (eg: 5.95) Report= Report= Report=Invoice ID| Report= Report= Report= Report= Report= Report= Report=
    1 point
  3. Jon

    AutoIt v3.3.13.19 Beta

    File Name: AutoIt v3.3.13.19 Beta File Submitter: Jon File Submitted: 24 Aug 2014 File Category: Beta 3.3.13.19 (24th August, 2014) (Beta) AutoIt: - Fixed: Map setting of property using dot notation was creating duplicates. - Fixed #2862: Regression in Copy-on-write optimization in arrays. UDFs: - Fixed #2853: Bad Run link in Notepad tutorial doc. - Fixed #2854: Keyword reference doc page. - Fixed #2861: _WinAPI_ReadDirectoryChanges() example. Other: - Fixed #2848: Script breaking changes not being highlighted. - Fixed: Remarks missing in certain documentation pages. - Fixed: Syntax highlighting missing in certain documentation pages. Beta docs: https://www.autoitscript.com/autoit3/files/beta/autoit/docs/ Script breaking changes: https://www.autoitscript.com/autoit3/files/beta/autoit/docs/script_breaking_changes.htm
    1 point
  4. Atom Table UDF Local and Global Atom Table Since I've had this collecting dust on my computer, I figured I'd release it to see if anyone can find some use for it. About Atom Tables - MSDN Example Global Atom Table Listing Basically, a bunch of strings can be stored locally (at program level) or globally (at O/S level) with unique numerical identifiers. This UDF lets you add, find, delete, and query these atoms. Description from the top of the AtomFunctions UDF: ---------------------------------------------------------------- Functions for accesing Local and Global Atom Tables, which contain strings up to 255 characters long The Atom tables are used for multiple types of Windows data including Window Classes (RegisterClass/Ex), Clipboard formats (RegisterClipboardFormat), Hotkeys (RegisterHotKey), and Dynamic Data Exchange (DDE) which is a form of interprocess communication. (Some of the above may use a Local rather than the Global Atom table) Other uses can include storing program strings to lookup by a 16-bit value and interprocess communication "RegisterHotKey function" @ MSDN states this: "An application must specify an id value in the range 0x0000 through 0xBFFF. A shared DLL must specify a value in the range 0xC000 through 0xFFFF (the range returned by the GlobalAddAtom function). To avoid conflicts with hot-key identifiers defined by other shared DLLs, a DLL should use the GlobalAddAtom function to obtain the hot-key identifier." Kernel Note: The Atom Table is a separate entity from Kernel Objects like Events, Mutexes, Files, etc. However, the Atom Table is (separately) accessible from within the Kernel, so its like a Kernish object? Notes on Atom Tables: Stringlimit is 255 characters NOT including a null-terminator. This is unfortunately not enough for a MAX_PATH string, which is 259+null-term. However, stripping off root-drive prefix get you within 1 character of the length (259 - 3 ["C:"] = 256] which may be enough - but using IPC, one can store 4 - 6 (8-12 in x64) extra chars in wParam/lParam.. See <AtomExample_IPC.au3> for an implementation of this There is both a Local and Global Atom Table. The Local one is local to this Process, and the Global one is available/accessible to/from all Processes. Atoms numbered 0 - 49151 (0xBFFF) are not actually part of the Atom Table. Querying these values will return a string representation of the number as an unsigned integer Example: 1234 is translated to "#1234" Adding atom strings that start with a "#" will return an unsigned integer if the numbers following "#" are an integer less than 49152 (1 - 49151 [0xBFFF]). Examples: "#1" => 1, "#49151" => 49151 Atoms numbered from 49152 - 65535 (from 0xC000 - 0xFFFF) DO reference the Atom Table strings Maximum Atom string length is 255 characters (not including a null-terminator) Functions: ; Local: ; _AtomTableInit() ; Initializes Local Atom Table. Optional [37 hash buckets allocated by default] ; _AtomAddLocal() ; Adds a string to the Local Atom table, returns # identifier [increments reference if already exists] ; _AtomGetNameLocal() ; Gets the Local Atom string associated with a numerical identifier ; _AtomDeleteLocal() ; Decrements the reference count of Local Atom, deletes when reaches 0 ; _AtomFindLocal() ; Finds # identifier for a string in the Local Atom table ; _AtomGetAllLocal() ; Returns all found Local atoms in an array ; Global: ; _AtomAddGlobal() ; Adds a string to the Global Atom table, returns # identifier [increments reference if already exists] ; _AtomGetNameGlobal() ; Gets the Global Atom string associated with a numerical identifier ; _AtomDeleteGlobal() ; Decrements the reference count of Global Atom, deletes when reaches 0 ; _AtomFindGlobal() ; Finds # identifier for a string in the Global Atom table ; _AtomGetAllGlobal() ; Returns all found Global atoms in an array ; 'Undocumented': ; _AtomGetGlobalTableUD() ; Using 'undocumented' function calls, gets info on all Global Atoms ; _AtomGetInfoUD() ; Returns reference count, pinned status, as well as Atom Name ---------------------------------------------------------------- There are a few 'undocumented' functions used for getting information on the Atom Table included (I can't help myself). In addition to the core UDF, there's 2 example files: AtomTableExample.au3 - This demonstrates various use - adding, deleting, and querying information in the Local and Global atom tables. (Extended info comes from 'undocumented' functions) AtomExample_IPC.au3 - This demonstrates how the Atom Table could be used in InterProcess Communication. A rather rough sketch, but shows how you could squeeze MAX_PATH pathnames into IPC messages combined with Atom tables. It's all a bit light on the documentation, but I just wanted to prevent this thing from collecting more dust Might prove useful to someone! History:: AtomTablesUDF.zip ~prev Downloads: 29
    1 point
  5. sahsanu Thanks BTW this one can be done without using backreference(s) K can be nicely used as a kind of "lookbehind including undefinite quantifiers" $txt = StringRegExpReplace($txt, '(?s).*project.*?version="\K([^"]+)', "0.0.0")
    1 point
  6. Hylia, This may give you some ideas... #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> local $gui = guicreate('Roll The Dice',200,200) local $display = guictrlcreateedit('',10,10,100,160, BitOR($WS_VSCROLL, $ES_READONLY)) ; create a group to hold the frequency count controls local $g1 = guictrlcreategroup('Frequency',115,05,80,160) ; create an array to hold the frequency count control id's local $aRolls[6] ; create static controls for frequency counts for $1 = 1 to 6 guictrlcreatelabel('#' & $1 & ' - ',130,$1*15+15,20,15) $aRolls[$1-1] = guictrlcreatelabel('',145,$1*15+15,20,15,bitor($SS_SUNKEN,$SS_CENTER)) next local $roller = GUICtrlCreateButton("Roll the Dice!" & @CRLF, 10,180,180,20) ; do roll routine if the enter key is pressed local $Enter = GUICtrlCreateDummy() GUISetState(@SW_SHOW) ; allows Enter key to actuate a control ($Enter) Dim $aAccelKeys[1][2] = [["{ENTER}", $Enter]] GUISetAccelerators($aAccelKeys) While 1 switch guigetmsg() Case $GUI_EVENT_CLOSE Exit ; do roll routine if either Roll button is clicked or the Enter key is pressed case $roller, $Enter _Roll() EndSwitch WEnd func _Roll() static $roll_number = 1 ; will persist between calls local $tRoll = random(1,6,1) ; will change between calls ; display the current roll guictrlsetdata($display,'Roll # ' & stringformat('%03i',$roll_number) & ' = ' & $tRoll & @CRLF,1) $roll_number += 1 ; update the frequency count by adding 1 to the matching control guictrlsetdata($aRolls[$tRoll-1], guictrlread($aRolls[$tRoll-1]) + 1) endfunc kylomas edit: added ENTER key as accelerator
    1 point
  7. @Milkyourcow2, can you please explain in detail what you are trying to automate? 99% of the time there is a much easier way to accomplish what you're after without having to resort to MouseMoves and MouseClicks.
    1 point
  8. How about if you post what you did, in case someone runs into a similar issue in the future?
    1 point
  9. And maybe that with 520+ posts you could have taken the time and pain to learn how to store data in an array and iterate processing on its elements. Local $aDevices = [ _ ["192.168.1.200", "Prn1"], _ ["192.168.1.201", "Prn2"], _ ["192.168.1.202", "Prn3"], _ ["192.168.1.203", "Prn4"], _ ["192.168.1.207", "Waitstation by Kitchen"], _ ["192.168.1.116", "Bar Terminal"], _ ["192.168.1.15", "Terminal By Back Door"] _ ] While 1 For $i = 0 To UBound($aDevices) - 1 If Ping($aDevices[$i][0], 250) Then Sleep(5000) Else MsgBox(0, "", $aDevices[$i][1] & " Stopped Communicating") EndIf Next WEnd
    1 point
  10. Simucal

    Sliding Toolbar

    EDIT: Added AutoItKing's Double Layer toolbar example EDIT: Val added transparency setting to his toolbar. EDIT: Next toolbar will be an attempt to mimic the OSX/Object dock toolbar. Stay tuned for a beta release! EDIT: Now will snap to the nearest side of the desktop you drag it to! EDIT: Added Valuaters Example script to the post. EDIT: Replaced my button-hover handling code with Valuaters more effecient version. EDIT: Now, whatever button your mouse hovers over becomes larger and the text above it turns red. Toolbar2: This is a sliding toolbar GUI created by myself and Valuater. It uses the WindowsAnimation DLL call along with two GUI windows to get the desired effect. This version of it is meant to be a base GUI for your script. Base GUI Screenshot: toolbar2.au3+ 79DL's Valuater's example toolbar: This script is pretty sweet. It allows you to configure what applications it runs along with their corresponding icons while the script is running! You can simply drag and drop the exe you want added to the toolbar while in the config menu (all changes you make to the toolbar are saved to an ini). I tried to take some better video/screenshots of it in action but my applications didnt like the transparency settings the config window used. Example Usage Screenshots: toolbar2_val.au3+ 130 DL's AutoItKing's example toolbar: King took Valuaters toolbar that had the config menu and made it two layered. So, if you have more applications than 7 you should give his version a try! Double Layer Toolbar Screenshot: toolbar_king.au3 Give it a try! -Simucal EDIT: Forgot to thank Valuater for his help in getting the desired effect!
    1 point
  11. This is an example of a universal date converter from your PC local date format to any format you could need to use. I couldn't find any good solution on the forum, so I re-engineered an example of DaRam. This should work with any regional setting date format. The script reads the Local date format in your registry setting. RegRead("HKCU\Control Panel\International", "sShortDate") I hope you can use it. GreenCan #cs Description: Universal date format converter Converts the (default regional setting) PC Date format into any other specified date format: - convert date into another date format (for example ddd dd MMMM, yyyy) - convert date into day (d or dd) - convert date into month ( m, mm or mmm) - convert date into year (yy or yyyy) Parameter(s): $InputDate Input date $DateFmt - Format of input date (optional), if omitted, will return date in mm/dd/yyyy Requirement(s): <DateCalc.au3> The udf is included in this script Return Value(s):On Success - Date in in requested format On Error - @ERROR 1 (input date badly formatted) - Error Message Author(s): GreenCan Note(s): Part of source code was borrowed from the Date conversion example provided by DaRam http://www.autoitscript.com/forum/index.php?showtopic=76984&view=findpost&p=557834 DateCalc.au3 (_DateCalc udf) by Sean Hart http://www.autoitscript.com/forum/index.php?showtopic=14084&view=findpost&p=96173 Syntax: DateFormat( $Date , $DateFormat ) Example: DateFormat( _NowCalcDate() , "dd-MM-yyyy" ) #ce #include <Date.au3> #include <DateTimeConstants.au3> #include <GUIConstants.au3> ;#include <DateCalc.au3> Global $sDateFormat = RegRead("HKCU\Control Panel\International", "sShortDate") ; This is the date format of your PC ; example 1: Using GUICtrlCreateDate in a GUI $Form1 = GUICreate("PC DateFormat: " & $sDateFormat, 290, 112, 193, 115) $Label1 = GUICtrlCreateLabel("Date:", 8, 8, 90, 17) $Input1 = GUICtrlCreateDate(_Date_Time_GetLocalTime(), 100, 8, 180, 21,$DTS_SHORTDATEFORMAT ) ; $DTS_SHORTDATEFORMAT $DTS_LONGDATEFORMAT $Label2 = GUICtrlCreateLabel("Date Time Format:", 8, 36, 90, 17) $Input2 = GUICtrlCreateInput("ddd dd MMMM, yyyy", 100, 33, 180, 21) $Button1 = GUICtrlCreateButton("&Convert", 8, 64, 89, 25, 0) $Input3 = GUICtrlCreateInput("", 100, 64, 180, 24) GUISetState(@SW_SHOW) GUICtrlSetData( $Input3, DateFormat( GUICtrlRead($Input1), GUICtrlRead($Input2) ) ) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button1 GUICtrlSetData( $Input3, DateFormat( GUICtrlRead($Input1), GUICtrlRead($Input2) ) ) EndSwitch Wend ; Example 2: Direct conversion (make sure that the input date is in the PC sShortDate format, see your local settings) $Date = "05/12/2009" ConsoleWrite ( DateFormat( $Date , "dd-MM-yyyy" ) & @CR) ConsoleWrite ( DateFormat( $Date , "MMM" ) & @CR) ConsoleWrite ( DateFormat( $Date , "d" ) & @CR) ConsoleWrite ( DateFormat( $Date , "yy" ) & @CR) ; Example 3: Error simulation $NewDate = DateFormat( "35/12/2009" , "dd-MM-yyyy" ) If @error Then ConsoleWrite ( $NewDate & @CR) Else ConsoleWrite ( $NewDate & @CR) EndIf #FUNCTION# ============================================================== Func DateFormat($InputDate, $DateFmt = "mm/dd/yyyy") If StringLen($InputDate) < 6 Then SetError (1) Return "Invalid Date" ; ddmmyy = 6 EndIf If $DateFmt = "" Then $DateFmt = "dd/mm/yyyy" Local $DateValue = _DateCalc ($InputDate,$sDateFormat) ; convert the date to yyyy/mm/dd $DateValue = StringSplit($DateValue, "/") If @error Then SetError (1) Return "Invalid Date " & $InputDate EndIf If $DateValue[0] < 3 Then ; less than 3 parts in date not possible SetError (1) Return "Invalid Date " & $InputDate EndIf If Int(Number($DateValue[1])) < 0 Then SetError (1) Return "Invalid Year in Date" EndIf If Int(Number($DateValue[2])) < 1 Or Int(Number($DateValue[2])) > 12 Then SetError (1) Return "Invalid Month in Date" EndIf If Int(Number($DateValue[3])) < 1 Or Int(Number($DateValue[3])) > 31 Then SetError (1) Return "Invalid Day in Date" EndIf If Int(Number($DateValue[1])) < 100 Then $DateValue[1] = StringLeft(@YEAR,2) & $DateValue[1] $InputDate = $DateFmt $InputDate = StringReplace($InputDate, "d", "@") ; Convert All Day References to @ $InputDate = StringReplace($InputDate, "m", "#") ; Convert All Month References to # $InputDate = StringReplace($InputDate, "y", "&") ; Convert All Year References to & $InputDate = StringReplace($InputDate, "&&&&", $DateValue[1]) ; Century and Year $InputDate = StringReplace($InputDate, "&&", StringRight($DateValue[1],2)) ; Year Only $InputDate = StringReplace($InputDate, "&", "") ; Discard leftover Year Indicator $InputDate = StringReplace($InputDate, "####", _DateMonthOfYear($DateValue[2], 0)) ; Long Month Name $InputDate = StringReplace($InputDate, "###", _DateMonthOfYear($DateValue[2], 1)) ; Short Month Name If StringLen($DateValue[1]) < 2 Then $InputDate = StringReplace($InputDate, "##", "0" & $DateValue[2]) ; Month Number 2 Digit Else $InputDate = StringReplace($InputDate, "##", $DateValue[2]) ; Month Number 2 Digit EndIf $InputDate = StringReplace($InputDate, "#", int($DateValue[2])) ; Month Number $iPos = _DateToDayOfWeek($DateValue[1], $DateValue[2], $DateValue[3]) ; Day of Week Number $InputDate = StringReplace($InputDate, "@@@@", _DateDayOfWeek($iPos, 0)) ; Long Weekday Name $InputDate = StringReplace($InputDate, "@@@", _DateDayOfWeek($iPos, 1)) ; Short Weekday Name $InputDate = StringReplace($InputDate, "@@", $DateValue[3]) ; Day Number 2 Digit $InputDate = StringReplace($InputDate, "@", int($DateValue[3])) ; Day Number Return $InputDate EndFunc ;==>DateFormat #FUNCTION# ============================================================== ;=============================================================================== ; ; Description: Returns the Date [and time] in format YYYY/MM/DD [HH:MM:SS], ; give the date / time in the system or specified format. ; Parameter(s): $sSysDateTime - Input date [and time] ; $dFormat - Format of input date (optional) ; $tFormat - Format of input time (optional) ; Requirement(s): None ; Return Value(s): On Success - Date in in format YYYY/MM/DD [HH:MM:SS] ; On Error - @ERROR - 1 (input date badly formatted) ; - @ERROR - 2 (input time badly formatted) ; Author(s): Sean Hart <autoit@hartmail.ca> ; Note(s): Date format can be provided without any separators only in ; the format YYYYMMDD. ; If system format is used it is current user format, NOT ; default user format (which may be different). ; 2 digit years converted: 81 - 99 -> 1981-1999 ; 00 - 80 -> 2000-2080 ; ;=============================================================================== #include-once Func _DateCalc($sSysDateTime, $dFormat = "", $tFormat = "") Local $sDay Local $sMonth Local $sYear Local $sHour Local $sMin Local $sSec ;Local $dFormat Local $dSep ;Local $tFormat Local $tSep Local $am Local $pm Local $split1[9] Local $split2[9] Local $sSysDate Local $sSysTime Local $isAM Local $isPM Local $sTestDate ; Read default system time formats and separators from registry unless provided if $dFormat = "" then $dFormat = RegRead ("HKEY_CURRENT_USER\Control Panel\International", "sShortDate") $dSep = RegRead ("HKEY_CURRENT_USER\Control Panel\International", "sDate") else ; Extract separator from date format by finding first non recognised character for $x = 1 to StringLen ($dFormat) if (not (StringMid ($dFormat, $x, 1) = "y")) AND (not (StringMid ($dFormat, $x, 1) = "m")) AND (not (StringMid ($dFormat, $x, 1) = "d")) then $dSep = StringMid ($dFormat, $x, 1) ExitLoop endif next endif if $tFormat = "" then $tFormat = RegRead ("HKEY_CURRENT_USER\Control Panel\International", "sShortDate") $tSep = RegRead ("HKEY_CURRENT_USER\Control Panel\International", "sDate") $am = RegRead ("HKEY_CURRENT_USER\Control Panel\International", "s1159") $pm = RegRead ("HKEY_CURRENT_USER\Control Panel\International", "s2359") else ; Extract separator from time format by finding first non hour character for $x = 1 to StringLen ($tFormat) if (not (StringMid ($tFormat, $x, 1) = "h")) then $tSep = StringMid ($tFormat, $x, 1) ExitLoop endif next $am = "AM" $pm = "PM" endif ; Separate date and time if included (make break at first space) if StringInStr ($sSysDateTime, " ") then $sSysDate = StringLeft ($sSysDateTime, StringInStr ($sSysDateTime, " ") - 1) $sSysTime = StringStripWS (StringReplace ($sSysDateTime, $sSysDate, ""), 1) else $sSysDate = $sSysDateTime $sSysTime = "" endif ; Simple check of input date format (look for separators and unexpected non numeric characters) $sTestDate = StringReplace ($sSysDate, $dSep, "") $sTestDate = "1" & $sTestDate if (String (Number ($sTestDate)) <> $sTestDate) then SetError (1) Return endif if (StringInStr ($sSysDate, $dSep) = 0) AND ($dSep <> "") then SetError (1) Return endif if $sSysTime <> "" then $sTestDate = StringReplace ($sSysTime, $tSep, "") $sTestDate = StringReplace ($sTestDate, $am, "") $sTestDate = StringReplace ($sTestDate, $pm, "") $sTestDate = StringReplace ($sTestDate, " ", "") $sTestDate = "1" & $sTestDate if (StringInStr ($sSysTime, $tSep) = 0) or (String (Number ($sTestDate)) <> $sTestDate) then SetError (2) Return endif endif ; Break up date components (using format as a template), unless format is YYYYMMDD if $dFormat = "YYYYMMDD" then $sYear = StringMid ($sSysDate, 1, 4) $sMonth = StringMid ($sSysDate, 5, 2) $sDay = StringMid ($sSysDate, 7, 2) else $split1 = StringSplit ($dFormat, $dSep) $split2 = StringSplit ($sSysDate, $dSep) for $x = 1 to $split1[0] if StringInStr ($split1[$x], "M") then $sMonth = $split2[$x] if StringInStr ($split1[$x], "d") then $sDay = $split2[$x] if StringInStr ($split1[$x], "y") then $sYear = $split2[$x] next endif ; Pad values with 0 if required and fix 2 digit year if StringLen ($sMonth) = 1 then $sMonth = "0" & $sMonth if StringLen ($sDay) = 1 then $sDay = "0" & $sDay if StringLen ($sYear) = 2 then if $sYear > 80 then $sYear = "19" & $sYear else $sYear = "20" & $sYear endif endif ; Break up time components (if given) if $sSysTime <> "" then ; Look for AM/PM and note it, then remove from the string $isPM = 0 if StringInStr ($sSysTime, $am) then $sSysTime = StringReplace ($sSysTime, " " & $am, "") $isPM = 1 elseif StringInStr ($sSysTime, $pm) then $sSysTime = StringReplace ($sSysTime, " " & $pm, "") $isPM = 2 endif $split1 = StringSplit ($tFormat, $tSep) $split2 = StringSplit ($sSysTime, $tSep) $sSec = "00" for $x = 1 to $split2[0] if StringInStr ($split1[$x], "h") then $sHour = $split2[$x] if StringInStr ($split1[$x], "m") then $sMin = $split2[$x] if StringInStr ($split1[$x], "s") then $sSec = $split2[$x] next ; Clean up time values (change hour to 24h and 0 pad values) if ($isPM = 1) and ($sHour = 12) then $sHour = "00" if ($isPM = 2) and ($sHour < 12) then $sHour = $sHour + 12 if StringLen ($sHour) = 1 then $sHour = "0" & $sHour if StringLen ($sMin) = 1 then $sMin = "0" & $sMin if StringLen ($sSec) = 1 then $sSec = "0" & $sSec ; Return date with time Return $sYear & "/" & $sMonth & "/" & $sDay & " " & $sHour & ":" & $sMin & ":" & $sSec else ; Return date only Return $sYear & "/" & $sMonth & "/" & $sDay endif EndFunc ;==>_DateCalc #FUNCTION# ==============================================================
    1 point
  12. Markus

    Tetris

    Hi! I hope you'll have much fun with this. I know that there are already existing a lot of tetris versions, but i thought, it would be nice to have one with AutoIt. AutoIt owns!!! Markus EDIT: Codebox for AutoItKing^^ EDIT: 20/06/2006 (Tetris1.1) - removed several bugs by changing the hotkeyfunctions (hotkeys now only change vars, that tells the script to move the item at a position in the script, where no bugs can be caused by moving it) - added zedna's changes EDIT: 21/06/2006 (Tetris1.11) - Tetris now pauses automatically if Window is minimized/not activated, it will go on at once if its activated again - If you press down arrow button for a very short time, the item will fall down "as a brick" --> its moved straight to the ground, if you press the button longer, the item will fall only faster as long as you press it and then will fall as slow as before. The Script: #compiler_icon=tetris.ico #include <GUIConstants.au3> #include <misc.au3> _hotkey_enable() HotKeySet("{PAUSE}","_pause") Global $reserve_id[8][101] Global $reserve_anzahl[8] Global $vorschau_id[8][5] Global $vorschau_background_id[5][5] Global $current_id[5] Global $current_x_pos[5] Global $current_y_pos[5] Global $temp_x_pos[5] Global $temp_y_pos[5] Global $current_colour Global $current_lage=1 Global $lieing_id[21][11] Global $lieing_colour[21][11] Global $feld_status[21][11] For $i=1 To 20 For $s=1 To 10 $feld_status[$i][$s]=0 Next Next Global $teiler=500 Global $line_info_voll[21] $line_info_voll[0]=0 ;[0] enthält die Angabe, wie viele voll sind Global $random Global $points=0 Global $item=1 Global $level=1 Global $pause=0 Global $move_right=0 Global $move_left=0 Global $move_rotate=0 ;Global $move_let_fall=0 Global $pressed=0 Global $pressedtimer=0 Global $started_by_minimize=0 SplashTextOn("Tetris",@crlf & "Loading GUI..." & @crlf & @crlf & "...please be patient!",200,100) $main_gui=GUICreate("Tetris (by M.Braun)",425,540) GUISetBkColor(0x000000) GUICtrlCreatePic(@ScriptDir & "\Pics\line.bmp",18,18,2,504) GUICtrlCreatePic(@ScriptDir & "\Pics\line.bmp",270,18,2,504) GUICtrlCreatePic(@ScriptDir & "\Pics\horiz.bmp",20,18,250,2) GUICtrlCreatePic(@ScriptDir & "\Pics\horiz.bmp",20,520,250,2) GUICtrlCreatePic(@ScriptDir & "\Pics\line.bmp",288,18,2,124) GUICtrlCreatePic(@ScriptDir & "\Pics\line.bmp",410,18,2,124) GUICtrlCreatePic(@ScriptDir & "\Pics\horiz.bmp",290,18,120,2) GUICtrlCreatePic(@ScriptDir & "\Pics\horiz.bmp",290,140,120,2) GUICtrlCreatePic(@ScriptDir & "\Pics\line.bmp",288,163,2,109) ; 288,163,2,99 GUICtrlCreatePic(@ScriptDir & "\Pics\line.bmp",410,163,2,109) ; 410,163,2,99 GUICtrlCreatePic(@ScriptDir & "\Pics\horiz.bmp",290,163,120,2) GUICtrlCreatePic(@ScriptDir & "\Pics\horiz.bmp",290,270,120,2) ; 290,260,120,2 GUICtrlCreatePic(@ScriptDir & "\Pics\line.bmp",288,293,2,49) GUICtrlCreatePic(@ScriptDir & "\Pics\line.bmp",410,293,2,49) GUICtrlCreatePic(@ScriptDir & "\Pics\horiz.bmp",290,293,120,2) GUICtrlCreatePic(@ScriptDir & "\Pics\horiz.bmp",290,340,120,2) $label_points=GUICtrlCreateLabel("Your Points:" & @CRLF & $points,300,175,100,90) ; 300,175,100,75 GUICtrlSetFont(-1,18) GUICtrlSetColor(-1,0x00FF00) $label_level=GUICtrlCreateLabel("Level: " & $level ,300,305,100,25) GUICtrlSetFont(-1,18) GUICtrlSetColor(-1,0x00FF00) $label_pause=GUICtrlCreateLabel("PAUSED",300,450,100,25) GUICtrlSetFont(-1,18) GUICtrlSetColor(-1,0x00FF00) GUICtrlSetState(-1,$GUI_HIDE) $reserve_anzahl[1]=100 $reserve_anzahl[2]=100 $reserve_anzahl[3]=100 $reserve_anzahl[4]=100 $reserve_anzahl[5]=100 $reserve_anzahl[6]=100 $reserve_anzahl[7]=100 For $i=1 To 100 $reserve_id[1][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_red.bmp",-99,-99,25,25) $reserve_id[2][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_green.bmp",-99,-99,25,25) $reserve_id[3][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_yellow.bmp",-99,-99,25,25) $reserve_id[4][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_blue.bmp",-99,-99,25,25) $reserve_id[5][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_orange.bmp",-99,-99,25,25) $reserve_id[6][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_pink.bmp",-99,-99,25,25) $reserve_id[7][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_teal.bmp",-99,-99,25,25) Next For $i=1 To 4 $vorschau_id[1][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_red.bmp",-99,-99,25,25) $vorschau_id[2][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_green.bmp",-99,-99,25,25) $vorschau_id[3][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_yellow.bmp",-99,-99,25,25) $vorschau_id[4][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_blue.bmp",-99,-99,25,25) $vorschau_id[5][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_orange.bmp",-99,-99,25,25) $vorschau_id[6][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_pink.bmp",-99,-99,25,25) $vorschau_id[7][$i]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_teal.bmp",-99,-99,25,25) Next For $i=1 To 4 For $s=1 To 4 $vorschau_background_id[$i][$s]=GUICtrlCreatePic(@ScriptDir & "\Pics\circle_grey.bmp",($i-1)*25+300,($s-1)*25+30,25,25) Next Next $random=Random(1,7,1) _new_item() SplashOff() GUISetState() $timer=TimerInit() While 1 _msg() If $move_right=1 Then _move_right() $move_right=0 EndIf If $move_left=1 Then _move_left() $move_left=0 EndIf If $move_rotate=1 Then _rotate() $move_rotate=0 EndIf #cs If $move_let_fall=1 Then _let_it_fall_to_ground() $move_let_fall=0 EndIf #ce If $pressed=1 Then If _IsPressed(28)=0 Then $pressed=0 ;MsgBox(0,TimerDiff($pressedtimer),"") If TimerDiff($pressedtimer)<150 Then _let_it_fall_to_ground() EndIf EndIf $timer_dif=TimerDiff($timer) If _IsPressed(28) Then If $pressed=0 Then $pressedtimer=TimerInit() $pressed=1 EndIf If $timer_dif/30>1 Then _let_it_fall() $timer=TimerInit() EndIf ElseIf $timer_dif/$teiler>1 Then _let_it_fall() $timer=TimerInit() EndIf WEnd Func _pause() If $pause=0 Then _hotkey_disable() GUICtrlSetState($label_pause,$GUI_SHOW) $pause=1 While 1 If $started_by_minimize=1 Then If WinActive($main_gui)=1 Then _pause() EndIf If $pause=0 Then ExitLoop _msg() WEnd Else _hotkey_enable() GUICtrlSetState($label_pause,$GUI_HIDE) $started_by_minimize=0 $pause=0 EndIf EndFunc Func _msg() $msg=GUIGetMsg() If $msg=$GUI_EVENT_CLOSE Then Exit EndFunc Func _hotkey_enable() HotKeySet("{RIGHT}","_move_right_var") HotKeySet("{LEFT}","_move_left_var") HotKeySet("{UP}","_rotate_var") ;HotKeySet("{DOWN}","_let_it_fall_to_ground_var") EndFunc Func _hotkey_disable() HotKeySet("{RIGHT}") HotKeySet("{LEFT}") HotKeySet("{UP}") ;HotKeySet("{DOWN}") EndFunc Func _move_right_var() $move_right=1 EndFunc Func _move_left_var() $move_left=1 EndFunc Func _rotate_var() $move_rotate=1 EndFunc #cs Func _let_it_fall_to_ground_var() $move_let_fall=1 EndFunc #ce Func _move_right() If _check_free_space_to_right_side()=0 Then Return 0 For $i=1 To 4 $current_x_pos[$i]=$current_x_pos[$i]+1 Next _move_current_item() EndFunc Func _check_free_space_to_right_side() For $i=1 To 4 If $current_x_pos[$i]=10 Then Return 0 ElseIf $feld_status[$current_y_pos[$i]][$current_x_pos[$i]+1]=1 Then Return 0 EndIf Next Return 1 EndFunc Func _move_left() If _check_free_space_to_left_side()=0 Then Return 0 For $i=1 To 4 $current_x_pos[$i]=$current_x_pos[$i]-1 Next _move_current_item() EndFunc Func _check_free_space_to_left_side() For $i=1 To 4 If $current_x_pos[$i]=1 Then Return 0 ElseIf $feld_status[$current_y_pos[$i]][$current_x_pos[$i]-1]=1 Then Return 0 EndIf Next Return 1 EndFunc Func _rotate() $rotate_point_x_cord=$current_x_pos[2] $rotate_point_y_cord=$current_y_pos[2] For $i=1 To 4 $temp_x_pos[$i]=$rotate_point_x_cord-($current_y_pos[$i]-$rotate_point_y_cord) $temp_y_pos[$i]=$rotate_point_y_cord+($current_x_pos[$i]-$rotate_point_x_cord) If $temp_x_pos[$i]<1 Or $temp_x_pos[$i]>10 Or $temp_y_pos[$i]<1 Or $temp_y_pos[$i]>20 Then Return 0 If $feld_status[$temp_y_pos[$i]][$temp_x_pos[$i]]=1 Then Return 0 Next For $i= 1 To 4 $current_x_pos[$i]=$temp_x_pos[$i] $current_y_pos[$i]=$temp_y_pos[$i] Next _move_current_item() EndFunc Func _let_it_fall() _check_free_space() For $i=1 To 4 $current_y_pos[$i]=$current_y_pos[$i]+1 Next _move_current_item() If WinActive($main_gui)=0 Then $started_by_minimize=1 _pause() EndIf EndFunc Func _let_it_fall_to_ground() While 1 If _check_free_space()=1 Then ExitLoop For $i=1 To 4 $current_y_pos[$i]=$current_y_pos[$i]+1 Next WEnd EndFunc Func _move_current_item() For $i=1 To 4 $x_pos=($current_x_pos[$i]-1)*25+20 $y_pos=($current_y_pos[$i]-1)*25+20 GUICtrlSetPos($current_id[$i],$x_pos,$y_pos) Next EndFunc #cs Func _check_free_space_without_stop() For $i=1 To 4 If $current_y_pos[$i]=20 Then _move_current_item() $timer=TimerInit() Return 1 ElseIf $feld_status[$current_y_pos[$i]+1][$current_x_pos[$i]]=1 Then _move_current_item() $timer=TimerInit() Return 1 EndIf Next EndFunc #ce Func _check_free_space() For $i=1 To 4 If $current_y_pos[$i]=20 Then _stop_fall() Return 1 ElseIf $feld_status[$current_y_pos[$i]+1][$current_x_pos[$i]]=1 Then _stop_fall() Return 1 EndIf Next EndFunc Func _stop_fall() _hotkey_disable() _move_current_item() For $i=1 To 4 If $current_y_pos[$i]<3 Then _game_over() Return 0 EndIf Next $item=$item+1 If $level<15 Then If $item/10=$level Then $level=$level+1 GUICtrlSetData($label_level,"Level: " & $level) If $level=2 Then $teiler=500 If $level=3 Then $teiler=450 If $level=4 Then $teiler=400 If $level=5 Then $teiler=350 If $level=6 Then $teiler=330 If $level=7 Then $teiler=300 If $level=8 Then $teiler=270 If $level=9 Then $teiler=240 If $level=10 Then $teiler=210 If $level=10 Then $teiler=190 If $level=11 Then $teiler=170 If $level=12 Then $teiler=150 If $level=13 Then $teiler=130 If $level=14 Then $teiler=120 If $level=15 Then $teiler=110 EndIf EndIf For $i=1 To 4 $feld_status[$current_y_pos[$i]][$current_x_pos[$i]]=1 $lieing_id[$current_y_pos[$i]][$current_x_pos[$i]]=$current_id[$i] $lieing_colour[$current_y_pos[$i]][$current_x_pos[$i]]=$current_colour Next _line_check() _new_item() _hotkey_enable() EndFunc Func _line_check() $line_info_voll[0]=0 For $i=1 To 20 $line_voll=1 For $s=1 To 10 If $feld_status[$i][$s]=0 Then $line_voll=0 ExitLoop EndIf Next If $line_voll=1 Then $line_info_voll[0]=$line_info_voll[0]+1 $line_info_voll[$line_info_voll[0]]=$i EndIf Next If $line_info_voll[0]>0 Then If $line_info_voll[0]=1 Then $points=$points+25 If $line_info_voll[0]=2 Then $points=$points+50 If $line_info_voll[0]=3 Then $points=$points+100 If $line_info_voll[0]=4 Then $points=$points+200 GUICtrlSetData($label_points,"Your Points:" & @CRLF & $points) For $i=1 To $line_info_voll[0] For $s=1 To 10 GUICtrlSetPos($lieing_id[$line_info_voll[$i]][$s],-99,-99) $feld_status[$line_info_voll[$i]][$s]=0 $colour=$lieing_colour[$line_info_voll[$i]][$s] $reserve_anzahl[$colour]=$reserve_anzahl[$colour]+1 $reserve_id[$colour][$reserve_anzahl[$colour]]=$lieing_id[$line_info_voll[$i]][$s] Next _lines_nach_rutschen($line_info_voll[$i]) Next Endif EndFunc Func _lines_nach_rutschen($ab_line) For $i=$ab_line-1 To 1 Step -1 For $s=1 To 10 If $feld_status[$i][$s]=1 Then ;MsgBox(0,$i & $s,"") $feld_status[$i][$s]=0 $feld_status[$i+1][$s]=1 GUICtrlSetPos($lieing_id[$i][$s],($s-1)*25+20,($i)*25+20) $lieing_id[$i+1][$s]=$lieing_id[$i][$s] $lieing_colour[$i+1][$s]=$lieing_colour[$i][$s] EndIf Next Next EndFunc Func _new_item() If $random=1 Then $current_colour=1 $current_id[1]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]] $current_id[2]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-1] $current_id[3]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-2] $current_id[4]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-3] $current_x_pos[1]=5 $current_x_pos[2]=6 $current_x_pos[3]=5 $current_x_pos[4]=6 $current_y_pos[1]=2 $current_y_pos[2]=2 $current_y_pos[3]=1 $current_y_pos[4]=1 $reserve_anzahl[$current_colour]=$reserve_anzahl[$current_colour]-4 EndIf If $random=2 Then $current_colour=2 $current_id[1]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]] $current_id[2]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-1] $current_id[3]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-2] $current_id[4]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-3] $current_x_pos[1]=5 $current_x_pos[2]=5 $current_x_pos[3]=5 $current_x_pos[4]=5 $current_y_pos[1]=1 $current_y_pos[2]=2 $current_y_pos[3]=3 $current_y_pos[4]=4 $reserve_anzahl[$current_colour]=$reserve_anzahl[$current_colour]-4 EndIf If $random=3 Then $current_colour=3 $current_id[1]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]] $current_id[2]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-1] $current_id[3]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-2] $current_id[4]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-3] $current_x_pos[1]=5 $current_x_pos[2]=5 $current_x_pos[3]=5 $current_x_pos[4]=4 $current_y_pos[1]=1 $current_y_pos[2]=2 $current_y_pos[3]=3 $current_y_pos[4]=3 $reserve_anzahl[$current_colour]=$reserve_anzahl[$current_colour]-4 EndIf If $random=4 Then $current_colour=4 $current_id[1]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]] $current_id[2]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-1] $current_id[3]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-2] $current_id[4]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-3] $current_x_pos[1]=5 $current_x_pos[2]=5 $current_x_pos[3]=5 $current_x_pos[4]=4 $current_y_pos[1]=1 $current_y_pos[2]=2 $current_y_pos[3]=3 $current_y_pos[4]=1 $reserve_anzahl[$current_colour]=$reserve_anzahl[$current_colour]-4 EndIf If $random=5 Then $current_colour=5 $current_id[1]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]] $current_id[2]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-1] $current_id[3]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-2] $current_id[4]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-3] $current_x_pos[1]=5 $current_x_pos[2]=5 $current_x_pos[3]=5 $current_x_pos[4]=4 $current_y_pos[1]=1 $current_y_pos[2]=2 $current_y_pos[3]=3 $current_y_pos[4]=2 $reserve_anzahl[$current_colour]=$reserve_anzahl[$current_colour]-4 EndIf If $random=6 Then $current_colour=6 $current_id[1]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]] $current_id[2]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-1] $current_id[3]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-2] $current_id[4]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-3] $current_x_pos[1]=5 $current_x_pos[2]=5 $current_x_pos[3]=6 $current_x_pos[4]=6 $current_y_pos[1]=1 $current_y_pos[2]=2 $current_y_pos[3]=2 $current_y_pos[4]=3 $reserve_anzahl[$current_colour]=$reserve_anzahl[$current_colour]-4 EndIf If $random=7 Then $current_colour=7 $current_id[1]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]] $current_id[2]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-1] $current_id[3]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-2] $current_id[4]=$reserve_id[$current_colour][$reserve_anzahl[$current_colour]-3] $current_x_pos[1]=6 $current_x_pos[2]=6 $current_x_pos[3]=5 $current_x_pos[4]=5 $current_y_pos[1]=1 $current_y_pos[2]=2 $current_y_pos[3]=2 $current_y_pos[4]=3 $reserve_anzahl[$current_colour]=$reserve_anzahl[$current_colour]-4 EndIf $current_lage=1 _move_current_item() _vorschau() $timer=TimerInit() EndFunc Func _vorschau() For $i=1 To 4 GUICtrlSetPos($vorschau_id[$current_colour][$i],-99,-99) Next For $i=1 To 4 For $s=1 To 4 GUICtrlSetPos($vorschau_background_id[$i][$s],($i-1)*25+300,($s-1)*25+30,25,25) Next Next $random=Random(1,7,1) If $random=1 Then GUICtrlSetPos($vorschau_background_id[2][2],-99,-99) GUICtrlSetPos($vorschau_background_id[3][2],-99,-99) GUICtrlSetPos($vorschau_background_id[2][3],-99,-99) GUICtrlSetPos($vorschau_background_id[3][3],-99,-99) GUICtrlSetPos($vorschau_id[1][1],1*25+300,1*25+30) GUICtrlSetPos($vorschau_id[1][2],2*25+300,1*25+30) GUICtrlSetPos($vorschau_id[1][3],1*25+300,2*25+30) GUICtrlSetPos($vorschau_id[1][4],2*25+300,2*25+30) EndIf If $random=2 Then GUICtrlSetPos($vorschau_background_id[2][1],-99,-99) GUICtrlSetPos($vorschau_background_id[2][2],-99,-99) GUICtrlSetPos($vorschau_background_id[2][3],-99,-99) GUICtrlSetPos($vorschau_background_id[2][4],-99,-99) GUICtrlSetPos($vorschau_id[2][1],1*25+300,0*25+30) GUICtrlSetPos($vorschau_id[2][2],1*25+300,1*25+30) GUICtrlSetPos($vorschau_id[2][3],1*25+300,2*25+30) GUICtrlSetPos($vorschau_id[2][4],1*25+300,3*25+30) EndIf If $random=3 Then GUICtrlSetPos($vorschau_background_id[3][1],-99,-99) GUICtrlSetPos($vorschau_background_id[3][2],-99,-99) GUICtrlSetPos($vorschau_background_id[3][3],-99,-99) GUICtrlSetPos($vorschau_background_id[2][3],-99,-99) GUICtrlSetPos($vorschau_id[3][1],2*25+300,0*25+30) GUICtrlSetPos($vorschau_id[3][2],2*25+300,1*25+30) GUICtrlSetPos($vorschau_id[3][3],2*25+300,2*25+30) GUICtrlSetPos($vorschau_id[3][4],1*25+300,2*25+30) EndIf If $random=4 Then GUICtrlSetPos($vorschau_background_id[3][1],-99,-99) GUICtrlSetPos($vorschau_background_id[3][2],-99,-99) GUICtrlSetPos($vorschau_background_id[3][3],-99,-99) GUICtrlSetPos($vorschau_background_id[2][1],-99,-99) GUICtrlSetPos($vorschau_id[4][1],2*25+300,0*25+30) GUICtrlSetPos($vorschau_id[4][2],2*25+300,1*25+30) GUICtrlSetPos($vorschau_id[4][3],2*25+300,2*25+30) GUICtrlSetPos($vorschau_id[4][4],1*25+300,0*25+30) EndIf If $random=5 Then GUICtrlSetPos($vorschau_background_id[3][1],-99,-99) GUICtrlSetPos($vorschau_background_id[3][2],-99,-99) GUICtrlSetPos($vorschau_background_id[3][3],-99,-99) GUICtrlSetPos($vorschau_background_id[2][2],-99,-99) GUICtrlSetPos($vorschau_id[5][1],2*25+300,0*25+30) GUICtrlSetPos($vorschau_id[5][2],2*25+300,1*25+30) GUICtrlSetPos($vorschau_id[5][3],2*25+300,2*25+30) GUICtrlSetPos($vorschau_id[5][4],1*25+300,1*25+30) EndIf If $random=6 Then GUICtrlSetPos($vorschau_background_id[2][1],-99,-99) GUICtrlSetPos($vorschau_background_id[2][2],-99,-99) GUICtrlSetPos($vorschau_background_id[3][2],-99,-99) GUICtrlSetPos($vorschau_background_id[3][3],-99,-99) GUICtrlSetPos($vorschau_id[6][1],1*25+300,0*25+30) GUICtrlSetPos($vorschau_id[6][2],1*25+300,1*25+30) GUICtrlSetPos($vorschau_id[6][3],2*25+300,1*25+30) GUICtrlSetPos($vorschau_id[6][4],2*25+300,2*25+30) EndIf If $random=7 Then GUICtrlSetPos($vorschau_background_id[3][1],-99,-99) GUICtrlSetPos($vorschau_background_id[3][2],-99,-99) GUICtrlSetPos($vorschau_background_id[2][2],-99,-99) GUICtrlSetPos($vorschau_background_id[2][3],-99,-99) GUICtrlSetPos($vorschau_id[7][1],2*25+300,0*25+30) GUICtrlSetPos($vorschau_id[7][2],2*25+300,1*25+30) GUICtrlSetPos($vorschau_id[7][3],1*25+300,1*25+30) GUICtrlSetPos($vorschau_id[7][4],1*25+300,2*25+30) EndIf EndFunc Func _restart() For $i=1 To 4 GUICtrlSetPos($current_id[$i],-99,-99) $reserve_id[$current_colour][$reserve_anzahl[$current_colour]+$i]=$current_id[$i] Next $reserve_anzahl[$current_colour]=$reserve_anzahl[$current_colour]+4 For $i=1 To 20 For $s=1 To 10 If $feld_status[$i][$s]=1 Then GUICtrlSetPos($lieing_id[$i][$s],-99,-99) $reserve_anzahl[$lieing_colour[$i][$s]]=$reserve_anzahl[$lieing_colour[$i][$s]]+1 $reserve_id[$lieing_colour[$i][$s]][$reserve_anzahl[$lieing_colour[$i][$s]]]=$lieing_id[$i][$s] $feld_status[$i][$s]=0 EndIf Next Next $points=0 $item=1 $level=1 $teiler=500 GUICtrlSetData($label_level,"Level: " & $level) GUICtrlSetData($label_points,"Your Points:" & @CRLF & $points) _new_item() _hotkey_enable() EndFunc Func _game_over() If MsgBox(4,"Game over","Do you want to restart?")=6 Then _restart() Else Exit EndIf EndFunc Tetris.zip.8d0c5479a29d485ddcfc25ebf99034b4 Tetris1.1.zip.7ea30ae74d32fb7e704881655b7e43fa Tetris1.11.zip.327332ac5fee9bde192ff811c0ca4338
    1 point
  13. Valik

    " in a Msg

    You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with. This should be in the v3 Help and Support forum.
    1 point
  14. Markus

    Tower of Hanoi

    Hi! I just developed an algorithmus + graphic output for the Tower of Hanoi. Most of you might know it, we made the tower in our last maths lessons and as i have few ideas what i could write in the last time, i used tonight to code a perfect solution prog for the Tower of Hanoi. Here's the outcome. #include <GUIConstants.au3> $sleeptime=15 Opt("GUIOnEventMode", 1) GUISetOnEvent($GUI_EVENT_CLOSE, "_exit") GUICreate("Tower of Hanoi 1.1 by Markus Braun",770,280) Global $scheibe[100] Global $scheiben_stapel_pos[100] Global $scheiben_x_pos[100] Global $scheiben_y_pos[100] Global $scheiben_width[100] Global $scheiben_height[100] Global $scheiben_colour[100] Global $zwischensteps[100] Global $steps_to_next_movement[100] Global $next_move_to[100] Global $count_way[100];0=rückwärts 1=vorwärts Global $anzahl_scheiben=10 Global $stapelhoehe[4] Global $stapelstabxpos[4] Global $step=0 $stapelhoehe[1]=10 $stapelhoehe[2]=0 $stapelhoehe[3]=0 $stapelstabxpos[1]=110 $stapelstabxpos[2]=330 $stapelstabxpos[3]=550 ;left pos= 680 + 10 $id_label_steps=GUICtrlCreateLabel("Steps: 0", 690,60,70,20) $id_button_higher=GUICtrlCreateButton("higher", 690,100,70,20) $id_label_speed=GUICtrlCreateLabel("Speed: " & $sleeptime & "ms", 690,120,70,20,-1,$WS_EX_CLIENTEDGE ) $id_button_lower=GUICtrlCreateButton("lower", 690,140,70,20) GUICtrlSetOnEvent($id_button_higher, "_higher_speed") GUICtrlSetOnEvent($id_button_lower, "_lower_speed") GuiCtrlCreateGraphic(110, 60, 20,200) GUICtrlSetBkColor(-1,0x8B4513) GUICtrlSetColor(-1,0) GuiCtrlCreateGraphic(330, 60, 20,200) GUICtrlSetBkColor(-1,0x8B4513) GUICtrlSetColor(-1,0) GuiCtrlCreateGraphic(550, 60, 20,200) GUICtrlSetBkColor(-1,0x8B4513) GUICtrlSetColor(-1,0) For $i=$anzahl_scheiben To 1 Step -1;i=0!! $scheibe[$i]=GuiCtrlCreateGraphic(20+($anzahl_scheiben-$i)*10, 240-($anzahl_scheiben-$i)*20, 200-($anzahl_scheiben-$i)*20,20) If mod($i, 2) = 0 Then GUICtrlSetBkColor(-1,0xff0000) $scheiben_colour[$i]=1 Else GUICtrlSetBkColor(-1,0x0000ff) $scheiben_colour[$i]=0 EndIf GUICtrlSetColor(-1,0) $scheiben_stapel_pos[$i]=1 $scheiben_x_pos[$i]=20+($anzahl_scheiben-$i)*10 $scheiben_y_pos[$i]=240-($anzahl_scheiben-$i)*20 $scheiben_width[$i]=200-($anzahl_scheiben-$i)*20 $scheiben_height[$i]=20 Next GUISetState() ;Versuch Folgen zu finden, durch Aufschreiben der perfekten Variante #cs _move_and_set_vars(1,3) _move_and_set_vars(2,2) _move_and_set_vars(1,2) _move_and_set_vars(3,3) _move_and_set_vars(1,1) _move_and_set_vars(2,3) _move_and_set_vars(1,3) _move_and_set_vars(4,2) _move_and_set_vars(1,2) _move_and_set_vars(2,1) _move_and_set_vars(1,1) _move_and_set_vars(3,2) _move_and_set_vars(1,3) _move_and_set_vars(2,2) _move_and_set_vars(1,2) _move_and_set_vars(5,3) _move_and_set_vars(1,1) _move_and_set_vars(2,3) _move_and_set_vars(1,3) _move_and_set_vars(3,1) _move_and_set_vars(1,2) _move_and_set_vars(2,1) _move_and_set_vars(1,1) _move_and_set_vars(4,3) _move_and_set_vars(1,3) _move_and_set_vars(2,2) _move_and_set_vars(1,2) _move_and_set_vars(3,3) _move_and_set_vars(1,1) _move_and_set_vars(2,3) _move_and_set_vars(1,3) #ce ;-->Regelmäßigkeit der Scheiben die bewegt werden 1 2 1 3 1 2 1 4 1 2.... ;zwischensteps bis scheibe wieder bewegt wird ist: ;a(n+1)=a(n)+2^n -->rekursive folge $zwischensteps[0]=0 For $i=1 To $anzahl_scheiben $zwischensteps[$i]=$zwischensteps[$i-1]+2^($i-1) ;MsgBox(0,$i,$zwischensteps[$i]) Next ;erste bewegung nach $zwischensteps(n-1) For $i=1 To $anzahl_scheiben $steps_to_next_movement[$i]=$zwischensteps[$i-1]+1 ;MsgBox(0,$i,$steps_to_next_movement[$i] & " " & $zwischensteps[$i]) ;MsgBox(0,$i,$zwischensteps[$i]) Next ;-->Regelmäßigkeit der Stäbe wo sie hinbewegt werden. ;Scheibe 1 beginnt bei bewegung nach stab 3 und wird dann rückwärtsgezählt ;Scheibe 2 beginnt bei bewegung nach stab 2 und wird dann hochgezählt $next_move_to[0]=2 For $i=1 To $anzahl_scheiben If $next_move_to[$i-1]=3 Then $next_move_to[$i]=2 Else $next_move_to[$i]=3 EndIf Next $count_way[0]=1 For $i=1 To $anzahl_scheiben If $count_way[$i-1]=0 Then $count_way[$i]=1 Else $count_way[$i]=0 EndIf Next While 1 For $s=1 To $anzahl_scheiben $steps_to_next_movement[$s]-=1 If $steps_to_next_movement[$s]=0 Then _move_and_set_vars($s,$next_move_to[$s]) $step=$step+1 GUICtrlSetData($id_label_steps,"Steps: " & $step) $steps_to_next_movement[$s]=$zwischensteps[$s]+1 If $count_way[$s]=1 Then $next_move_to[$s]+=1 If $next_move_to[$s]=4 Then $next_move_to[$s]=1 EndIf Else $next_move_to[$s]-=1 If $next_move_to[$s]=0 Then $next_move_to[$s]=3 EndIf EndIf ;check finished? For $i=1 To $anzahl_scheiben If $scheiben_stapel_pos[$i]<>$scheiben_stapel_pos[$anzahl_scheiben] Then ExitLoop ElseIf $i=$anzahl_scheiben Then While 1 WEnd EndIf Next EndIf Next WEnd Func _move_and_set_vars($scheiben_id,$ziel_stapel) ;heben GUISetOnEvent($GUI_EVENT_CLOSE, "_exit") GUICtrlSetOnEvent($id_button_higher, "_higher_speed") GUICtrlSetOnEvent($id_button_lower, "_lower_speed") While $scheiben_y_pos[$scheiben_id]>40 $scheiben_y_pos[$scheiben_id]-=20 GUICtrlSetPos($scheibe[$scheiben_id],$scheiben_x_pos[$scheiben_id],$scheiben_y_pos[$scheiben_id]) Sleep($sleeptime) WEnd ;verschieben $verschiebung=($ziel_stapel-$scheiben_stapel_pos[$scheiben_id])*220 For $i=20 To Abs($verschiebung) Step 20 If $verschiebung<0 Then $scheiben_x_pos[$scheiben_id]-=20 Else $scheiben_x_pos[$scheiben_id]+=20 EndIf GUICtrlSetPos($scheibe[$scheiben_id],$scheiben_x_pos[$scheiben_id],$scheiben_y_pos[$scheiben_id]) Sleep($sleeptime) Next ;senken $senktiefe=240-$stapelhoehe[$ziel_stapel]*20 While $scheiben_y_pos[$scheiben_id]<$senktiefe $scheiben_y_pos[$scheiben_id]+=20 GUICtrlSetPos($scheibe[$scheiben_id],$scheiben_x_pos[$scheiben_id],$scheiben_y_pos[$scheiben_id]) Sleep($sleeptime) WEnd $stapelhoehe[$ziel_stapel]+=1 $stapelhoehe[$scheiben_stapel_pos[$scheiben_id]]-=1 $scheiben_stapel_pos[$scheiben_id]=$ziel_stapel ;$scheiben_x_pos[1],$scheiben_y_pos[1],$scheiben_width[1],$scheiben_height[1],$scheiben_stapel_pos[1] ;senken EndFunc Func _exit() Exit EndFunc Func _higher_speed() $sleeptime+=5 GUICtrlSetData($id_label_speed,"Speed: " & $sleeptime & "ms") EndFunc Func _lower_speed() If $sleeptime>0 Then $sleeptime-=5 GUICtrlSetData($id_label_speed,"Speed: " & $sleeptime & "ms") EndFunc Some feedback would be nice^^ Markus Tower_of_Hanoi_1.1.au3
    1 point
  15. Instead of using .click on the button, use .focus and then Send("{ENTER}") The alert still comes up but your script is free to continue. I think there is an example of the's approach in replys of the IE.au3 thread. Dale
    1 point
×
×
  • Create New...