Jump to content

Replace text and display in a text box?


Recommended Posts

Im having a little trouble with this. I have one window, which takes in some information, and the output I need is a rather long text document, with information replaced with the inputs to the first window.

I have the windows set up and displayed properly, but I cant quite figure out how to get a text box to display on the entire window.

I am also a little confused on the best way to put in the text document into a string array. I dont know how to best preserver the line spacing and such. Sorry if this was a little tough to understand, but any help would be greatly appreciated.

Link to comment
Share on other sites

Oh, also see _FileReadToArray() to put the file's contents into a string array; I missed the array part on my first read of your post, for some reason my speed reads aren't that meticulous anymore, seems like my mind is distant.

Link to comment
Share on other sites

If you just want to write something in the window you can add:

GUICtrlCreateLabel ( "text", left, top [, width [, height [, style [, exStyle]]]] )

by making a static width and height the text will do an automated linebreak when reaching the end of the labels "frame". Have a window Width: 500px, 400px. Create a label: GUICtrlCreateLabel ("text", 10, 10, 480, 380)

Link to comment
Share on other sites

Thanks for your replies.

I am almost there... it finds what it needs, and replaces them. But from my primary window, it reads a field (in this case a name), but it returns a number...not sure why.

I added a

MsgBox(0, "DEBUG", $input)

which just says 0, or 4...

*EDIT*

Im an idiot, it was because I deleted the GUI before I read in the values ><

Here is my code... sorry for the roughness of it... please forgive me

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

Opt('MustDeclareVars', 1)
Opt("GUIOnEventMode", 1)

Start()
; example 1
Func Start()
    Local $msg

    GUICreate("Welcome Email") ; will create a dialog box that when displayed is centered
    GUISetState(@SW_SHOW) ; will display an empty dialog box
    GUICtrlCreateLabel("Account Name:", 10, 25, 75)
    Global $account = GUICtrlCreateInput("", 10, 45, 150, 20)
    
    Local $YesID = GUICtrlCreateButton("Create", 10, 150, 75, 20)
    GUICtrlSetOnEvent($YesID, "OnYes")
    
    GUICtrlCreateLabel("Email: First.Last", 10, 70, 75)
    Global $email = GUICtrlCreateInput("", 10, 90, 150, 20)
    ; Run the GUI until the dialog is closed
    
    While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
    GUIDelete()
EndFunc   ;==>Example1

Func OnYes()
    GUIDelete()
    Local $input = GUICtrlRead($account)    
    Local $msg
    MsgBox(0, "DEBUG", $input)
    Local $file = FileOpen("welcome.txt", 0)
    Local $chars = FileRead($file)
    ;MsgBox(0, "Debug", $chars)
    Local $chars_rep = StringReplace($chars, "@user", $input)
    GUICreate("Generated Email") ; will create a dialog box that when displayed is centered
    GUISetState(@SW_SHOW) ; will display an empty dialog box
    
    Local $text = GUICtrlCreateEdit($chars_rep & @CRLF, 10, 32, 350, 325, $ES_AUTOVSCROLL + $WS_VSCROLL)

    While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
    GUIDelete()
EndFunc   ;==>Example1
Edited by ICANSEEYOU7687
Link to comment
Share on other sites

Got it working! Thanks!

I got one more little problem, I think, and then I think I have it working the way I want.

I cant close the GUI! lol.

I am doing something really dumb, but I just cant put my finger on it. This last attempt, I tried copying one of the examples in the help file, but when I push the X no the top right of the window nothing happens.

Func Create()
    ;Global $input = GUICtrlRead($username)
    Global $email_r = $firstname &"." & $lastname
    GUIDelete()
        
    Local $msg
    ;MsgBox(0, "DEBUG", $input)
    Local $file = FileOpen("welcome.txt", 0)
    Local $chars = FileRead($file)
    ;MsgBox(0, "Debug", $chars)
    Local $chars_rep = StringReplace($chars, "@user", $username)
    Local $chars_rep2 = StringReplace($chars_rep, "@email", $email_r)
    GUICreate("Generated Email") ; will create a dialog box that when displayed is centered
    GUISetState(@SW_SHOW) ; will display an empty dialog box
    Local $text = GUICtrlCreateEdit($chars_rep2 & @CRLF, 10, 32, 350, 325, $ES_AUTOVSCROLL + $WS_VSCROLL)

    GUISetState()
    While 1
        Select
                   Case $msg = $GUI_EVENT_CLOSE
                   MsgBox(0, "", "Dialog was closed")
           Exit
        EndSelect       
    WEnd
    GUIDelete()
EndFunc   ;==>Example1
Edited by ICANSEEYOU7687
Link to comment
Share on other sites

No need for multiple GUIs, try this :mellow:

#include <GUIConstantsEx.au3>

Global $sMyWelcomeFilePath = "welcome.txt"

;To add another field you only need to modify this array
Global $avUserInfo[4][3] = [["Account Name", "@user", ""],["Email", "@email", ""], _
        ["Password", "@pass", ""],["Nickname", "@nick", ""]]

_Register()

Func _Register()
    Local $nMsg, $Form1 = GUICreate("Demo 1", 250, (UBound($avUserInfo, 1) * 50) + 45)
    Local $Input[UBound($avUserInfo, 1)]
    For $i = 0 To UBound($avUserInfo, 1) - 1
        GUICtrlCreateLabel($avUserInfo[$i][0] & ":", 10, 10 + ($i * 50))
        $Input[$i] = GUICtrlCreateInput("", 10, 30 + ($i * 50), 230, 21)
    Next
    Local $Button1 = GUICtrlCreateButton("Submit", 140, ($i * 50) + 10, 100, 25)
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $Button1
                For $i = 0 To UBound($Input) - 1
                    $avUserInfo[$i][2] = GUICtrlRead($Input[$i])
                Next
                For $i = 0 To $Button1
                    GUICtrlDelete($i)
                Next
                Local $iWNew = 640, $iHNew = 480
                WinMove($Form1, "", (@DesktopWidth - $iWNew) / 2, (@DesktopHeight - $iHNew) / 2, $iWNew, $iHNew)
                Local $aSize = WinGetClientSize($Form1)
                GUICtrlCreateEdit(_GenWelcomeText($avUserInfo, $sMyWelcomeFilePath), 10, 10, $aSize[0] - 20, $aSize[1] - 20)
        EndSwitch
    WEnd
EndFunc   ;==>_Register

Func _GenWelcomeText(ByRef $avArray, $sFilePath)
    Local $sWelcomeText = FileRead($sFilePath)
    For $i = 0 To UBound($avUserInfo, 1) - 1
        $sWelcomeText = StringReplace($sWelcomeText, $avArray[$i][1], $avArray[$i][2])
    Next
    Return $sWelcomeText
EndFunc   ;==>_GenWelcomeText

Hope this helps,

-smartee

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...