Jump to content
Sign in to follow this  
LastSoul

Load text file to listBox

Recommended Posts

LastSoul

hey guys

there is way to load text file to listbox like this in autoit ?

csF88857.gif

:sweating:

Edited by LastSoul

Share this post


Link to post
Share on other sites
Melba23

LastSoul,

Like this? :)

#include <GUIConstantsEx.au3>

; Read file and convert @CRLF to "|"
$sData = "|" & StringReplace(FileRead(@ScriptDir & "\12.txt"), @CRLF, "|")

$hGUI = GUICreate("Test", 500, 500)

$cList = GUICtrlCreateList("", 10, 10, 200, 200)
GUICtrlSetData($cList, $sData)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
M23
  • Like 1

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
LastSoul

Thanks  :huggles:

this was i looking for^^

Edited by LastSoul

Share this post


Link to post
Share on other sites
meows

Thanks  :huggles:

this was i looking for^^

Trying to get through all the misdirection I tried this to get text into a box, I got this box.jpg

The issue I discovered it the text is all misplaced. the top's in the middle and the bottom is at the top.

So I spent two days and got this to actually put text into a box on a page. The issue is it is one and just one VERY long line..

I must say. this is way to time intensive.. just to put text into a box other than Notepad.. It is just i really needed this in a box. but am going to fall back to Open Office and make a PDF and use that in the program,. I've actually got good at that,

Many thanks though, Melba23 at least I kinda understood that was going on,,

#include <GUIConstantsEx.au3>
Global $FO_READ
 Local Const $sFilePath = @ScriptDir & "\Command Interface.txt"
 Local $hFileOpen = FileOpen($sFilePath, $FO_READ)


; Read file and convert @CRLF to "|"
;$sData = "|" & StringReplace(FileRead(@ScriptDir & "\Command Interface.txt"), @CRLF, "|")

 Local $sFileRead = FileRead($hFileOpen)
$sData = $sFileRead
;$sData = -1 FileRead  & @ScriptDir & "\Command Interface.txt"
$hGUI = GUICreate("Test", 500, 500)

$cList = GUICtrlCreateList("", 10, 10, 450, 450)
GUICtrlSetData($cList, $sData)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites
kylomas

meows,

Or just use an edit control like...

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

local $str = 'This is one honk''in ass long line.  The purpose of this honk''in ass long line is to demonstrate that a honk''in ass long line can be used.'

local $gui010 = guicreate('',200,200)
; $es_multiline causes automatic wrapping and $es_readonly prevents editing
local $edt010 = guictrlcreateedit('',0,20,200,150, bitor($es_readonly,$es_multiline))
guictrlsetdata($edt010,$str)
guisetstate()

; deselect text in edit control
_GUICtrlEdit_SetSel ($edt010, -1, 0)

while 1
    switch guigetmsg()
        case $gui_event_close
            Exit
    EndSwitch
WEnd

kylomas

edit: Can you post the file you are loading????  I suspect that your EOL's are not CRLF.

edit2: BTW, your code is NOT what M23 posted...you are not replacing the EOL's...also $sfileread and $sdata contain the same thing

This is how your script might have been coded...

#include <GUIConstantsEx.au3>
#include <FileConstants.au3>

;Global $FO_READ                            ; this is declared in FileConstants.au3...declaring it here without assigning a value is meaningless

Local Const $sFilePath = @ScriptDir & "\Command Interface.txt"
Local $hFileOpen = FileOpen($sFilePath, $FO_READ)

; the only real reason to use a file handle is to check if the open was sucessful
if $sFilePath = -1 Then
    msgbox(0,'Open Error','File failed to open' & @CRLF & 'File = ' & $sFilePath)
    Exit
endif

; Read file and convert @CRLF to "|"
;$sData = "|" & StringReplace(FileRead(@ScriptDir & "\Command Interface.txt"), @CRLF, "|")

;Local $sFileRead = FileRead($hFileOpen)    ; this is redundant to the next statement
$sData = fileread($hFileOpen)

; if you are going to use a file handle than you should close the handle when you are done with it
fileclose($hFileOpen)

; convert EOL's to delimiter for GuiCtrlSetData()
$sdata = stringreplace($sdata,@CRLF,'|')    ;   assuming that CRLF is EOL

