
HansH
Active Members-
Posts
51 -
Joined
-
Last visited
Everything posted by HansH
-
SQLite semi Embedded database functionality in AutoIt
HansH replied to ptrex's topic in AutoIt Example Scripts
Well I think that it should not be embedded in autoit as default database. I rather see standard odbc functions in autoit, which supplies you with a standard interface to a database (local or remote). It also will make programs independent of the database, so people can choose there own database. Since odbc is in windows it exposes no overhead to autoit. -
Interesting, did some changes:- added extension and length of the random generation to it - changed the prefix defaulting to "~" - default extension is including the . - random generation is a little changed, I noticed it did float and then round, so I changed it to integers which saves a function call Current random generation gives a little more randomize than the hex way, which has an advantage for shorter filenames. I specifcally added a check for an ending \ in the directory name, to avoid users using it as _TempFile("c:\") Func _TempFile($s_DirectoryName=@Tempdir, $s_FilePrefix="~", $s_FileExtension=".tmp", $i_RandomLength=6) Local $s_TempName ; add trailing \ for directory name If StringRight($s_DirectoryName,1) <> "\" Then $s_DirectoryName &= "\" Do $s_TempName = "" While StringLen($s_TempName) < $i_RandomLength $s_TempName &= Chr(Random(97, 122,1)) Wend $s_TempName = $s_DirectoryName & $s_FilePrefix & $s_TempName & $s_FileExtension Until Not FileExists($s_TempName) Return ($s_TempName) EndFunc Better, or keep the first version ?
-
I changed the function _TempFile in FILE.au3 to accept some parameters to have more control where and how the tempfile is created. The new parameters are optional, so previous use of the function will not break New code: ;=============================================================================== ; ; Function Name: _TempFile([s_DirectoryName],[s_FilePrefix]) ; Description: Generate a name for a temporary file. The file is guaranteed ; not to already exist in the user's %TEMP% or given directory. ; Parameter(s): ; $s_DirName optional Name of directory for filename, defaults to @TempDir ; $s_FilePrefix optional File prefixname, defaults to "" ; Requirement(s): None. ; Return Value(s): Filename of a temporary file which does not exist. ; Author(s): Dale (Klaatu) Thompson and Hans Harder ; Notes: None. ; ;=============================================================================== Func _TempFile($s_DirectoryName=@Tempdir, $s_FilePrefix="") Local $s_TempName ; add trailing \ for directory name If StringRight($s_DirectoryName,1) <> "\" Then $s_DirectoryName &= "\" Do $s_TempName = "~" While StringLen($s_TempName) < 8 $s_TempName = $s_TempName & Chr(Round(Random(97, 122), 0)) Wend $s_TempName = $s_DirectoryName & $s_FilePrefix & $s_TempName & ".tmp" Until Not FileExists($s_TempName) Return ($s_TempName) EndFunc New example: #include <File.au3> Dim $s_TempFile, $s_FileName ; generate unique filename in @TempDir $s_TempFile = _TempFile() ; generate unique filename in given directory and starting with tst_ $s_FileName = _TempFile("C:\", "tst_") MsgBox(4096, "Info", "Names suitable for new temporary file : " & @LF & $s_TempFile & @LF & $s_FileName) Exit If there any remarks, please let me know.
-
That's stupid of me, thx i am using the latest beta so that's ok Hans
-
I am trying to update a treeviewitem, is it possible ? Something like : #include <GUIConstants.au3> $gui = GuiCreate("treeviewtest", 450, 488, 490,360) $tree = GUICtrlCreateTreeView(10, 60, 300, 360,-1 , $WS_EX_CLIENTEDGE) $item = GUICtrlCreateTreeViewItem("original text", $tree) $bt_test = GUICtrlCreateButton("test", 330,60,60,20) GUISetState () while 1 $msg = GUIGetMsg() if $msg = $GUI_EVENT_CLOSE Then ExitLoop if $msg = $bt_test Then GUICtrlSetData("new text", $item) GUICtrlSetState($item,$GUI_SHOW) EndIf WEnd Exit But the treeitem keeps his old text, any ideas ?
-
if you do: _SQLopen() , windows will show a dialog were you can select your datasource.If the datasource requires an user/password it will prompt you for that. if you do: _SQLopen("DRIVER={SQL Server};SERVER=" & $server & ";DATABASE=" & $db & ";uid=" & $username & ";pwd=" & $password & ";") it will connect to that server or _SQLopen("DRIVER={SQL Server};") it will prompt you for uid and password if required. or _SQLopen("c:\test\test.mdb") to connect to an access db Simple and flexible Hans
-
Check all inputbox before continue
HansH replied to keyser's topic in AutoIt General Help and Support
You can also use the GuiFocus library, which gives you onfocus and onblur functionality for all controls. That means if you enter or leave a field by tabbing or clicking on a button a function will be activated. You can find the library here : http://www.autoitscript.com/fileman/users/HansH/GuiFocus.zip Forum thread 14979 #include <GUIConstants.au3> #include <GUIFocus.au3> ;Create window $Gui = GUICreate("onfocus and onblur example", 240, 200) $Inp_1 = GUICtrlCreateInput("", 35, 20, 160, 20 ) $Inp_2 = GUICtrlCreateInput("", 35, 50, 160, 20) $Btn_1 = GUICtrlCreateButton("Save", 70, 85, 70, 25) GUICtrlSetState(-1, $GUI_DISABLE) ; Disable button ; DEFINE onfocus and onblur functions _GuiFocusDefine($Gui, $Inp_1, "", "FLD1_onblur") _GuiFocusDefine($Gui, $Inp_2, "FLD2_onfocus") ; Set start field and show windo GUICtrlSetState($Inp_1, $GUI_FOCUS) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() _GuiFocusCheck($Gui) if $msg = $GUI_EVENT_CLOSE then ExitLoop if $msg = $Btn_1 then MsgBox(64,"Save", "save button executed",2); WEnd Exit Func FLD1_onblur() $value = GUICtrlRead($Inp_1) if StringLen($value) < 5 Then MsgBox(64,"Input Error", "Mandatory field, please fill in at least 5 characters") GUICtrlSetState($Inp_1, $GUI_FOCUS) GUICtrlSetState($Btn_1, $GUI_DISABLE) SetError(1) ; signal not to continue with possible onfocus, error encountered else GUICtrlSetState($Btn_1, $GUI_ENABLE) ; enable button if content is ok Endif EndFunc Func FLD2_onfocus() ; if empty set default value ok if GUICtrlRead($Inp_2) = "" Then GUICtrlSetData($Inp_2, "ok" ) EndFunc -
Uploaded latest version of library and demo program Changes: - Added _SQLschema() for catalog information about tables - expanded example program to show table information When double click on a table the column information is shown. Have fun Hans
-
This UDF library has some basic functions for connecting and querying SQL databases. The UDF library can be found here : http://www.autoitscript.com/fileman/users/HansH/SQL.au3 If you have remarks or improvements, let me know, so I can adapt it and do the documentation according the UDF standards Underneath a small example how to use this. #include <GUIConstants.au3> #include <SQL.au3> ; ============================================================== ; Define a general COM error handler for intercepting COM errors ; ============================================================== ; Variable $sCOMErrMsg will contain: "Errorno:Error message" Global $sCOMErrMsg="" $oCOMError = ObjEvent("AutoIt.Error","_COMErrHandler"); Install a COM error handler ; DBid of connection Global $oDBid=0 ; ======================================== ; GUI controls ; ======================================== GuiCreate("SQL test", 500, 400, 400,300 ) GUICtrlCreateLabel("DSN :", 12, 22) $inp_DSN = GUICtrlCreateCombo("", 50, 20, 320, 20) GUICtrlSetData(-1,_SQLGetDSN()) ; fill it with known entries $bt_DB = GUICtrlCreateButton("Connect" , 400, 20, 80, 20) $inp_qry = GUICtrlCreateEdit("" , 10, 50,360, 120) $bt_run = GUICtrlCreateButton("Run" , 400, 50, 80, 20) $lst_qry = GUICtrlCreateListView("Result", 10, 180, 480, 200) GUISetState () While 1 $msg = GUIGetMsg() if $msg <> 0 then Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $bt_DB ; DB open or close if $oDBid = 0 Then $oDBid=_SQLOpen(GuiCtrlRead($inp_DSN)) if @error then MsgBox(64,"Error",$sCOMErrMsg); Else GUICtrlSetData($bt_DB,"Disconnect") Endif Else _SQLclose($oDBid) GUICtrlSetData($bt_DB,"Connect") $oDBid=0 Endif Case $msg = $bt_run ; run query, max 1000 rows allowed $qryid = _SQLQuery($oDBid, GUICtrlRead($inp_qry), 1000) if not @error then Dim $qryhdr, $qryresult $qryhdr = _SQLGetFields($qryid) GUICtrlDelete($lst_qry); $lst_qry = GUICtrlCreateListView($qryhdr, 10, 180, 480, 200) Do $qryresult = _SQLGetRow($qryid) if not @error Then GUICtrlCreateListViewItem($qryresult,$lst_qry) Until @error EndIf EndSelect EndIf WEnd if $oDBid <> 0 Then _SQLclose($oDBid) ; if still open, close the database GUIDelete() Exit ; This is a general COM error handler Func _COMErrHandler() $sCOMErrMsg=hex($oCOMError.number,8) & ":" & $oCOMError.description SetError(1) ; something to check for when this function returns Endfunc Have fun Hans
-
Well a UDF library can be simple, but sometimes it is complicated within, because it has to test for error conditions en functions must be flexible.For instance support for multiple open databases, so you can copy tables between databases. Download the SQL.au3 and put it in the include directory Underneath a basic test program Just replace the query with a real one #include <SQL.au3> Dim $oDBid, $qryid, $result $oDBid=_SQLOpen() ; open database or _SQLopen("DRIVER={SQL Server}") if not @error then ; if open is successfull $qryid = _SQLQuery($oDBid, "select * from something") ; send query While not @error ; retrieve all rows $result &= _SQLGetRow($qryid) & @LF ; append each row WEnd _SQLclose($oDBid) ; close connection msgbox(64,"Result",$result) ; show all rows Endif Tell me what you don't understand. Hans
-
My fault, if you do $adCN.Execute ( $query )where are the result rows going to ? I extracted all the ADO sql calls from my program and put them in http://www.autoitscript.com/fileman/users/HansH/SQL.au3 You can find a sample GUI program here Just change the include from GUISQL.au3 to SQL.au3 Hans
-
This UDF library has some basic functions for connecting and querying SQL databases. The UDF library can be found here : http://www.autoitscript.com/fileman/users/HansH/GUISQL.au3 If you have remarks or improvements, let me know, so I can adapt it and do the documentation according the UDF standards Underneath a small example how to use this. #include <GUIConstants.au3> #include <GUISQL.au3> ; ============================================================== ; Define a general COM error handler for intercepting COM errors ; ============================================================== ; Variable $sCOMErrMsg will contain: "Errorno:Error message" Global $sCOMErrMsg="" $oCOMError = ObjEvent("AutoIt.Error","_COMErrHandler"); Install a COM error handler ; DBid of connection Global $oDBid=0 ; ======================================== ; GUI controls ; ======================================== GuiCreate("SQL test", 500, 400, 400,300 ) GUICtrlCreateLabel("DSN :", 12, 22) $inp_DSN = GUICtrlCreateCombo("", 50, 20, 320, 20) GUICtrlSetData(-1,_SQLGetDSN()) ; fill it with known entries $bt_DB = GUICtrlCreateButton("Connect" , 400, 20, 80, 20) $inp_qry = GUICtrlCreateEdit("" , 10, 50,360, 120) $bt_run = GUICtrlCreateButton("Run" , 400, 50, 80, 20) $lst_qry = GUICtrlCreateListView("Result", 10, 180, 480, 200) GUISetState () While 1 $msg = GUIGetMsg() if $msg <> 0 then Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $bt_DB ; DB open or close if $oDBid = 0 Then $oDBid=_SQLOpen(GuiCtrlRead($inp_DSN)) if @error then MsgBox(64,"Error",$sCOMErrMsg); Else GUICtrlSetData($bt_DB,"Disconnect") Endif Else _SQLclose($oDBid) GUICtrlSetData($bt_DB,"Connect") $oDBid=0 Endif Case $msg = $bt_run ; run query, max 1000 rows allowed $qryid = _SQLQuery($oDBid, GUICtrlRead($inp_qry), 1000) if not @error then Dim $qryhdr, $qryresult $qryhdr = _SQLGetFields($qryid) GUICtrlDelete($lst_qry); $lst_qry = GUICtrlCreateListView($qryhdr, 10, 180, 480, 200) Do $qryresult = _SQLGetRow($qryid) if not @error Then GUICtrlCreateListViewItem($qryresult,$lst_qry) Until @error EndIf EndSelect EndIf WEnd if $oDBid <> 0 Then _SQLclose($oDBid) ; if still open, close the database GUIDelete() Exit ; This is a general COM error handler Func _COMErrHandler() $sCOMErrMsg=hex($oCOMError.number,8) & ":" & $oCOMError.description SetError(1) ; something to check for when this function returns Endfunc Mmm, of course the library has nothing to do with a GUI, so I will adapt the name later on. Any suggestions for an other name are welcome. Hans
-
So where does the output goes from execute ? If you want to do something with ado recordsets for results look at http://www.autoitscript.com/fileman/users/HansH/ODBCquery.au3 The only difference with ODBC is your connection string, code will be the same
-
How to pass array using com object ?
HansH replied to HansH's topic in AutoIt General Help and Support
Works ! You only must declare $arr[5]="Employees"If you fill any of the other arrayfields with "" it will do nothing. Const $adSchemaIndexes=12 Dim $arr[5] $arr[5]="Employees" $adoRs = $adoCon.OpenSchema ($adSchemaIndexes, $arr ) Thx -
How to pass array using com object ?
HansH replied to HansH's topic in AutoIt General Help and Support
Still not able to find a way to solve this, anybody ? -
Ok, than I don't spent any time trying. Thanks for the answers
-
Anybody knows if it is possible to disable a tabitem Currently it does not work, example: #include <GUIConstants.au3> $h_Gui = GuiCreate("tabtest", 704, 488, 490,360 ,BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) ; --- Tab --- $tab=GUICtrlCreateTab (2,2, 700,440) $tab_conn=GUICtrlCreateTabitem ("TAB 1") GUICtrlCreateLabel("label 1",200,100) $tab_schema=GUICtrlCreateTabitem ("TAB 2") GUICtrlSetState($tab_schema,$GUI_DISABLE) GUICtrlCreateLabel("label 2",200,100) $tab_query=GUICtrlCreateTabitem ("TAB 3") GUICtrlSetState($tab_query,$GUI_DISABLE) GUICtrlCreateLabel("label 3",200,100) GUICtrlCreateTabitem (""); end of Tab control GUISetState (@SW_SHOW,$h_Gui) While 1 $msg = GUIGetMsg() if $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd Exit You still can move between tabs, although they are disabled. Perhaps it is not supported ? Hans
-
Small application in autoit for doing QDBC queries Changes: - menu functions are now all functioning - changed variablenames and added more comments - added cliboard and save to file for results. - window resizing now corrected, final bug will be fixed in 3.1.1.71 Todo: - further improve catalog layout. You can download the latest version here : http://www.autoitscript.com/fileman/users/HansH/ODBCquery.au3 Have fun Hans
-
J,it doesnot work this way. The call function does not support variable passing So I am back to my original design. Hans
-
J,Yes, I looked at it. I'm saving the classname with the definition of the function for the control and checking in the loop if the current classname changes. Your doing an extra dll call in the loop to get an autoit controlid from it Well it saves some cpucycles by checking only the classname changes (no extra controlgetHandle and dllcall) Have to think if I can use this piece for passing the controlid to the user function, so you can define 1 onfocus or onblur function which get the controlid passed and the user can check what he wants to do perhaps something like: $GUI = GuiCreate("Has focus:") $one = GuiCtrlCreateButton("ok", 10, 10, 100, 50) $two = GuiCtrlCreateButton("cancel", 10, 110, 100, 50) $three = GuiCtrlCreateButton("maybe", 10, 210, 100, 50) GuiSetState() do $msg = GuiGetMsg() ; _GuiFocusCheck ( onblurfunc, onfocusFunc (default=onblurfunc)) _GuiFocusCheck("DOcheck") until $msg = $GUI_EVENT_CLOSE Func DOcheck($h_controlid, $s_type) ; type="onblur" or " onfocus" select case $h_controlid = $one ; do something case $h_controlid = $three ; do something EndSelect EndFuncThat would save the define of the focusfunctions and storages of that. GuiFocuscheck will do 2 calls to the given functions for each focus change. Thats what you were meaning ? But then I also have to think of a solution what michael said about a label I will make a new version based on this and we can try it out. Hans
-
placed it in the bug report sectionthx
-
When resizing a window after you recreated a listview, the listview is not correctly redraw. - Run underneath code - resize the window using the mouse - hit the button, recreate the listview (will be the same size and position as shown) - resize the window using the mouse Is it a bug ? #include <GUIConstants.au3> GUICreate("listview resize test",300,200, 100,200, $WS_OVERLAPPEDWINDOW) ; --- create a 3 column list --- $listview = GUICtrlCreateListView ("col1|col2|col3 ", 20, 10, 240, 150) $item1=GUICtrlCreateListViewItem("item2|col22|col23",$listview) $button = GUICtrlCreateButton ("recreate",100,170,70,20) GUISetState() Do $msg = GUIGetMsg () if $msg = $button Then $a_info=ControlGetPos("", "", $listview) ; get current pos and size GUICtrlDelete($listview) ; delete current list ; --- create a 2 column list --- $listview = GUICtrlCreateListView ("col1|col2",$a_info[0],$a_info[1],$a_info[2],$a_info[3]) $item1=GUICtrlCreateListViewItem("item_a|item_b",$listview) EndIf Until $msg = $GUI_EVENT_CLOSE Exit
-
Hi Holger, I checked the help, but I missed that one Just what I needed, thanks ! Hans
-
HI, I am missing a GUICtrlGetPos to get the corrent position / size of a control (a listView) Is there a other way to get those values of a control ? Hans
-
Michel, that is a tricky one, official it doesnot get focus and you could trap that by just <{POST_SNAPBACK}> $LABEL = GUICtrlCreateLabel("label", 15, 85, 40, 20 ) While 1 $msg = GUIGetMsg() _GuiFocusCheck($Gui) if $msg = $GUI_EVENT_CLOSE then ExitLoop if $msg = $LABEL then MsgBox(64,"Label", "clicked",2); WEnd So why do you want to click on a label, or are you using it for instance as a hyperlink ? The only thing I perhaps can do in the _GuiFocusCheck is to trigger the onblur of the current control. Or make seperate functions for onblur and onfocus which you can use to force a check when a label is activated, for instance: $LABEL = GUICtrlCreateLabel("label", 15, 85, 40, 20 ) While 1 $msg = GUIGetMsg() _GuiFocusCheck($Gui) if $msg = $GUI_EVENT_CLOSE then ExitLoop if $msg = $LABEL then _GuiFocus_onblur() ; force onblur check on current control if not @error then MsgBox(64,"Label", "clicked",2); endif WEnd The last one has my preference. Will this solve your problem ? Hans