faustf Posted February 24, 2016 Share Posted February 24, 2016 hi guy i waqnt create a udf file for integrate with my program i created the udf like this expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.2 Author: myName Script Function: UDF DI CONNESSIONE DB Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <TabConstants.au3> #include <WindowsConstants.au3> #include <IE.au3> #include <SQLite.au3> #include <SQLite.dll.au3> #include <Array.au3> Global $database, $server, $port, $user, $pass, $DBP Func _Connetti_DB_Postgres($database, $server, $port, $user, $pass) $objConn = ObjCreate("ADODB.Connection") Local $test1 = $objConn.Open('Dsn=PostgreSQL35W;database=' & $database & ';server=' & $server & ';port=' & $port & ';uid=' & $user & ';pwd=' & $pass) If @extended Then Return SetError(0, @extended, $test1) EndIf Return SetError(1, 0, $test1) EndFunc ;==>_Connetti_DB_Postgres but i am not sure , how can return a data , i think is not good , like i setup , some one can explain me ?? Link to comment Share on other sites More sharing options...
mLipok Posted February 24, 2016 Share Posted February 24, 2016 I'll submit my ADO.au3 UDF. Wait a moment. Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
mLipok Posted February 24, 2016 Share Posted February 24, 2016 Try to look here: Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
faustf Posted February 24, 2016 Author Share Posted February 24, 2016 o thankz so much is very interesting , i look Link to comment Share on other sites More sharing options...
faustf Posted February 24, 2016 Author Share Posted February 24, 2016 i guy i have questions i try to creae my personal function udf i create a first file in this mode , this isa udf Func _Connetti_DB_Postgres($database, $server, $port, $user, $pass, $dsn) If $dsn = '' Then $objConn = ObjCreate("ADODB.Connection") $objConn.Open('Dsn=PostgreSQL35W;database=' & $database & ';server=' & $server & ';port=' & $port & ';uid=' & $user & ';pwd=' & $pass) If @error Then SetError(1) Return 0 Else Return $objConn EndIf Else $objConn = ObjCreate("ADODB.Connection") $objConn.Open('Dsn=' & $dsn & ';database=' & $database & ';server=' & $server & ';port=' & $port & ';uid=' & $user & ';pwd=' & $pass) If @error Then SetError(1) Return 0 Else Return $objConn EndIf EndIf EndFunc ;==>_Connetti_DB_Postgres and test program like this #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <TabConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #include "db_connector_UDF.au3" Local $strin=_Connetti_DB_Postgres('bitnami_openerp','127.0.0.1','5432','postgres','xxxxx','') MsgBox(0,'',$strin) but result of $strin is always blank , how is possible ?? i would , when the _Connetti_DB_Postgres go good have 1 and when not go good answer me with 0 how is possible thankz Link to comment Share on other sites More sharing options...
TheSaint Posted February 24, 2016 Share Posted February 24, 2016 (edited) Just advising, that if you are creating a true UDF, you should not be using Global for any declarations. From what I can see, you can just change Global to Local Especially if you are intending to share the UDF with others, as I imagine that $database, $server, $port, $user, $pass could very easily be used as variables by others in their scripts. On top of that, for a UDF you are sharing with others, you really should be using Best Coding Practices for naming your variables anyway. See the Wiki. Edited February 24, 2016 by TheSaint Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
faustf Posted February 24, 2016 Author Share Posted February 24, 2016 ok thankz for advice i correct this immidiatly Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 24, 2016 Moderators Share Posted February 24, 2016 TheSaint, Quote if you are creating a true UDF, you should not be using Global for any declarations Not at all. What is important is that any such Global declared variables have names which are extremely unlikely to be used by the script into which the UDF is "included". The "standard" UDFs prefix required Global variables as follows: $__g_ Hungarian notation for variable type (s/i/h etc) variable name Such a naming convention means that the names are "pretty much" guaranteed to be unique and not overwritten by the user. Most of my personal UDFs use a similar naming convention to try and prevent that situation arising. Of interest, in the case of the code in the OP, there is absolutely no need to declare any of the variables at all: The first 5 are all function parameters and so are Local to the function by default, while the 6th appears to be superfluous as it is not used within the code. In passing, I would also question the need for any of the #include lines. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
TheSaint Posted February 24, 2016 Share Posted February 24, 2016 I totally agree with you Melba23, and we have certainly had discussions about all that here before, so I was aware, just was targeting my advice, to the level of the user, without getting bogged down in detail, which may be over his head. But I also pointed him to the Wiki (Best Coding Practices) where he could gain deeper insight. I know that the complexity of some UDF's does indeed require Globals. I think you will agree they should be avoided though, if they can be, for even the smartest of variable naming can be defeated by a user who does seemingly odd things. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
faustf Posted February 24, 2016 Author Share Posted February 24, 2016 the udf is only for my program , but of course if i learn correct method is much better but why in my udf not return a value ?? thankz at all Link to comment Share on other sites More sharing options...
faustf Posted February 24, 2016 Author Share Posted February 24, 2016 for mLipoK i tryed your udf beta but not go example i have this error Running AU3Check (3.3.14.2) params:-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 from:C:\Program Files\AutoIt3 input:C:\Users\utente\Downloads\ADO 2.1.7 BETA\ADO_EXAMPLE__PostgreSQL.au3 "C:\Users\utente\Downloads\ADO 2.1.7 BETA\ADO_EXAMPLE__PostgreSQL.au3"(29,44) : warning: $oConnection: possibly used before declaration. _ADO_Connection_OpenConString($oConnection, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ "C:\Users\utente\Downloads\ADO 2.1.7 BETA\ADO_EXAMPLE__PostgreSQL.au3"(78,72) : warning: $oADOConnection: possibly used before declaration. Local $aProperties = _ADO_Connection_PropertiesToArray($oADOConnection) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ "C:\Users\utente\Downloads\ADO 2.1.7 BETA\ADO_EXAMPLE__PostgreSQL.au3"(78,72) : error: $oADOConnection: undeclared global variable. Local $aProperties = _ADO_Connection_PropertiesToArray($oADOConnection) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Users\utente\Downloads\ADO 2.1.7 BETA\ADO_EXAMPLE__PostgreSQL.au3 - 1 error(s), 2 warning(s) !>23:36:25 AU3Check ended. Press F4 to jump to next error.rc:2 +>23:36:25 AutoIt3Wrapper Finished. >Exit code: 2 Time: 0.7188 Link to comment Share on other sites More sharing options...
mLipok Posted February 24, 2016 Share Posted February 24, 2016 Sorry. My fault. I was tired when I finish this example. Try this: expandcollapse popup#include "ADO.au3" #Tidy_Parameters=/sort_funcs /reel #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 #include <Array.au3> #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> Global $sDSN = 'PostgreSQL35W' Global $sDatabase = '' Global $sServer = '' Global $sPort = '' Global $sUser = '' Global $sPassword = '' Global $sConnectionString = 'DSN=' & $sDSN & ';DATABASE=' & $sDatabase & ';SERVER=' & $sServer & ';PORT=' & $sPort & ';UID=' & $sUser & ';PWD=' & $sPassword & ';' ; Internal ADO.au3 UDF COMError Handler _ADO_ComErrorHandler_UserFunction(_ADO_COMErrorHandler) _Example_PostgreSQL_1() _Example_PostgreSQL_2() _Example_PostgreSQL_3() Func _Example_PostgreSQL_1() Local $oConnection = _ADO_Connection_Create() _ADO_Connection_OpenConString($oConnection, $sConnectionString) If @error Then Return SetError(@error, @extended, $ADO_RET_FAILURE) Local $sTableName = 'SOME_TABLE_NAME' Local $sQUERY = 'Select * from ' & $sTableName Local $oRecordset = _ADO_Execute($oConnection, $sQUERY) Local $aRecordsetArray = _ADO_Recordset_ToArray($oRecordset, False) Local $aRecordset_inner = _ADO_RecordsetArray_GetContent($aRecordsetArray) Local $iColumn_count = UBound($aRecordset_inner, $UBOUND_COLUMNS) For $iRecord_idx = 0 To UBound($aRecordset_inner) - 1 ConsoleWrite('==================================================================' & @CRLF) For $iColumn_idx = 0 To $iColumn_count - 1 ConsoleWrite($aRecordset_inner[$iRecord_idx][$iColumn_idx] & @CRLF) Next Next ; CleanUp $oRecordset = Null _ADO_Connection_Close($oConnection) $oConnection = Null EndFunc ;==>_Example_PostgreSQL_1 Func _Example_PostgreSQL_2() Local $oConnection = _ADO_Connection_Create() _ADO_Connection_OpenConString($oConnection, $sConnectionString) If @error Then Return SetError(@error, @extended, $ADO_RET_FAILURE) Local $sTableName = 'SOME_TABLE_NAME' Local $sQUERY = 'Select * from ' & $sTableName Local $aRecordset = _ADO_Execute($oConnection, $sQUERY, True) ; CleanUp _ADO_Connection_Close($oConnection) $oConnection = Null _ADO_REcordset_Display($aRecordset, $sTableName & ' - Recordset content') EndFunc ;==>_Example_PostgreSQL_2 Func _Example_PostgreSQL_3() Local $oConnection = _ADO_Connection_Create() _ADO_Connection_OpenConString($oConnection, $sConnectionString) If @error Then Return SetError(@error, @extended, $ADO_RET_FAILURE) Local $aProperties = _ADO_Connection_PropertiesToArray($oConnection) ; CleanUp _ADO_Connection_Close($oConnection) $oConnection = Null _ArrayDisplay($aProperties, "ADO connection - List of properties", "", 0, Default, "Name|Type|Value|Attributes") EndFunc ;==>_Example_PostgreSQL_3 Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
faustf Posted February 24, 2016 Author Share Posted February 24, 2016 dont worry your work inspire me , so much i tested thankz alot 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