Sign in to follow this  
Followers 0
jfcby

Edit Control and String Format Display Text Problem

4 posts in this topic

#1 ·  Posted (edited)

I have a edit control that I need to read text from an ini file and display formatted text. The problem is the edit control does not display the text with new lines (n) and tabs (t).

How can I get the edit control to display the text from an ini file with new lines and tabs?

I've searched through the help file and this forum but I did not find an answer.

Ini File: db.ini

;Database Test Example
[faqq]
q0=Select a question
q1=Question 1?
q2=Question 2?
q3=Question 3?
[faqa]
a0=Select a question above from the drop down.nnEach answer will be displayed here in this area.nnIf there are buttons below this text box then click them because there will be a video or a link for reference with more details.nnIf the answers you are looking for are not found here then go to the Help Tab for more details.
a1=Answer 1.
a2=Answer 2.
a3=Answer 3nnAnswer 3anAnswer 3bt Answer 3ctAnswer 3dnAnswer 3et Answer 3ft Answer 3gnAnswer 3htt Answer 3it Answer 3j

Script:

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <GuiEdit.au3>
#include <WindowsConstants.au3>
$IniLoc = @ScriptDir & "db.ini"
GUICreate("Combo Ini Ex FAQ", 230, 200)
$cbofaq = GUICtrlCreateCombo("", 10, 10, 200, 25) ; create first item
$editfaq = GUICtrlCreateEdit("" & @CRLF, 10, 50, 200, 125, $ES_AUTOVSCROLL + $WS_VSCROLL)
_FaqSetupCombo()
GuiSetState()
While 1
$msg = GUIGetMsg()
Switch $msg
  Case $GUI_EVENT_CLOSE
   ExitLoop
EndSwitch
WEnd
Func _FaqSetupCombo()
;
$irsfq = IniReadSection($IniLoc, "faqq")
$irsfa = IniReadSection($IniLoc, "faqa")
For $iirsfq = 1 To $irsfq [0][0]
  GUICtrlSetData($cbofaq, $irsfq[$iirsfq][1] & "|", IniRead($IniLoc, "faqq", "q0", "NotFound")) ; add other item and set a new default
Next

GUICtrlSetData($editfaq, StringFormat(IniRead($IniLoc, "faqa", "a0", "NotFound")))  ;Does not display text correct
MsgBox(0, "", StringFormat(IniRead($IniLoc, "faqa", "a0", "NotFound"))) ;Displays text correct
EndFunc  ;==>_FaqSetupCombo

Thank you for your help,

jfcby

Edited by jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Share this post


Link to post
Share on other sites



#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <GuiEdit.au3>
#include <WindowsConstants.au3>
#Include <GuiComboBoxEx.au3>

;~ _GUICtrlComboBoxEx_GetCurSel

$IniLoc = @ScriptDir & "db.ini"

Global $irsfq = IniReadSection($IniLoc, "faqq")
Global $irsfa = IniReadSection($IniLoc, "faqa")


Global $hWnd = GUICreate("Combo Ini Ex FAQ", 230, 200)

Global $cbofaq = GUICtrlCreateCombo("", 10, 10, 200, 25) ; create first item
For $i = 1 To $irsfq[0][0]
    GUICtrlSetData(-1, $irsfq[$i][1], $irsfq[1][1])
    $irsfa[$i][1] = StringReplace($irsfa[$i][1], "n", @CRLF)
    $irsfa[$i][1] = StringReplace($irsfa[$i][1], "t", @TAB)
Next

Global $editfaq = GUICtrlCreateEdit("" & @CRLF, 10, 50, 200, 125, $ES_AUTOVSCROLL + $WS_VSCROLL)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $cbofaq
            GUICtrlSetData($editfaq, $irsfa[GUICtrlSendMsg($cbofaq, 0x147, 0, 0) + 1][1])
    EndSwitch
WEnd


Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites

jfcby,

I think this does what you need: :oops:

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <GuiEdit.au3>
#include <WindowsConstants.au3>

; You create these arrays in a function but we need to use them elsewhere so they must be declared as Global
Global $irsfq, $irsfa

$IniLoc = @ScriptDir & "db.ini"

GUICreate("Combo Ini Ex FAQ", 230, 200)
$cbofaq = GUICtrlCreateCombo("", 10, 10, 200, 25) ; create first item
$editfaq = GUICtrlCreateEdit("" & @CRLF, 10, 50, 200, 125, BitOr($ES_AUTOVSCROLL, $WS_VSCROLL))

_FaqSetupCombo()

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $cbofaq
            ; Read the new combo selection
            $sQuestion = GUICtrlRead($cbofaq)
            ; Run through the questions
            For $i = 1 To $irsfq[0][0]
                If $sQuestion = $irsfq[$i][1] Then
                    ; And when we get a match we write the answer
                    GUICtrlSetData($editfaq, $irsfa[$i][1])
                    ; No point in looking any more!
                    ExitLoop
                EndIf
            Next
    EndSwitch
WEnd

Func _FaqSetupCombo()
    ; Read questions
    $irsfq = IniReadSection($IniLoc, "faqq")
    $sCombo_String = ""
    For $iirsfq = 1 To $irsfq[0][0]
        $sCombo_String &= "|" & $irsfq[$iirsfq][1]
    Next
    GUICtrlSetData($cbofaq, $sCombo_String, $irsfq[1][1])
    ; read answers
    $irsfa = IniReadSection($IniLoc, "faqa")
    ; Now loop through the answers and convert n and t
    For $i = 1 To $irsfa[0][0]
        $irsfa[$i][1] = StringReplace($irsfa[$i][1], "n", @CRLF)
        $irsfa[$i][1] = StringReplace($irsfa[$i][1], "t", @TAB)
    Next
    GUICtrlSetData($editfaq, $irsfa[1][1])


EndFunc   ;==>_FaqSetupCombo

Please ask if you have any questions. :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thank you funkey and Melba23 for your help. Your replies solved solved my problem. Thank you.


Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

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
Sign in to follow this  
Followers 0