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

    • kitoy
      Previous data is removed after using GUICtrlSetData
      By kitoy
      I wanted to make a countdown timer without queueing the countdown message to the next line but the previous data is removed after using GUICtrlSetData. Any thoughts on how to display the previous data/message?

      Here is an example:
      #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $_main = GUICreate("", 501, 313, -1, -1) Global $g_idMemo = GUICtrlCreateEdit("", 2, 2, 496, 274, $ES_AUTOVSCROLL + $ES_READONLY + $WS_VSCROLL) GUICtrlSetData(-1, "") GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New") GUICtrlSendMsg($g_idMemo, $EM_SETREADONLY, True, 0) GUICtrlSetBkColor($g_idMemo, 0xFFFFFF) GUICtrlSetCursor($g_idMemo, -1) GUISetState(@SW_SHOW) HotKeySet('{esc}', "_close") Func _close() Exit EndFunc ;==>_close Func MemoWrite($sMessage = "") GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite MemoWrite("test message 1") Sleep(1000) MemoWrite("test message 2") Sleep(1000) MemoWrite("test message 3") Sleep(1000) For $i = 5 to 0 Step -1 GUICtrlSetData($g_idMemo, "Program will exit in "&$i&" seconds...") Sleep(1000) Next While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd  
    • Blank517
      _SQLite_FetchData problem
      By Blank517
      Hi, when a client sends /logout to the server i want that the server find the id of the client and set his online status to 0
      Using 'default' I have no problems, but when I do this with 'blank517' gives me id 10 and then for the database remains online
      Database while Blank517 logout:
      id  |  username  |  password |   permissions  |  online  |
      0   |  default        |    pass1      |           0             |      0       |
      1   |  Blank517    |     pass       |           0              |     1       |
      Server recv:
      Func _Recv_From_Sockets_() For $0 = 1 To $max_connections $Recv = TCPRecv ($Socket_Data[$0][0],1024) If StringLeft($Recv, 1) = "/" Then If StringInStr($Recv, "logout") Then _SQLite_Query(-1, "SELECT id FROM Users WHERE username = '" & $Socket_Data[$0][1] & "' AND online = '1';", $hQuery) While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK $sMsg &= $aRow[0]; <-- $sMsg = 10 after FetchData WEnd _SQLite_Exec(-1, "UPDATE Users SET online = '0' WHERE id = '" & $sMsg & "';") For $000 = 1 To $max_connections TCPSend($Socket_Data[$000][0], $Socket_Data[$0][1] & " ha effettuato il logout") Next TCPCloseSocket($Socket_Data[$0][0]) $sMsg = Null EndIf Else _Broadcast_To_Sockets_ ($Recv) EndIf Next EndFunc *excuse me for my bad english *
    • Blank517
      SQLite login
      By Blank517
      Hi, I would like to make a login script with SQLite. The database looks like this:
      _SQLite_Exec(-1, "CREATE TABLE Users (id INT(8) NOT NULL, username VARCHAR(30) NOT NULL, password VARCHAR(255) NOT NULL, permission INT(8) NOT NULL, PRIMARY KEY (id)); CREATE UNIQUE INDEX 'user_name_unique' ON 'Users' ('username' );") _SQLite_Exec(-1, "INSERT INTO Users(id, username, password, permission) VALUES ('0', 'default', 'password', '0');")
      theoretically I should make a query in this way, right?
      _SQLite_Query (-1, "SELECT id FROM Users WHERE username = '" & $ Recv [1] & "' AND password = '" & $ Recv [2] & "';", $ hQuery)
      but then I do not know how to know if you have found the 'id'
    • Skysnake
      SQLite Open Read Only
      By Skysnake
      My SQLite.au3 include contains this entry on line 43
      Global Const $SQLITE_READONLY = 8 ; /* Attempt to write a readonly database */ But, is not in the Help file.  The right page, I think is _SQLite_Open.htm, and does not contain a reference to opening a SQLite db as ReadOnly.  Should this be added to the Help File?
       
      BUT, what I really want to know is this: What is the best way to determine whether a SQLite db should be opened as ReadOnly?
      I have WAL files active.  Can I check for WAL and if exists, force open ReadOnly?  ie, if a user is already logged on, simply for other users to Read Only?
      Is this the right question to ask?
       
       
    • Simpel
      howto: colored layer over updating EDIT control
      By Simpel
      Hi,
      I'm trying to create a console reader. All is working but I have a problem with the look. I want the line numbers with another backgroundcolor in silver. I made this with a small silver label. The edit control over the label has a transparent background.
      But if I start the prog then i can see how the line numbers wipe the silver background off. And if I click into the Edit then the silver label disappears completely.
      #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <ColorConstants.au3> #include <StaticConstants.au3> #include <GuiEdit.au3> Opt("GUIOnEventMode", 1) Global $g_iZaehler = 0 Global $g_hGUI = GUICreate("Console: StdoutRead" , 800, 800, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_CLIPCHILDREN, $WS_EX_ACCEPTFILES) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") Global $text = GUICtrlCreateEdit("",10,30,780,760, $ES_AUTOVSCROLL + $WS_VSCROLL + $ES_READONLY + $ES_NOHIDESEL) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlSetFont(-1, 9, -1, -1, "Lucida Console") GUICtrlSetResizing(-1, $GUI_DOCKBORDERS) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Global $g_LaZeilen = GUICtrlCreateLabel("Zeilen: " & StringFormat("% 5d", $g_iZaehler), 680, 10, 100, 9, $SS_LEFTNOWORDWRAP) GUICtrlSetFont(-1, 9, -1, -1, "Lucida Console") GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKSIZE) Global $g_hCbFreeze = GUICtrlCreateCheckbox("&Freeze", 13, 5, 90) GUICtrlSetFont(-1, 9, -1, -1, "Lucida Console") GUICtrlSetResizing(-1, $GUI_DOCKALL) GUICtrlCreateLabel("", 11, 31, 42, 758) ; soll die Ziffern andersfarbig hinterlegen GUICtrlSetBkColor(-1, $COLOR_SILVER) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH) GUISetState(@SW_SHOW) Global $sText = StringFormat("% 5d", $g_iZaehler) & @CRLF _GUICtrlEdit_AppendText($text, $sText) While 1 Sleep(200) $g_iZaehler += 1 $sText = StringFormat("% 5d", $g_iZaehler) & @CRLF _GUICtrlEdit_AppendText($text, $sText) WEnd Func _Exit() Exit EndFunc Do you have any suggestions.
      Regards, Conrad