Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 05/18/2018 in all areas

  1. I was playing around with simple GUI creation. I tend to like parameter driven coding (in prior life (years ago) as Clipper/FoxPro/dBase coder). Just wanted to see what I could do with a GUI. #Region options, includes Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) ; Change to OnEvent mode #include <GUIConstantsEx.au3> #EndRegion options, includes Global Const $nCols = 2, $nRows = 6, $nSpacer = 10, $nBtnWidth = 150, $nBtnHeight = 30 Global $xName = 0, $xID = 0 Global $nGUIWidth = ($nCols * $nBtnWidth) + (($nCols + 1) * $nSpacer) Global $nGUIHeight = ($nRows * $nBtnHeight) + (($nRows + 1) * $nSpacer) Global $hMainGUI = GUICreate("Calculated GUI", $nGUIWidth, $nGUIHeight, -1, -1) For $xRows = 1 to $nRows ;in this arrangement, tabbing is left to right, then next row For $xCols = 1 to $nCols ;reverse the order of this line with the prior line for top to bottom tabbing, then next col $xName += 1 $xID += 1 Global $Dummy = GUICtrlCreateButton("Button" & $xName, _ ($nBtnWidth * ($xCols - 1)) + (($xCols - 1) * $nSpacer) + $nSpacer, _ ($nBtnHeight* ($xRows - 1)) + (($xRows - 1) * $nSpacer) + $nSpacer, _ $nBtnWidth, _ $nBtnHeight) GUICtrlSetOnEvent($xID+2, "Handler") Next Next GUISetOnEvent($GUI_EVENT_CLOSE, "CloseApp") GUISetState(@SW_SHOW) While 1 Sleep(10) WEnd Func CloseApp() Exit EndFunc Func Handler() MsgBox(0,0,"Button " & @GUI_CtrlId - 2) EndFunc
    2 points
  2. I searched around on here for some SQL stuff to use with an MSDE database and I ended up getting confused so I tried to simplfy it a bit, there are only a couple of functions so far but I guess someone may find it usefull. I have a database called test and a table called BBKS This has been totally revamped now and it uses very similar syntax to the SQLITE3 functions included with Autoit3 It will break any scripts that used the previous _SQL.au3 file but the new file is much more user friendly See the example below #include <_sql.au3> #include <array.au3> Opt ("trayIconDebug",1) Msgbox(0,"","Start the Script and load the error handler") _SQL_RegisterErrorHandler();register the error handler to prevent hard crash on COM error $oADODB = _SQL_Startup() If $oADODB = $SQL_ERROR then Msgbox(0 + 16 +262144,"Error",_SQL_GetErrMsg()) If _sql_Connect(-1,"localhost","","sa","Superartcore") = $SQL_ERROR then Msgbox(0 + 16 +262144,"Error",_SQL_GetErrMsg()) _SQL_Close() Exit EndIf If _SQL_Execute(-1,"Create database My_SQL_Test;") = $SQL_ERROR then Msgbox(0 + 16 +262144,"Error",_SQL_GetErrMsg()) _SQL_Close() Msgbox(0,"","Created datatbase logging out and back in again") $oADODB = _SQL_Startup() If _SQL_Connect(-1,"localhost","My_SQL_Test","sa","Superartcore") = $SQL_ERROR then Msgbox(0 + 16 +262144,"Error",_SQL_GetErrMsg()) If _SQL_Execute(-1, "CREATE TABLE BBKS (ID INT NOT NULL IDENTITY(1,1),ComputerName VARCHAR(20) UNIQUE,Status VARCHAR(10),Error VARCHAR(10)Primary Key (ID));") = $SQL_ERROR then Msgbox(0 + 16 +262144,"Error",_SQL_GetErrMsg()) If _SQL_Execute(-1,"INSERT INTO BBKS (ComputerName,Status,Error) VALUES ('"& @computername & "','On;li''ne','None');") = $SQL_ERROR then Msgbox(0 + 16 +262144,"Error",_SQL_GetErrMsg()) If _SQL_Execute(-1,"INSERT INTO BBKS (ComputerName,Status,Error) VALUES ('1"& @computername & "','On;li''ne','None');") = $SQL_ERROR then Msgbox(0 + 16 +262144,"Error",_SQL_GetErrMsg()) If _SQL_Execute(-1,"INSERT INTO BBKS (ComputerName,Status,Error) VALUES ('2"& @computername & "','Online','None');") = $SQL_ERROR then Msgbox(0 + 16 +262144,"Error",_SQL_GetErrMsg()) ; this one will cause an error because the computername is not unique! If _SQL_Execute(-1,"INSERT INTO BBKS (ComputerName,Status,Error) VALUES ('2"& @computername & "','Online','None');") = $SQL_ERROR then Msgbox(0 + 16 +262144,"Error","Example Error this was meant to happen!" & @crlf & @crlf & _SQL_GETErrMsg()) Msgbox(0,"","Created table and added data so lets get some data out first as a 2dArray") Local $aData,$iRows,$iColumns;Variables to store the array data in to and the row count and the column count $iRval = _SQL_GetTable2D(-1,"SELECT * FROM BBKS;",$aData,$iRows,$iColumns) If $iRval = $SQL_OK then _arrayDisplay($aData,"2D (" & $iRows & " Rows) (" & $iColumns & " Columns)" ) Msgbox(0,"","Next as a 1dArray") Local $aData,$iRows,$iColumns;Variables to store the array data in to and the row count and the column count $iRval = _SQL_GetTable(-1,"SELECT * FROM BBKS;",$aData,$iRows,$iColumns) If $iRval = $SQL_OK then _arrayDisplay($aData,"1D (" & $iRows & " Rows) (" & $iColumns & " Columns)" ) Msgbox(0,"","And now the same data returned 1 row at a time") $hData = _SQL_Execute(-1,"SELECT * FROM BBKS;") Local $aNames;Variable to store the array data in to $iRval = _SQL_FetchNames ($hData, $aNames); Read out Column Names If $iRval = $SQL_OK then ConsoleWrite(StringFormat(" %-10s %-10s %-10s %-10s ", $aNames[0], $aNames[1], $aNames[2], $aNames[3]) & @CR) _ArrayDisplay($aNames,"Column Names") Local $aRow;Variable to store the array data in to While _SQL_FetchData ($hData, $aRow) = $SQL_OK; Read Out the next Row ConsoleWrite(StringFormat(" %-10s %-10s %-10s %-10s ", $aRow[0], $aRow[1], $aRow[2], $aRow[3]) & @CR) _ArrayDisplay($aRow,"Single Row of Data") WEnd Msgbox(0,"","And now the same data returned as a string") Local $vString If _Sql_GetTableAsString(-1,"SELECT * FROM BBKS;",$vString) = $SQL_OK then Msgbox(0,"Data as a String",$vString) Else Msgbox(0 + 16 +262144,"SQL Error",_SQL_GetErrMsg() ) EndIf Msgbox(0,"","Now just a single row") Local $aRow;Variable to store the row array data in $iRval = _SQL_QuerySingleRow(-1,"SELECT * FROM BBKS;",$aRow) If $iRval = $SQL_OK then _arrayDisplay($aRow,"1 Row" ) Msgbox(0,"","Now drop the tables and the database") If _SQL_Execute(-1, "DROP TABLE BBKS;") = $SQL_ERROR then Msgbox(0 + 16 +262144,"Error",_SQL_GetErrMsg()) If _SQL_Close() <> $SQL_OK then Msgbox(0 + 16 +262144,"Error",_SQL_GetErrMsg() ) ;Just being lazy and not putting any error checking in now! $oADODB = _SQL_Startup() _SQL_Connect(-1,"localhost","","sa","Superartcore") _SQL_Execute(-1,"DROP database My_SQL_Test;") _SQL_Close() Msgbox(0,"","Example Finished") Previous downloads: 4176 _SQL.au3 updated with some tweaks by eltorro, CarlH and Elias (Thanks) Updated 28/08/2010 Updated 29/04/2011 _sql_Old.au3 _sql.au3
    1 point
  3. Try this, it's much shorter. #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <TabConstants.au3> #include <GuiComboBoxEx.au3> #include <Array.au3> $Form = GUICreate("Form", 310, 297, 4, 35) Const $sAppIni = @AppDataDir & "\TEST.INI" WinSetOnTop("Form", "", True) ;##################################################################################################### $maintab = GUICtrlCreateTab(0, 0, 550, 400) ;##################################################################################################### GUICtrlCreateTabItem("Tab1") Global $array1[4] = ["$Name1", "$Name2", "$Name3", "$Name4"] $array1[0] = GUICtrlCreateInput("", 2, 55, 37, 30, BitOR($ES_CENTER, $ES_NUMBER)) GUICtrlSetFont(-1, 15, 800, 0, "Arial") GUICtrlSetData($array1[0], 0) $array1[1] = GUICtrlCreateInput("", 42, 55, 37, 30, BitOR($ES_CENTER, $ES_NUMBER)) GUICtrlSetFont(-1, 15, 800, 0, "Arial") GUICtrlSetData($array1[1], 0) $array1[2] = GUICtrlCreateInput("", 82, 55, 37, 30, BitOR($ES_CENTER, $ES_NUMBER)) GUICtrlSetFont(-1, 15, 800, 0, "Arial") GUICtrlSetData($array1[2], 0) $array1[3] = GUICtrlCreateInput("", 122, 55, 37, 30, BitOR($ES_CENTER, $ES_NUMBER)) GUICtrlSetFont(-1, 15, 800, 0, "Arial") GUICtrlSetData($array1[3], 0) $sb1 = GUICtrlCreateButton("Save", 1, 275, 150, 22) $sb2 = GUICtrlCreateButton("Load", 152, 275, 150, 22) $ec1 = GUICtrlCreateCombo("", 1, 254, 162, 22) GUICtrlSetFont(-1, 8, 800, 0, "Arial") _GUICtrlComboBox_SetCueBanner($ec1, "Name it") GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $sb1 save() Case $sb2 load() EndSwitch WEnd Func save() $ec1empty = GUICtrlRead($ec1) If $ec1empty = "" Then MsgBox(0, "", "Name it!") Else For $i = 0 To 3 IniWrite("TEST.INI", "Section", "$Input" & $i, GUICtrlRead($array1[$i])) Next EndIf EndFunc ;==>save Func load() For $i = 0 To 3 $readInput1 = GUICtrlSetData($array1[$i], IniRead("TEST.INI", "Section", "$Input" & $i, "Error")) Next EndFunc ;==>load An even shorter way. #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <TabConstants.au3> #include <GuiComboBoxEx.au3> #include <Array.au3> $Form = GUICreate("Form", 310, 297, 4, 35) Const $sAppIni = @AppDataDir & "\TEST.INI" WinSetOnTop("Form", "", True) ;##################################################################################################### $maintab = GUICtrlCreateTab(0, 0, 550, 400) ;##################################################################################################### GUICtrlCreateTabItem("Tab1") Global $array1[4] = ["$Name1", "$Name2", "$Name3", "$Name4"] For $I = 0 To 3 $array1[$i] = GUICtrlCreateInput("", 2 + ($i * 40), 55, 37, 30, BitOR($ES_CENTER, $ES_NUMBER)) GUICtrlSetFont(-1, 15, 800, 0, "Arial") GUICtrlSetData($array1[$i], 0) Next $sb1 = GUICtrlCreateButton("Save", 1, 275, 150, 22) $sb2 = GUICtrlCreateButton("Load", 152, 275, 150, 22) $ec1 = GUICtrlCreateCombo("", 1, 254, 162, 22) GUICtrlSetFont(-1, 8, 800, 0, "Arial") _GUICtrlComboBox_SetCueBanner($ec1, "Name it") GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $sb1 save() Case $sb2 load() EndSwitch WEnd Func save() $ec1empty = GUICtrlRead($ec1) If $ec1empty = "" Then MsgBox(0, "", "Name it!") Else For $i = 0 To 3 IniWrite("TEST.INI", "Section", "$Input" & $i, GUICtrlRead($array1[$i])) Next EndIf EndFunc ;==>save Func load() For $i = 0 To 3 $readInput1 = GUICtrlSetData($array1[$i], IniRead("TEST.INI", "Section", "$Input" & $i, "Error")) Next EndFunc ;==>load
    1 point
  4. Simply use an Array for the Names and the Inputs and use a for..Next loop to write them all into the ini. Post your runable test script when you want us to assist to make the change. Jos
    1 point
  5. Hi @p1xeL, and welcome to the AutoIt forum If you have created a set of variables named $Name1...n, and $Input1...n, then you could easily make an array in which you put all the variables ( $Name1...n ) and another array in which you put inputs ( $Input1...n ), and loop them to write in the .ini file. I think you could use another approach to do this... Maybe @Melba23 knows a little bit about this!
    1 point
  6. @Bilgus Very nice ! It will be useful for the .NET CLR UDF as well I see you reused some the CLR.au3 code Global Const $sIID_IDispatch = "{00020400-0000-0000-C000-000000000046}" Global Const $dtag_IDispatch = _         "GetTypeInfoCount hresult(dword*);" & _ ; Retrieves the number of type information interfaces that an object provides (either 0 or 1).         "GetTypeInfo hresult(dword;dword;ptr*);" & _ ; Gets the type information for an object.         "GetIDsOfNames hresult(ptr;ptr;dword;dword;ptr);" & _ ; Maps a single member and an optional set of argument names to a corresponding set of integer DISPIDs, which can be used on subsequent calls to Invoke.         "Invoke hresult(dword;ptr;dword;word;ptr;ptr;ptr;ptr);" ; Provides access to properties and methods exposed by an object. Rgds, ptrex
    1 point
  7. Version 0.0.1

    1,095 downloads

    This is an experimental AutoIt-to-machine code compiler, written in AutoIt, JavaScript and C. Make sure you have GCC installed and configured within CompileIt before using.
    1 point
×
×
  • Create New...