kashamalasha

How to put formatted text via GUICtrlSetData to native Edit field

9 posts in this topic

Hello.

Could you help me find the answer for my issue. I'm trying to set fomatted data wich is selected from SQL to GUICtrlCreateEdit field.

And the GUICtrlSetData function is inserting it in one line. But when I'm trying to do the same using MsgBox the data looks fine.

I'm trying to not use _GUICtrlRichEdit UDF.

Thanks in advance. Here is my test code.

#include <GUIConstants.au3>
#include <GUIListBox.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>

Opt("GUIOnEventMode", 1)

$hMainGUI = GUICreate("Test", 520, 240)
$hListBox = _GUICtrlListBox_Create($hMainGUI, "", 10, 10, 180, 80)
$hEdit = GUICtrlCreateEdit("", 10, 80, 500, 150)

GUISetState(@SW_SHOW, $hMainGUI)
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

Local $hQuery, $aRow
_SQLite_Startup()
$hDB = _SQLite_Open('MyDB.sqlite')

_SQLite_Query(-1, "SELECT ID ||"". "" || Name FROM Templates ORDER BY ID;", $hQuery)

While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK
    _GUICtrlListBox_AddString($hListBox, $aRow[0])
WEnd

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSE_Button")

While 1
    Sleep(100)
WEnd

Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox
    If Not IsHWnd($hListBox) Then $hWndListBox = GUICtrlGetHandle($hListBox)
    $hWndFrom = $lParam
    $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word
    $iCode = BitShift($wParam, 16) ; Hi Word

    Switch $hWndFrom
        Case $hListBox, $hWndListBox
            Switch $iCode
                Case $LBN_DBLCLK
                    Select_Template(_GUICtrlListBox_GetCurSel($hListBox) + 1)
                    Return 0
            EndSwitch
    EndSwitch
EndFunc   ;==>_WM_COMMAND

Func CLOSE_Button()
    _SQLite_Close()
    _SQLite_Shutdown()
    Exit
EndFunc   ;==>CLOSE_Button

Func Select_Template($sListItem)
    _SQLite_QuerySingleRow($hDB, _
            "SELECT Content " & _
            "FROM Templates " & _
            "WHERE ID = " & $sListItem & ";", $aRow)
;~      MsgBox(64, "Test: " & $sListItem, $aRow[0])
    GUICtrlSetData($hEdit, $aRow[0])
    WinSetTitle($hMainGUI, "", "Test: " & $sListItem)
EndFunc   ;==>Select_Template

 

1.PNG

2.PNG

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Insert a Console('Data: '&$YourRawDataFromSQLite&@crlf) in your script and post this line from console output.

Copy the line from edit and post it.

Edited by AutoBert

Share this post


Link to post
Share on other sites

Example:

^XA
^FX | Delete files from FLASH (E:)  | ^FS
^IDE:X5_*.*^FS
^XZ

Screenshot from ConsoleWrite:

 

1.PNG

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Use this:

Func Select_Template($sListItem)
    #cs
    _SQLite_QuerySingleRow($hDB, _
            "SELECT Content " & _
            "FROM Templates " & _
            "WHERE ID = " & $sListItem & ";", $aRow)
;~      MsgBox(64, "Test: " & $sListItem, $aRow[0])
    #ce
    Dim $aRow[1]        ;just for test delete it
    $aRow[0]="^XA^FX | Delete files from FLASH (E:)  | ^FS^IDE:X5_*.*^FS^XZ" ;just for test delete it
    $aRow[0]=StringStripWS(StringReplace(StringReplace($aRow[0],"^",@CRLF&"^"),@CRLF&"^FS","^FS"),$STR_STRIPLEADING)
    GUICtrlSetData($hEdit, $aRow[0])
    WinSetTitle($hMainGUI, "", "Test: " & $sListItem)
EndFunc   ;==>Select_Template

Run >= once without any change, after tested with the hardcoded line, delete the 2 "just for test lines" and try with real data, this means also delete lines #cs and #ce.

Edited by AutoBert
1 person likes this

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Yeah! That's work! Thanks a lot.

You save me from this:

If StringLen(_GUICtrlRichEdit_GetText($hRichEdit)) > 0 Then
    _GUICtrlRichEdit_SetSel($hRichEdit, 0, -1, True) 
    _GUICtrlRichEdit_ReplaceText($hRichEdit, $aRow[0])   
Else
    _GUICtrlRichEdit_InsertText($hRichEdit, $aRow[0]) 
EndIf

And other nice features of UDF like WM_SIZE.

Edited by kashamalasha

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hi again!

I tested my script using StringStripWS and StringReplace tricks and find out that it works correct only if I don't have empty lines in my multilines text files in DB.

E.g. if I store text like this:

^XA
^FX Test script

^FD Test data
^XZ

my script will return me using

$aRow[0] = StringStripWS( _
                    StringReplace( _
                        StringReplace($aRow[0], "^", @CRLF & "^"), _
                    @CRLF & "^FS", "^FS"), _
           $STR_STRIPLEADING)