$hGUI = GUICreate("Test", 500, 500)

$cList = GUICtrlCreateList("", 10, 10, 450, 450)
GUICtrlSetData($cList, $sData)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
meows

 

meows,

Or just use an edit control like...

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

local $str = 'This is one honk''in ass long line.  The purpose of this honk''in ass long line is to demonstrate that a honk''in ass long line can be used.'

local $gui010 = guicreate('',200,200)
; $es_multiline causes automatic wrapping and $es_readonly prevents editing
local $edt010 = guictrlcreateedit('',0,20,200,150, bitor($es_readonly,$es_multiline))
guictrlsetdata($edt010,$str)
guisetstate()

; deselect text in edit control
_GUICtrlEdit_SetSel ($edt010, -1, 0)

while 1
    switch guigetmsg()
        case $gui_event_close
            Exit
    EndSwitch
WEnd

kylomas

edit: Can you post the file you are loading????  I suspect that your EOL's are not CRLF.

edit2: BTW, your code is NOT what M23 posted...you are not replacing the EOL's...also $sfileread and $sdata contain the same thing

This is how your script might have been coded...

#include <GUIConstantsEx.au3>
#include <FileConstants.au3>

;Global $FO_READ                            ; this is declared in FileConstants.au3...declaring it here without assigning a value is meaningless

Local Const $sFilePath = @ScriptDir & "\Command Interface.txt"
Local $hFileOpen = FileOpen($sFilePath, $FO_READ)

; the only real reason to use a file handle is to check if the open was sucessful
if $sFilePath = -1 Then
    msgbox(0,'Open Error','File failed to open' & @CRLF & 'File = ' & $sFilePath)
    Exit
endif

; Read file and convert @CRLF to "|"
;$sData = "|" & StringReplace(FileRead(@ScriptDir & "\Command Interface.txt"), @CRLF, "|")

;Local $sFileRead = FileRead($hFileOpen)    ; this is redundant to the next statement
$sData = fileread($hFileOpen)

; if you are going to use a file handle than you should close the handle when you are done with it
fileclose($hFileOpen)

; convert EOL's to delimiter for GuiCtrlSetData()
$sdata = stringreplace($sdata,@CRLF,'|')    ;   assuming that CRLF is EOL

$hGUI = GUICreate("Test", 500, 500)

$cList = GUICtrlCreateList("", 10, 10, 450, 450)
GUICtrlSetData($cList, $sData)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Oh yes I used a edit something,,

GUICtrlSetTip($TITLE, "The title of the message box.")
GUICtrlCreateLabel("Text", 10, 50, 30, 4)
$TEXT = GUICtrlCreateEdit("", 10, 65, 420, 100, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_BORDER), BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
GUICtrlSetData($TEXT, StringFormat("Command Interface\r\nHere you can edit almost everything. We left out editing the Users Start date \r\nfor the next 500 words")
GUICtrlSetTip($TEXT, "How to use the Command Interface")
;$aTEXT = @ScriptDir & "/Command Interface.txt"
;GUICtrlSetData($TEXT, StringFormat)
;GUICtrlCreateEdit $sText ("", 10, 65, 420, 100, BitOr($ES_READONLY, $WS_VSCROLL, $ES_AUTOVSCROLL))

and it worked! however I forgot and could not find how many words you can use in this and I have 2130 to enter. And it seemed stupid to have to chase ScIte across the screen so I started looking for another way.

Then things got ugly.. I do not now how to use StringFormat ( just a lucky guess it worked at all)

It is supposed to look like mess2.jpg

And NOT like

mess1.jpg

And I put that together not testing a standard PDF only to discover without using FOX you can't use PDF. so it looks like

I need to use AutoitHotkey to do some things and Autoit to do others being all the IE goodies are linked to deadends.

And I thought i would just make notepad a small pop up. but I could not google any answers on how to control it's size.

All for the want to put some ANSI text into a stupid box.

I do have one last trick up my sleeve. a simple browser.  I was researching adding the File Association for it when I came across your posts. That is not what I wanted but thats the way it is.. 30 years and not one of us can get even the what should be simple right,

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  

×