Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/07/2020 in all areas

  1. BugFix version - 27 Dec 23 Fixed: No default value set for the MaxWidth parameter - took 12 years for someone to notice it! New UDF and new examples below and in zip. I just realised that although I have posted versions of this UDF many times in Help topics, I had never actually posted a "final" version here in Example scripts - better late than never, I suppose! StringSize takes a text string and calculates the size of label required to hold it as well as formatting the string to fit. Now AutoIt will, of course, size a label automatically to fit a text string, but it will not format the string in any way - what you use as the string is what you get in the label. If you do set any label sizes the text will be wrapped, but you can only determine the correct size of the label by trial and error. StringSize will, however, reformat the string to fit in a given width and tell you the required height so that you can read it all - whatever the font type or size - and you do not have to do the formatting beforehand. Here is a simple example to show what I mean (you need the UDF in the same folder for all the examples): And here is an example showing how StringSize can deal with different fonts and text sizes: You can see that the GUI is perfectly sized each time and that the button is always the right size and in the right place. StringSize returns an array which contains the formatted text to display and the size of the label needed to display it. All you need to do is to use the array elements when you create your label. Try changing the values in $aFont and $aSize if you want to try you own favourites - but beware, StringSize will return an error if you make the size so large that it cannot fit a word into the label width. NEW A more complex example showing how formatted and unformatted text can be sized correctly. The width of GUI holding the unformatted text varies randomly in width (the current value is displayed at top right): NEW And a final example showing how you can get your text in the largest possible font to fit in a given space: Finally here is the UDF itself: And all 5 files in zip format: StringSize.zip I hope you find this useful - I certainly do. M23
    1 point
  2. Inspired by i've made a little tool for simply QR-Code creation with all required stuff in the au3-file (dll included as binary string, because that, the au3 has 447kB and can not attached directly). By testing on my system the max. possible count of chars to encode are: $__QR_MAX_LEN = 3049. But on other systems it was round 2000 chars. Also on another computer the creation of QR-Code fails generally. But ist was the same system that i have (Win 7, 64 bit). I do not know the reason for this behavior. Would be interesting, how this script runs on other machines. You can store the QR-Image as *.png and/or *.bmp and/or copy it to clipboard. Here you can download QR_Creator.au3 Have a look:
    1 point
  3. #include <SQLite.au3> ;~ #include <SQLite.dll.au3> Local $hQuery, $aRow, $aNames _SQLite_Startup() ConsoleWrite("_SQLite_LibVersion=" & _SQLite_LibVersion() & @CRLF) _SQLite_Open() ; open :memory: Database _SQLite_Exec(-1, "CREATE TABLE aTest (A,B int not null unique ,C text);") _SQLite_Exec(-1, "INSERT INTO aTest(a,b,c) VALUES ('c','2','World');") _SQLite_Exec(-1, "INSERT INTO aTest(a,b,c) VALUES ('b','3',' ');") _SQLite_Exec(-1, "INSERT INTO aTest(a,b,c) VALUES ('a','1','Hello');") _SQLite_Query(-1, "SELECT _ROWID_,* FROM aTest ORDER BY a;", $hQuery) _SQLite_FetchTypes($hQuery, $aNames) ; Read out Column Types ConsoleWrite(StringFormat(" %-10s %-10s %-10s %-10s ", $aNames[0], $aNames[1], $aNames[2], $aNames[3]) & @CRLF) _SQLite_FetchNames($hQuery, $aNames) ; Read out Column Names ConsoleWrite(StringFormat(" %-10s %-10s %-10s %-10s ", $aNames[0], $aNames[1], $aNames[2], $aNames[3]) & @CRLF) While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK ConsoleWrite(StringFormat(" %-10s %-10s %-10s %-10s ", $aRow[0], $aRow[1], $aRow[2], $aRow[3]) & @CRLF) WEnd _SQLite_Exec(-1, "DROP TABLE aTest;") _SQLite_Close() _SQLite_Shutdown() ; Output: ; INTEGER int text ; rowid A B C ; 3 a 1 Hello ; 2 b 3 ; 1 c 2 World Func _SQLite_FetchTypes($hQuery, ByRef $aTypes) Dim $aTypes[1] If __SQLite_hChk($hQuery, 3, False) Then Return SetError(@error, 0, $SQLITE_MISUSE) Local $avDataCnt = DllCall($__g_hDll_SQLite, "int:cdecl", "sqlite3_column_count", "ptr", $hQuery) If @error Then Return SetError(1, @error, $SQLITE_MISUSE) ; DllCall error If $avDataCnt[0] <= 0 Then Return SetError(-1, 0, $SQLITE_DONE) ReDim $aTypes[$avDataCnt[0]] Local $avColName For $iCnt = 0 To $avDataCnt[0] - 1 $avColName = DllCall($__g_hDll_SQLite, "wstr:cdecl", "sqlite3_column_decltype16", "ptr", $hQuery, "int", $iCnt) If @error Then Return SetError(2, @error, $SQLITE_MISUSE) ; DllCall error $aTypes[$iCnt] = $avColName[0] Next Return $SQLITE_OK EndFunc ;==>_SQLite_FetchTypes If you wanna build a proper JSON string, you may want to know if is {"int":123} or {"text":"123"} and for that, this can help, obviously only when declared in the SQLite table.
    1 point
  4. FWIW, some of your concerns about "something going wrong" could be reduced or eliminated if you stopped using Send / Mouseclick and switched to using one of the UDFs designed for interacting with a browser.
    1 point
  5. By using IE.udf you can use _IETagNameGetCollection for li tags and read the innerText of the object. Something similar as this : #include <IE.au3> #include <MsgBoxConstants.au3> Local $oIE = _IECreate("you url here") Local $oInputs = _IETagNameGetCollection($oIE, "li") Local $sTxt = "" For $oInput In $oInputs $sTxt &= $oInput.innerText & @CRLF Next MsgBox($MB_SYSTEMMODAL, "li tags", $sTxt) _IEQuit($oIE) You will need to add error checking and inspect the content of the $sTxt to determine the course of actions.
    1 point
  6. Lgschez

    solved

    Sorry, was trying to see if I could speed up the process. My apologies
    1 point
  7. Shorter code as I recall. Going to close eyes now (5.40 AM here)
    1 point
  8. For the rowid (= meaningless "record number") you don't need autoincrement (unless you expect rowids numbers in the vincinity of 2^63 - 1), you don't need not null (because the PK here is type INTEGER) and you certainly don't need unique (which creates a needless duplicate "unique" index (PK can't be non-unique with a historical exception in SQLite for PK of types not INTEGER [distinct type from INT] where NULLs are always distinct). Any SQLite (SQL) table must have either an implicit rowid or a rowid alias in the form of a column like ID of type INTEGER declared as primary key. The difference between int and integer is specific to SQLite. Also SQLite doesn't honor declared sizes of column: char(14) is the same as char and you can store Mb of text in it. The type system of SQLite is flexible: you can store any type in any column except the rowid or rowid alias (INTEGER type). Declaring a type for a column is only an indication for what SQLite calls affinity. In an int[teger] column, you can input '123' and since the conversion to int is lossless, then SQLite will store 123 as int. ' 123' can't be stored losslessly (leading space) and will store as text ( = char). Else you can declare a column of type you call humour and all is fine. This "type" is unknow and no attempt at conversion will occur, no error either. This type system fits AutoIt variants well enough for most purpose, but you can always force storage of only controlled types by using check contraint(s) or trigger(s). You don't need to provide a value for an Id of type integer either in your inserts, except if you declare ID in the list of columns to insert (even then you can provide Null and it will create a new unique id for you). You can use create table if not exists blah ... which won't error out if the table blah already exists. You probably should merge date and time columns and specify default CURRENT_DATETIME: SQLite date/time are UTC and that makes them universal. You can manipulate timestamps to convert to local time, or whatever. Prefer the format YYYY-MM-DD since it's the format used by internal datetime functions, contrary to _NowDate() which uses YYYY/MM/DD. I anticipate you'll be extracting data based on timestamps and meter# so better use the format SQLite can manipulate inherently. It's always easy to convert to another format for display, outside the storage engine. The error column looks like binary or even ternary logic (Y/N/don't know). Hence you can store it as int (regular 0=N, 1= Y, Null if don't know) as SQLite stores and handles these values in a special format.
    1 point
  9. I will play with it and post my findings - as soon as I find some spare time
    1 point
  10. nah Updated the Beta lua script. Thanks for testing and the feedback. Jos
    1 point
  11. To add a bit more precision : $oIexp.document.parentwindow.frames.item (0) is the same thing as $oIexp.document.getElementsByTagName('iframe').item(0).contentWindow
    1 point
  12. It are just different objects with different methods https://www.w3schools.com/jsref/met_document_getelementsbytagname.asp The getElementsByTagName() method returns a collection of all elements in the document with the specified tag name, as an HTMLCollection object
    1 point
  13. Hello, $oIexp.document.getElementsByTagName('iframe').item(0) returns HTMLFrameElement object $oIexp.document.parentwindow.frames.item(0) returns HTMLWindow2 object Saludos
    1 point
  14. Hello, I would like to share the development of one of the applications I am creating in Autoit using this UDF http://www.youtube.com/watch?v=1hOYy6cyAZ8
    1 point
  15. Kip

    _StringSize UDF

    There is not much else to say when you've read the title and description. The function + example: $text = "Hello World! Whazzup"&@CRLF&"enter"&@CRLF&"enter"&@CRLF&"enter"&@CRLF&"enter"&@CRLF&"enter"&@CRLF&"enter"&@CRLF&"enter" $iSize = 8.5 $sFont = "Courier New" $hGui = GUICreate("dsd") $Label_1 = GUICtrlCreateLabel($text,10,10,500,500) GUICtrlSetFont (-1, $iSize, 400, 0, $sFont) $aSize = _StringSize($text, $sFont, $iSize) GUICtrlCreateLabel("",10,0,$aSize[0],9) ; Horizontal bar GUICtrlSetBkColor(-1,0x000000) GUICtrlCreateLabel("",0,10,9,$aSize[1]) ; Vertical bar GUICtrlSetBkColor(-1,0x000000) GUISetState() While 1 WEnd ; Created by Zedna? +Kip ; Returns an array: ; [0] = width (px) ; [1] = height (px) Func _StringSize($sText, $sFont="Ms Sans Serif", $iSize=8.5, $bItalic=False, $bUnderlined=False, $bStrike=False, $iWeight=400, $sLineBreak=@CRLF) Local $aReturn[2] Local $hGui = GUICreate("dsd") Local $iStyle = 0 $iStyle += $bItalic*2 $iStyle += $bUnderlined*4 $iStyle += $bStrike*8 Local $iLabel = GUICtrlCreateLabel("",10,10,500,500) GUICtrlSetFont (-1, $iSize, $iWeight, $iStyle, $sFont) Local $hControl = GUICtrlGetHandle($iLabel) Local $hDC = DLLCall("user32.dll","int","GetDC","hwnd",$hControl) $hDC = $hDC[0] Local $hFont = DllCall("user32.dll", "ptr", "SendMessage", "hwnd", $hControl, "int", 0x0031, "int", 0, "int", 0) $hFont = $hFont[0] Local $hOldFont = DllCall("GDI32.dll", "hwnd", "SelectObject", "hwnd", $hDC, "hwnd", $hFont) $hOldFont = $hOldFont[0] Local $struct_size = DllStructCreate("int;int") Local $sLineSplit = StringSplit($sText,$sLineBreak,1) Local $i For $i = 1 to $sLineSplit[0] DllCall("gdi32.dll", "int", "GetTextExtentPoint32", "int", $hDC, "str", $sLineSplit[$i], "long", StringLen($sLineSplit[$i]), "ptr", DllStructGetPtr($struct_size)) ;MsgBox(0,"sdsd",DllStructGetData($struct_size,1)) If DllStructGetData($struct_size,1) > $aReturn[0] Then $aReturn[0] = DllStructGetData($struct_size,1) $aReturn[1] += DllStructGetData($struct_size,2) Next DllCall("GDI32.dll", "hwnd", "SelectObject", "hwnd", $hDC, "hwnd", $hOldFont) DllCall("GDI32.dll", "int", "DeleteObject", "int", $hOldFont) DllCall("User32.dll", "int", "ReleaseDC", "hwnd", 0, "hwnd", $hDC) GUIDelete($hGui) Return $aReturn EndFunc
    1 point
×
×
  • Create New...