text formatted like this:

^XA
^FX Test script
^FD Test data
^XZ

Could you tell me, how can I fix it using the same trick with StringStripWS?

Thanks.

Edited by kashamalasha

Share this post


Link to post
Share on other sites

What format are you looking to have it come back as? Not really sure what you're trying to achieve with this.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Hi! For example, as I post previously, I store a text file in my database in this format:

^XA
^FX Test script

^FD Test data
^XZ

When I am trying to read it to GUICtrlCreateEdit via function GUICtrlSetData, it will be placed like this:

^XA^FX Test script^FD Test data^XZ

The trick with function StringStripWS and StringReplace

$aRow[0] = StringStripWS( _
                    StringReplace( _
                        StringReplace($aRow[0], "^", @CRLF & "^"), _
                    @CRLF & "^FS", "^FS"), _
           $STR_STRIPLEADING)

will convert it to this;

^XA
^FX Test script
^FD Test data
^XZ

As you can see, there is no @CRLF that was there in the source file.

Share this post


Link to post
Share on other sites

Eventually I replaced GUICtrlCreateEdit with _GUICtrlRichEdit_Create.

Thanks all.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • rynow
      By rynow
      romaSQL
      This autoIt UDF is built on the concept of Laravel Query & doctrine.
      RomaSQL provides a new, comfortable and easy to use way for SQL-queries in autoIt.
      Most of the common SQL-queries are supported already and more are coming soon.
      All of your support is much appreciated.
      Connections
      For the connection the object ADODB is used. Therefore the connection string is based on ODBC.
      You can also use OLEDB connection strings or other database connections.
      In order for this to work your add-ons have to be installed in the function: __4ern_SQL_Connection.
      I’d be very glad if you shared your modifications with me.
      Currently supported connections
      -       MySQL (odbc)
      -       Microsoft SQL Server (odbc)
      -       SQLite (odbc)
      -       Microsoft Access (odbc)
      Command reference
      $SQL_connect; establishing connection $SQL_returnType; return a Array or Dictionary ('oDict') Object (Default = Array) $SQL_setDefaultTable; Default Tablename $SQL_setDefaultKey; Default Colmn Key (Default = id) $SQL_debug; if True, show SQL Statment in Console $SQL_get $SQL_update $SQL_delete $SQL_insertInto $SQL_take $SQL_limit $SQL_table $SQL_select $SQL_distinct $SQL_where $SQL_orWhere $SQL_whereBetween $SQL_whereNotBetween $SQL_whereIn $SQL_whereNotIn $SQL_whereNull $SQL_whereNotNull $SQL_having $SQL_orHaving $SQL_havingBetween $SQL_havingNotBetween $SQL_havingIn $SQL_havingNotIn $SQL_havingNull $SQL_havingNotNull $SQL_groupBy $SQL_orderBy  
      Examples
      establishing connection
      ;-----/ ; SQLite Connection ;-----/ $SQL_setDatabase('sqlite') $SQL_connect('C:\project.db') ;-----/ ; Access Connection ; Database, User, Password ;-----/ $SQL_setDatabase('access') $SQL_connect('C:\project.mdb') ;or as Admin $SQL_connect('C:\project.mdb', '4ern', 'root') ;-----/ ; SQLServer Connection ; Database, User, Password, Server, Driver ;-----/ $SQL_setDatabase('sqlserver') $SQL_connect('myDB', '4ern', 'root', 'localhost') ;or with Driver $SQL_connect('myDB', '4ern', 'root', 'localhost', 'SQL Server') ;-----/ ; MySQL Connection ; Database, User, Password, Server, Driver ;-----/ $SQL_setDatabase('mysql') $SQL_connect('myDB', '4ern', 'root', 'localhost') ;or with Driver $SQL_connect('myDB', '4ern', 'root', 'localhost', 'MySQL ODBC 5.2 UNICODE Driver')  
      simple SQL query
      $SQL_table('albums') $aRet = $SQL_get() if IsArray($aRet ) then _ArrayDisplay($aRet ) else ConsoleWrite('Keine Ergebnisse' & @LF) endif  
      Select
      $SQL_table('albums') $SQL_select('id', 'Name', 'Artist', 'Song') ;or pass to an Array Local $aSelect = ['id', 'Name', 'Artist', 'Song'] $SQL_select($aSelect) $aRet = $SQL_get() if IsArray($aRet ) then _ArrayDisplay($aRet ) else ConsoleWrite('Keine Ergebnisse' & @LF) endif where
      $SQL_table('albums') $SQL_select('id', 'Name', 'Artist', 'Song', 'Votes') $SQL_where('Artist', 'adele') $SQL_where('Votes', '>=' ,'9') $SQL_orWhere('Artist', '=' ,'Rag'n'Bone Man') ;or pass to an 2dArray Local $aSelect = [['Artist','adele'],['Votes', '>=' ,'9']] $SQL_where($aSelect) $aRet = $SQL_get() if IsArray($aRet ) then _ArrayDisplay($aRet ) else ConsoleWrite('Keine Ergebnisse' & @LF) endif  
      If you need more examples, then tell me exactly what you need.
      I hope you like my UDF and find some use for it.
      ---
      ->DONWLOAD romaSQL
       
       
    • BisherSH
      By BisherSH
      Good day ,
      I have the code below , and i would like to embed SQLite3.dll to the compiled file 
      Is it possible ? 
      Thanks in advance
      #include <SQLite.au3> #include <SQLite.dll.au3> _SQLite_Startup() If @error Then     MsgBox($MB_SYSTEMMODAL, "SQLite Error", "SQLite3.dll Can't be Loaded!")     Exit -1 EndIf $DB = _SQLite_Open("C:\Temp\Test.db") $Action = "TestAction" $Time = @HOUR&":"&@MIN&":"&@SEC $Date = @YEAR&"-"&@MON&"-"&@MDAY $User = @UserName $Computer = @ComputerName $DC = @LogonServer If @error Then     MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Couldnt open Database")     Exit -1 EndIf _SQLite_Exec($DB,"INSERT INTO QLogs (Action,Date,Time,User,Computer,DC) " & _                               "VALUES ("& _SQLite_FastEscape($Action) & "," & _                                           _SQLite_FastEscape($Date) & "," & _                                           _SQLite_FastEscape($Time) & "," & _                                           _SQLite_FastEscape($User) & "," & _                                           _SQLite_FastEscape($Computer) & "," & _                                           _SQLite_FastEscape($DC) & ");") If @error Then     MsgBox($MB_SYSTEMMODAL, "SQLite Error", "Couldnt insert!")     Exit -1 EndIf _SQLite_Shutdown()
    • supersonic
      By supersonic
      Hello -
      For a SQLite insert statement I'm passing a 2D array through two For/Next loops -  code snippet:
      Local $sInsertInto2 = "" For $i = 0 To $iCount - 1 $sInsertInto2 &= " (" For $j = 0 To UBound($aTmp, 2) - 2 $sInsertInto2 &= "'" & StringReplace($aTmp[$i][$j], "'", "''") & "', " Next $sInsertInto2 &= "'" & StringReplace($aTmp[$i][$j], "'", "''") & "')" & ((($iCount - 1) = $i) ? (";") : ("," & @CRLF)) Next This works great but due to StringReplace() it is very slow. StringReplace() is used to "escape" single quotes (') and it is only required if a single quote actually is present...
      Somewhere on the forum there is a faster example by UEZ but I can't find it...
      Anyone any idea?
    • FrancescoDiMuro
      By FrancescoDiMuro
      Hi guys! How are you? Hope you're fine
      I'm trying to insert a text that contains quotes in a SQLite database, and I don't know how to do.
      I tried with:
      Local $sString = "1P6AV2104'0HA04'0AA0" StringReplace($sString, "'", "''") but I didn't managed to, obtaining this error:
      --> Error:    unrecognized token: "0HA04" How can I manage to solve this problem? Thanks  
    • FrancescoDiMuro
      By FrancescoDiMuro
      Hi guys! How are you? Hope you're fine
      I'm trying to use SQLite for managing some data, and, I would like to display my "retrieved" data, but I'm trying to do a select from 2 table, and seems to not work properly...
      What I'd like to do is retrieve data from 2 tables and display in a listview...
      I tried with:
      Local $aRisultato, $iRighe, $iColonne, $iRVal $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Rockwell, Magazzino_Siemens;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then ;_SQLite_Display2DResult($aRisultato) _ArrayDisplay($aRisultato) EndIf ... but it displays a single record 41 times, and it does this thing for every record in the database...
      What do you need to help me?
      Thanks  

      EDIT:
      Managed with a double If and double query like this:
       
      $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Rockwell;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then Local $aRisultatoRockwell = $aRisultato $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Siemens;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then _ArrayConcatenate($aRisultato, $aRisultatoRockwell) Local $i, $sRiga, $s_LV_Item For $i = 1 To Ubound($aRisultato) - 1 $sRiga = $aRisultato[$i][0] & "|" & _ $aRisultato[$i][1] & "|" & _ $aRisultato[$i][2] & "|" & _ $aRisultato[$i][3] & "|" & _ $aRisultato[$i][4] & "|" & _ $aRisultato[$i][5] & "|" & _ $aRisultato[$i][6] & "|" & _ $aRisultato[$i][7] & "|" & _ $aRisultato[$i][8] & "|" & _ $aRisultato[$i][9] & "|" & _ $aRisultato[$i][10] & "|" & _ $aRisultato[$i][11] $s_LV_Item = GUICtrlCreateListViewItem($sRiga, $lv_Lista) Next And so, the listview is created
      If anyone has another more efficient way, I'm here Thanks guys