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

    • Jibberish
      By Jibberish
      I am working on a Video Player Test Script. I am reading a text file into a 3d array to be displayed in a GUI.
      Array Content:
      [x][0]FileName.mp4
      [x][1]UsageCount -> Up to a 4 digit number
      [x][2]EnableUsageCount (True/False)
      In the GUI the user can check the filename box, edit the number of usages and check EnableUsageCount to turn on the UsageCount control using the UsageCount number for the maximum number of plays.
      To make this easier to deal with I have removed the EnableUsageCount section, and am just concentrating on getting a method to put the edited (or unchanged) UsageCount in the array. Currently nothing is read into the array, due to my using the wrong method in the Case statement.
      Here are code snippets of what I am trying to do:
      ; Snippets from script ; I read the text file at the bottom and put the .mp4 filenames in $aManifest[x][0] and UsageCount in $aManifest[x][1] ; Then I create a GUI to display the .mp4 filenames with checkboxes and the UsageCount to the right. UsageCount is editable by the user. ; If the filename is checked, I want to read the filename into $aCheckedVideos[x][0] and the updated UsageCount in $aCheckedVideos[x][1] ; The GUICtrlRead($aVideoName[$i]) with Case $GUI_CHECKED & UNCHECKED works for the checkboxes ; This section puts the filenames in the GUI with a checkbox For $i = 0 to $iMMCount Step 1 $sMP4Text = $aManifest[$i][0] $iMP4Length = StringLen($sMP4Text) $aVideoName[$i] = GUICtrlCreateCheckbox($sMP4Text,$iLeft, $iTop) $iTop += 30 Next ; This section reads numbers from the Manifest array, and I want to be able to change the number and have them saved. ; So the Case $GUI_CHECKED & UNCHECKED won't work here, and I can't figure out what I should be doing here. For $i = 0 to $iMMCount Step 1 $sUsageText = $aManifest[$i][1] $aUsageCount[$i] = GUICtrlCreateInput($sUsageText,$iLeft, $iTop, 50,18, $GUI_DOCKAUTO) GUICtrlSetPos($aUsageCount[$i],200) $iTop += 30 Next While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idCloseGUI For $i = 0 To $iMMNewCount Step 1 Switch GUICtrlRead($aVideoName[$i]) Case $GUI_CHECKED $aCheckedVideos[$i][0] = $aManifest[$i][0] ; If checked, I put the results into a two D array Case $GUI_UNCHECKED ; where Video Name is $aCheckedVideos[x][0] EndSwitch Switch GUICtrlRead($aUsageCounter[$i]) Case $GUI_CHECKED $aCheckedVideos[$i][1] = $aUsageCount[$i] ;I want to put the text (numbers) in $aCheckedVideos[x][1] Case $GUI_UNCHECKED ;but what is returned is blank, probably due to EndSwitch ; $GUI_CHECKED being the wrong thing. Next ExitLoop EndSwitch WEnd ;The txt file I'm reading has the following: ;~ /** Title #1: Big Buck Bunny 1080p **/ ;~ "Name": "Big Buck Bunny", ;~ "URI": "..\\MediaFiles\\bbb_1080_60s.mp4", ;~ "UsageCount": 9999, ;~ "URI": "..\\MediaFiles\\bbb_1080_60s_enc1.mp4", ;~ "UsageCount": 45, ;~ "URI": "..\\MediaFiles\\bbb_1080_60s_enc1.mp4", ;~ "UsageCount": 2, ;~ /** Title #2: Tears of Steel 4K **/ ;~ "Name": "Tears of Steel 4K", ;~ "URI": "..\\MediaFiles\\tos_4K_60s_HEVC.mp4", ;~ "UsageCount": 9876, ;~ "URI": "..\\MediaFiles\\tos_4K_60s_HEVC_enc2.mp4", ;~ "UsageCount": 0, ;~ "URI": "..\\MediaFiles\\tos_4K_60s_HEVC_enc2.mp4", ;~ "UsageCount": 5, I am certain that the section
                          Switch GUICtrlRead($aUsageCounter[$i])
                              Case $GUI_CHECKED
                                  $aCheckedVideos[$i][1] = $aUsageCount[$i]    ;I want to put the text (numbers) in $aCheckedVideos[x][1]
                              Case $GUI_UNCHECKED                                ;but what is returned is blank, probably due to
                          EndSwitch                                            ; $GUI_CHECKED being the wrong thing.

      is wrong, and this is what I am looking for help with. Instead of $GUI_CHECKED what should I be looking for?
      The worst part of this is I had this working late last night, and then lost my changes and cannot for the life of me remember how I had this working.
      Help is truly appreciated!
      Jibberish
       
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening guys
      I am working on a little project, in which I have to retrieve 8000+ rows of data from a table, from a SQLite database, to populate a combobox 
      This is what I tried 'til now, but it still takes about 12 seconds to populate the combobox.
      _SQLite_Exec($objDatabase, "BEGIN TRANSACTION;") If _SQLite_GetTable($objDatabase, "SELECT DISTINCT Comune FROM LISTA_COMUNI;", $arrRisultatoQuery, $intRighe, $intColonne) = $SQLITE_OK Then For $i = 2 To UBound($arrRisultatoQuery) - 1 If $i < UBound($arrRisultatoQuery) - 1 Then GUICtrlSetData($cbo_ComuneNascita, $arrRisultatoQuery[$i] & "|") Else GUICtrlSetData($cbo_ComuneNascita, $arrRisultatoQuery[$i]) EndIf Next _SQLite_Exec($objDatabase, "COMMIT;") Are there any other solution to retrieve 8000+ records from a SQLite database?
      Thank you very much  
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning community!
      I am working on a script which read from a text file ( .txt ) and should import all the content in a SQLite3 DB, in order to execute some queries that should be difficult to execute on a text file.
      So, I was looking for something very very fast, because the file could be very large ( I don't know exaclty how much can became big, but I know a lot of rows, it's a log file ... )
      I found the "Import method", but I don't know If I can implement it in a query ( @jchd, it's your turn!  )
      Do you know some methods that I can implement in my script to have a very very fast import of thousands and thousands rows in a SQLite3 DB?
      Thanks a lot
      Francesco
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning guys
      I was trying to use again SQLite in AutoIt, and I've again an issue: I can't startup SQLite...
      Can you please show me the way to set the enviornment for a SQLIte usage in AutoIt? Step by step, I'll follow your suggestion(s).

      Thanks for everyone will reply!

      Francesco
    • 232showtime
      By 232showtime
      im getting strange output in array display,$split_[1] is not properly aligned to other arrays and why guictrlsetdata is not writting any data if i put comma(,) at the end of the text in $Input1???
       
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #Region ### START Koda GUI section ### Form=C:\Users\user\Desktop\Script\StringSplit.kxf $Form1 = GUICreate("Form1", 623, 449, 192, 114) $Input1 = GUICtrlCreateInput("50UGITQ421X, 50UGITQ422X, 50UGITQ423X, 50UGITQ427X, 50UGITQ431X, 50UGITQ435X, 50UGITQ436X, 50UGITQ437X, 50UGITQ441X, 50UGITQ445X, 50UGITQ449X, 50UGITQ453X, 50UGITQ454X, 50UGITQ455X, 50UGITQ459X", 24, 16, 553, 21) $Split = GUICtrlCreateButton("Split", 24, 48, 75, 25) $List1 = GUICtrlCreateList("", 24, 96, 553, 97) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Split $read = GUICtrlRead($Input1) $split_ = StringSplit($read, ",") $Max = UBound($split_, 1) For $i = 1 To UBound($split_) - 1 ConsoleWrite($split_[$i] & @CRLF) ;~ ControlSetText($Form1, "", $List1, $split_[$i]) GUICtrlSetData($List1, $split_[$i]) ;~ GUICtrlSetData($List1, $split_[$i]) ;~ GUICtrlSetData($List1, $i) Next _ArrayDisplay($split_) EndSwitch WEnd