Sign in to follow this  
Followers 0
roofninja

display file in a gui

5 posts in this topic

I am having trouble getting a file to be displayed. I want the "afile.txt" to be displayed in the GUICtrlCreateList or something like it. All I get is a single line and not the whole file. I tried GUICtrlCreateView, but didn't have much success. I also, do not remember and the online documentation is not much help, but I will need to strip the file of blank lines extra spaces. I am lost.

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#Include <Array.au3>
#include <Misc.au3>
#Include <File.au3>
if _Singleton("Warning",1) = 0 Then
Msgbox(0,"Warning","An occurence of your program is already running")
Exit
EndIf
Opt('MustDeclareVars', 1)
Global $list[20]
If Not _FileReadToArray("afile.txt",$list) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
_ArrayDisplay($list)
Menu()
Func Menu()
    Local $msg, $parts
    GUICreate("list", 500, 150)
GUICtrlCreateList($list[2],5,1,300,130)
GUISetState()
While 1
  $msg = GUIGetMsg()
  Switch $msg
             Case $GUI_EVENT_CLOSE
                 ExitLoop
  EndSwitch
WEnd
GUIDelete()
EndFunc
Exit

afile.txt

Start of words.

  list of lines.
  set of lines.
  part of lines.
  start of lines.
  group of lines.

RUN . . . Slide . . . TAG . . . Your out . . . PAINTBALL !!!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You didn't actually add the array to the ListView. You just created the item and added a default item ($list[2])

You need to add the items with a For statement. Here, this will do the trick.

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#Include <Array.au3>
#include <Misc.au3>
#Include <File.au3>
Opt('MustDeclareVars', 1)
Global $list[20], $listbox, $msg, $parts, $StrippedString

If _Singleton("Warning",1) = 0 Then
Msgbox(0,"Warning","An occurence of your program is already running")
Exit
EndIf
If Not _FileReadToArray("afile.txt",$list) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
_ArrayDisplay($list)
Menu()
Func Menu()
    GUICreate("list", 500, 150)
$listbox = GUICtrlCreateList("",5,1,300,130)
For $i = 0 To $list[0]
$StrippedString = StringStripWS($list[$i], BitOr(1,2))
GUICtrlSetData($listbox, $StrippedString)
Next
GUISetState()
EndFunc
While 1
  $msg = GUIGetMsg()
  Switch $msg
             Case $GUI_EVENT_CLOSE
                 Exit
  EndSwitch
WEnd

Notice the For $i = 0 to $list[0]

This statement says to do a loop of whatever you want until you reach the end of the file.

And this: GUICtrlSetData($listbox, $list[$i])

Tell me to populate the ListView with the array, with the $i in the For loop it will count +1 each time, going through the arrays.

Also, I cleaned it up a little to make it easier to read.

Not 100% sure why you had it first ExitLoop on $GUI_EVENT_CLOSE and then Exit the program, so I moved the While out of the Main() func and set the $Msg and $parts vars to global.

Let me know if you have any questions.

Edited by Damein

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Share this post


Link to post
Share on other sites

Thanks, I will try it out when I get back to a windows box. Arrays have always given me problems. Thanks again.


RUN . . . Slide . . . TAG . . . Your out . . . PAINTBALL !!!

Share this post


Link to post
Share on other sites

Haha, I have problems with Array's too xD

Let me know how it turns out.


MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Share this post


Link to post
Share on other sites

Why don't you just read the wiki page about Arrays?


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

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