Jump to content
Sign in to follow this  
TheNorwegianUser

@crlf in list

Recommended Posts

TheNorwegianUser

Why does only the first @crlf come in the list?

#include <WindowsConstants.au3>
#include <guiconstants.au3>

$GUI=GUICreate("", 200, 200)
$list1=GUICtrlCreateList("", 5, 5, 190, 190, BitOR($WS_BORDER, $WS_VSCROLL))
GUISetState()
GUICtrlSetData($list1, "Justsomerandomdata")
GUICtrlSetData($list1, @CRLF)
GUICtrlSetData($list1, "Moredansomness")
GUICtrlSetData($list1, @CRLF)
GUICtrlSetData($list1, "okaythatsit")

WHile 1
$msg=GUIGetMsg()
If $msg=$GUI_EVENT_CLOSE then ExitLoop
WEnd

Share this post


Link to post
Share on other sites
Melba23

TheNorwegianUser,

Setting a second instance of an existing item in a list merely highlights the existing item - from the Help file for GUICtrlSetData:

"For Combo or List control :

If the "data" corresponds to an already existing entry it is set as the default"

You need to put the various items in a string separated by the delimiter (|) and then enter them as one - then they will all be entered as separate lines:

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

$GUI = GUICreate("", 200, 200)
$list1 = GUICtrlCreateList("", 5, 5, 190, 190, BitOR($WS_BORDER, $WS_VSCROLL))
GUISetState()

GUICtrlSetData($list1, "Justsomerandomdata|" & @CRLF & "|Moredansomness|" & @CRLF & "|okaythatsit")

While 1
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
WEnd

All clear? :)

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
TheSaint

Because you are just sending the same data again.

Using that method of adding data to a GUI List, it needs to be unique to appear as an entry.

Check your Help file for other ways to add entries to a List or ListBox.

It is unusual, to say the least, to add what amounts to a blank line, in a GUI List.

Maybe you should be using an Edit control?

EDIT

Or do as Melba23 (who just beat me with a reply) says.

There are alternatives to using GUICtrlSetData though ... haven't got AutoIt handy, but I believe it is something like GUICtrlList_AddText or somesuch, which doesn't have the same limitation - allows you to have more than one entry called the same.

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
TheNorwegianUser

TheNorwegianUser,

Setting a second instance of an existing item in a list merely highlights the existing item - from the Help file for GUICtrlSetData:

"For Combo or List control :

If the "data" corresponds to an already existing entry it is set as the default"

You need to put the various items in a string separated by the delimiter (|) and then enter them as one - then they will all be entered as separate lines:

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

$GUI = GUICreate("", 200, 200)
$list1 = GUICtrlCreateList("", 5, 5, 190, 190, BitOR($WS_BORDER, $WS_VSCROLL))
GUISetState()

GUICtrlSetData($list1, "Justsomerandomdata|" & @CRLF & "|Moredansomness|" & @CRLF & "|okaythatsit")

While 1
If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
WEnd

All clear? :)

M23

It's a bit harder to add it in the real script. Check the function UpdateInfo(), that's where it is.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=C:\Users\Elias\Documents\Autoit\Food.ico
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****


#include <APIConstants.au3>
#include <GUIConstantsEx.au3>
#include <guiconstants.au3>
#Include <_FileListToArray.au3>
#include <WindowsConstants.au3>
#include <DateTimeConstants.au3>
#include <GuiListBox.au3>

LagDirs()
$Error=False
$ListActive=1
local $AllFiles, $OldName, $Chosen

GUICreate("Food Planner", 500, 525, -1, -1, $WS_SIZEBOX + $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX)
GUISetBkColor(0xCCFFFF)


$New_Maaltid=GUICtrlCreateButton("New Meal", 5, 5, 120, 50)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 14, 0, 0, "Comic Sans MS")
GUICtrlSetBkColor(-1, 0xCCCCFF)
GUICtrlSetResizing(-1, 1)

$Show_Maaltid=GUICtrlCreateButton("Show Meals", 5, 60, 120, 50)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 14, 0, 0, "Comic Sans MS")
GUICtrlSetBkColor(-1, 0xCCCCFF)
GUICtrlSetResizing(-1, 1)

$Plan=GUICtrlCreateButton("Plan", 5, 115, 120, 50)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 14, 0, 0, "Comic Sans MS")
GUICtrlSetBkColor(-1, 0xCCCCFF)
GUICtrlSetResizing(-1, 1)

#region Plan
$Cancel_Save_Plan=GUICtrlCreateButton("Cancel", 200, 50, 200, 35)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 13, 0, 0, "Comic Sans MS")
GUICtrlSetBkColor(-1, 0xCCCCFF)
GUICtrlSetResizing(-1, 1)

$Save_Plan=GUICtrlCreateButton("Save", 200, 90, 200, 35)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 13, 0, 0, "Comic Sans MS")
GUICtrlSetBkColor(-1, 0xCCCCFF)
GUICtrlSetResizing(-1, 1)

$date=GUICtrlCreateDate("", 200, 140, 200, 30, $DTS_SHORTDATEFORMAT)
GUICtrlSetResizing(-1, 1)

$List_Breakfast=GUICtrlCreateList("", 8, 200, 117, 300)
GUICtrlSetResizing(-1, 1)

$List_Lunch=GUICtrlCreateList("", 130, 200, 117, 300)
GUICtrlSetResizing(-1, 1)

$List_Dinner=GUICtrlCreateList("", 252, 200, 117, 300)
GUICtrlSetResizing(-1, 1)

$List_Supper=GUICtrlCreateList("", 374, 200, 117, 300)
GUICtrlSetResizing(-1, 1)

$Label_Breakfast=GUICtrlCreateLabel("Breakfast", 8, 180, 200, 20)
GUICtrlSetFont(-1, 11, 0, 0, "Comic Sans MS")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetResizing(-1, 1)

$Label_Lunch=GUICtrlCreateLabel("Lunch", 130, 180, 200, 20)
GUICtrlSetFont(-1, 11, 0, 0, "Comic Sans MS")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetResizing(-1, 1)

$Label_Dinner=GUICtrlCreateLabel("Dinner", 252, 180, 200, 20)
GUICtrlSetFont(-1, 11, 0, 0, "Comic Sans MS")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetResizing(-1, 1)

$Label_Supper=GUICtrlCreateLabel("Supper", 374, 180, 200, 20)
GUICtrlSetFont(-1, 11, 0, 0, "Comic Sans MS")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetResizing(-1, 1)

$Edit_Plan=GUICtrlCreateButton("Edit Plan", 200, 5, 200, 40)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 13, 0, 0, "Comic Sans MS")
GUICtrlSetBkColor(-1, 0xCCCCFF)
GUICtrlSetResizing(-1, 1)
#endregion Plan

#region Edit
$Cancel_Edit=GUICtrlCreateButton("Cancel", 5, 400, 150, 40)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 11, 0, 0, "Comic Sans MS")
GUICtrlSetBkColor(-1, 0xCCCCFF)
GUICtrlSetResizing(-1, 1)

$Save_Edit=GUICtrlCreateButton("Save", 5, 450, 150, 40)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 11, 0, 0, "Comic Sans MS")
GUICtrlSetBkColor(-1, 0xCCCCFF)
GUICtrlSetResizing(-1, 1)
#endregion Edit

#region Info
$Label_Name=GUICtrlCreateLabel("", 5, 330, 490, 30)
GUICtrlSetFont(-1, 14, 0, 0, "Comic Sans MS")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetResizing(-1, 1)

$Label_ingredients=GUICtrlCreateLabel("Ingredients", 5, 350, 120, 30)
GUICtrlSetFont(-1, 14, 0, 0, "Comic Sans MS")
GUICtrlSetResizing(-1, 1)

$list2=GUICtrlCreateList("", 5, 380, 200, 120, BitOR($WS_BORDER, $WS_VSCROLL))
GUICtrlSetResizing(-1, 1)

$list3=GUICtrlCreateList("", 250, 380, 200, 120, BitOR($WS_BORDER, $WS_VSCROLL))
GUICtrlSetResizing(-1, 1)

$Label_Recipe=GUICtrlCreateLabel("Recipe", 250, 350, 145, 30)
GUICtrlSetResizing(-1, 1)
GUICtrlSetFont(-1, 14, 0, 0, "Comic Sans MS")
#endregion Info

#region List
$Label_List=GUICtrlCreateLabel("____________________________________________________________________________________", 0, 170, 200, 20)
GUICtrlSetResizing(-1, 1)
$list1=GUICtrlCreateList("", 140, 25, 355, 310)
GUICtrlSetResizing(-1, 1)
AddItemsToList()

$Delete_Maaltid=GUICtrlCreateButton("Delete", 5, 230, 120,  30)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 14, 0, 0, "Comic Sans MS")
GUICtrlSetBkColor(-1, 0xCCCCFF)
GUICtrlSetResizing(-1, 1)

$Hide_Maaltid=GUICtrlCreateButton("Hide", 5, 300, 120,  30)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 14, 0, 0, "Comic Sans MS")
GUICtrlSetBkColor(-1, 0xCCCCFF)
GUICtrlSetResizing(-1, 1)

$Edit_Maaltid=GUICtrlCreateButton("Edit", 5, 265, 120,  30)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 14, 0, 0, "Comic Sans MS")
GUICtrlSetBkColor(-1, 0xCCCCFF)
GUICtrlSetResizing(-1, 1)

$Get_Random=GUICtrlCreateButton("Get Random", 5, 195, 120,  30)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 14, 0, 0, "Comic Sans MS")
GUICtrlSetBkColor(-1, 0xCCCCFF)
GUICtrlSetResizing(-1, 1)

$Radio_Breakfast=GUICtrlCreateRadio("Breakfast", 140, 5, 70, 20)
GUICtrlSetResizing(-1, 1)
$Radio_Lunch=GUICtrlCreateRadio("Lunch", 210, 5, 70, 20)
GUICtrlSetResizing(-1, 1)
$Radio_Dinner=GUICtrlCreateRadio("Dinner", 280, 5, 70, 20)
GUICtrlSetResizing(-1, 1)
$Radio_Supper=GUICtrlCreateRadio("Supper", 350, 5, 70, 20)
GUICtrlSetResizing(-1, 1)
GUICtrlSetState($Radio_Breakfast, $GUI_CHECKED)
#endregion List

#Region New Meal
$Label_New_Maaltid=GUICtrlCreateLabel("__________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________", 0, 330, 510, 20)
GUICtrlSetResizing(-1, 1)
$KindOfMeal=GUICtrlCreateCombo("Breakfast", 5, 400, 150, 50)
GUICtrlSetFont(-1, 11, 0, 2, "Comic Sans MS")
GUICtrlSetData(-1, "Lunch|Dinner|Supper|")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetResizing(-1, 1)

$Maaltidets_Name=GUICtrlCreateInput("", 5, 370, 150, 20)
$Maaltidets_Name_Label=GUICtrlCreateLabel("Meal Name", 5, 350, 150, 15)
GUICtrlSetFont(-1, 11, 0, 0, "Comic Sans MS")
GUICtrlSetResizing(-1, 1)

$ingredients=GUICtrlCreateEdit("", 170, 370, 155, 120)
GUICtrlSetColor(-1, 0x0000FF)
$ingredients_Label=GUICtrlCreateLabel("Ingredients", 170, 350, 155, 20)
GUICtrlSetFont(-1, 11, 0, 0, "Comic Sans MS")
GUICtrlSetResizing(-1, 1)

$Andre_Recipe=GUICtrlCreateEdit("", 340, 370, 155, 120)
GUICtrlSetColor(-1, 0x0000FF)
$Andre_Recipe_Label=GUICtrlCreateLabel("Recipe", 340, 350, 155, 20)
GUICtrlSetFont(-1, 11, 0, 0, "Comic Sans MS")
GUICtrlSetResizing(-1, 1)

$Legg_Til=GUICtrlCreateButton("Add", 5, 435, 150, 25)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 11, 0, 0, "Comic Sans MS")
GUICtrlSetBkColor(-1, 0xCCCCFF)
GUICtrlSetResizing(-1, 1)

$Cancel_New_Maaltid=GUICtrlCreateButton("Cancel", 5, 465, 150, 25)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 11, 0, 0, "Comic Sans MS")
GUICtrlSetBkColor(-1, 0xCCCCFF)
GUICtrlSetResizing(-1, 1)
#endregion New Meal

HideNewMaaltid()
HideList()
HideInfo()
HideEdit()
HideViewPlan()
HidePlan()
HideEditPlan()
GUISetState()

While 1
$msg=GUIGetMsg()
switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $Cancel_Save_Plan()
GetPlan()
HideEditPlan()
Case $Save_Plan
SavePlanUpdate()
GetPlan()
HideEditPlan()
Case $date()
GetPlan()
Case $Edit_Plan
ShowEditPlan()
EditPlanUpdate()
Case $Plan()
HideEditPlan()
HideList()
HideInfo()
HideNewMaaltid()
HideEdit()
GetPlan()
ShowViewPlan()
ShowPlan()
Case $Cancel_Edit()
HideEdit()
Case $Edit_Maaltid()
HideEditPlan()
HidePlan()
HideViewPlan()
HideNewMaaltid()
HideInfo()
ShowEdit()
ReadToEdit()
Case $Save_Edit
EditList1()
Case $Delete_Maaltid()
DeleteMaaltid()
Case $Hide_Maaltid
HideList()
Case $Show_Maaltid
HideEditPlan()
HidePlan()
HideViewPlan()
ShowList()
Case $New_Maaltid
HideEditPlan()
HidePlan()
HideViewPlan()
HideInfo()
HideEdit()
ShowNewMaaltid()
Case $Cancel_New_Maaltid
HideNewMaaltid()
Case $Legg_Til
LeggTilNewMaaltid()
Case $list1
HideEditPlan()
HidePlan()
HideViewPlan()
HideNewMaaltid()
HideEdit()
ShowInfo()
UpdateInfo()
Case $Get_Random
GetRandomMeal()
Case $Radio_Breakfast
$ListActive=1
AddItemsToList()
Case $Radio_Lunch
$ListActive=2
AddItemsToList()
Case $Radio_Dinner
$ListActive=3
AddItemsToList()
Case $Radio_Supper
$ListActive=4
AddItemsToList()
EndSwitch
WEnd

Func GetRandomMeal()
If $ListActive=1 Then $Dir=@ScriptDir & "\Food Planner Data\Breakfast\"
If $ListActive=2 Then $Dir=@ScriptDir & "\Food Planner Data\Lunch\"
If $ListActive=3 Then $Dir=@ScriptDir & "\Food Planner Data\Dinner\"
If $ListActive=4 Then $Dir=@ScriptDir & "\Food Planner Data\Supper\"
$Files=_Filelisttoarrayex($Dir)
If $Files<>0 Then
$count=0
For $1=1 to $Files[0]
If StringInStr($Files[$1], "Name") Then $count+=1
Next
$Random=Random(0, $count, 1)
_GUICtrlListBox_ClickItem($list1, $Random)
ShowInfo()
EndIf
EndFunc

Func GetPlan()
GUICtrlSetData($List_Breakfast, "")
GUICtrlSetData($List_Lunch, "")
GUICtrlSetData($List_Dinner, "")
GUICtrlSetData($List_Supper, "")
$Dir=@ScriptDir & "\Food Planner Data\Plandata\" & GUICtrlRead($date)
If FileExists($Dir & "\Breakfast.txt") Then GUICtrlSetData($List_Breakfast, FileRead($Dir & "\Breakfast.txt"))
If FileExists($Dir & "\Lunch.txt") Then GUICtrlSetData($List_Lunch, FileRead($Dir & "\Lunch.txt"))
If FileExists($Dir & "\Dinner.txt") Then GUICtrlSetData($List_Dinner, FileRead($Dir & "\Dinner.txt"))
If FileExists($Dir & "\Supper.txt") Then GUICtrlSetData($List_Supper, FileRead($Dir & "\Supper.txt"))
EndFunc

Func SavePlanUpdate()
$Dir=@ScriptDir & "\Food Planner Data\Plandata\" & GUICtrlRead($date) & "\"
If FileExists($Dir) Then DirRemove($Dir, 1)
DirCreate($Dir)
If GUICtrlRead($List_Breakfast)<>"" then FileWrite($Dir & "\Breakfast.txt", GUICtrlRead($List_Breakfast))
If GUICtrlRead($List_Lunch)<>"" then FileWrite($Dir & "\Lunch.txt", GUICtrlRead($List_Lunch))
If GUICtrlRead($List_Dinner)<>"" then FileWrite($Dir & "\Dinner.txt", GUICtrlRead($List_Dinner))
If GUICtrlRead($List_Supper)<>"" then FileWrite($Dir & "\Supper.txt", GUICtrlRead($List_Supper))
EndFunc

Func EditPlanUpdate()
GUICtrlSetData($List_Breakfast, "")
GUICtrlSetData($List_Lunch, "")
GUICtrlSetData($List_Dinner, "")
GUICtrlSetData($List_Supper, "")
$Dir=@ScriptDir & "\Food Planner Data\Breakfast\"
$Files=_Filelisttoarrayex($Dir)
If $Files<>0 Then
For $1=1 to $Files[0]
If StringInStr($Files[$1], "Name") Then
$ReadFile=FileRead($Files[$1])
GUICtrlSetData($List_Breakfast, $ReadFile)
EndIf
Next
EndIf
$Dir=@ScriptDir & "\Food Planner Data\Lunch\"
$Files=_Filelisttoarrayex($Dir)
If $Files<>0 Then
For $1=1 to $Files[0]
If StringInStr($Files[$1], "Name") Then
$ReadFile=FileRead($Files[$1])
GUICtrlSetData($List_Lunch, $ReadFile)
EndIf
Next
EndIf
$Dir=@ScriptDir & "\Food Planner Data\Dinner\"
$Files=_Filelisttoarrayex($Dir)
If $Files<>0 Then
For $1=1 to $Files[0]
If StringInStr($Files[$1], "Name") Then
$ReadFile=FileRead($Files[$1])
GUICtrlSetData($List_Dinner, $ReadFile)
EndIf
Next
EndIf
$Dir=@ScriptDir & "\Food Planner Data\Supper\"
$Files=_Filelisttoarrayex($Dir)
If $Files<>0 Then
For $1=1 to $Files[0]
If StringInStr($Files[$1], "Name") Then
$ReadFile=FileRead($Files[$1])
GUICtrlSetData($List_Supper, $ReadFile)
EndIf
Next
EndIf
EndFunc

Func HideEditPlan()
GUICtrlSetState($Save_Plan, $GUI_HIDE)
GUICtrlSetState($Cancel_Save_Plan, $GUI_HIDE)
EndFunc

Func ShowEditPlan()
GUICtrlSetState($Save_Plan, $GUI_SHOW)
GUICtrlSetState($Cancel_Save_Plan, $GUI_SHOW)
EndFunc

Func HidePlan()
GUICtrlSetState($date, $GUI_HIDE)
GUICtrlSetState($Edit_Plan, $GUI_HIDE)
GUICtrlSetState($Label_Breakfast, $GUI_HIDE)
GUICtrlSetState($Label_Lunch, $GUI_HIDE)
GUICtrlSetState($Label_Dinner, $GUI_HIDE)
GUICtrlSetState($Label_Supper, $GUI_HIDE)
EndFunc

Func ShowPlan()
GUICtrlSetState($date, $GUI_SHOW)
GUICtrlSetState($Edit_Plan, $GUI_SHOW)
GUICtrlSetState($Label_Breakfast, $GUI_SHOW)
GUICtrlSetState($Label_Lunch, $GUI_SHOW)
GUICtrlSetState($Label_Dinner, $GUI_SHOW)
GUICtrlSetState($Label_Supper, $GUI_SHOW)
EndFunc

Func HideViewPlan()
GUICtrlSetData($List_Breakfast, "")
GUICtrlSetData($List_Lunch, "")
GUICtrlSetData($List_Dinner, "")
GUICtrlSetData($List_Supper, "")
GUICtrlSetState($List_Breakfast, $GUI_HIDE)
GUICtrlSetState($List_Lunch, $GUI_HIDE)
GUICtrlSetState($List_Dinner, $GUI_HIDE)
GUICtrlSetState($List_Supper, $GUI_HIDE)
EndFunc

Func ShowViewPlan()
GUICtrlSetState($List_Breakfast, $GUI_SHOW)
GUICtrlSetState($List_Lunch, $GUI_SHOW)
GUICtrlSetState($List_Dinner, $GUI_SHOW)
GUICtrlSetState($List_Supper, $GUI_SHOW)
EndFunc

Func ReadToEdit()
If $ListActive=1 Then $Dir=@ScriptDir & "\Food Planner Data\Breakfast\"
If $ListActive=2 Then $Dir=@ScriptDir & "\Food Planner Data\Lunch\"
If $ListActive=3 Then $Dir=@ScriptDir & "\Food Planner Data\Dinner\"
If $ListActive=4 Then $Dir=@ScriptDir & "\Food Planner Data\Supper\"
$Line=1
$WriteToIng=""
$WriteToNot=""
$WriteToName=FileRead($Dir & $Chosen & "\Name.txt")
While 1
$ReadFile=FileReadLine($Dir & $Chosen & "\Ingredients.txt", $Line)
If @error then ExitLoop
$WriteToIng=$WriteToIng & $ReadFile& @CRLF
$Line+=1
WEnd
$Line=1
While 1
$ReadFile=FileReadLine($Dir & $Chosen & "\Recipe.txt", $Line)
If @error then ExitLoop
$WriteToNot=$WriteToNot & $ReadFile & @CRLF
$Line+=1
WEnd
GUICtrlSetData($ingredients, $WriteToIng)
GUICtrlSetData($Maaltidets_Name, $WriteToName)
GUICtrlSetData($Andre_Recipe, $WriteToNot)
$OldName=$WriteToName
EndFunc

Func ShowEdit()
GUICtrlSetState($Andre_Recipe, $GUI_SHOW)
GUICtrlSetState($Andre_Recipe_Label, $GUI_SHOW)
GUICtrlSetState($ingredients, $GUI_SHOW)
GUICtrlSetState($ingredients_Label, $GUI_SHOW)
GUICtrlSetState($Maaltidets_Name, $GUI_SHOW)
GUICtrlSetState($Maaltidets_Name_Label, $GUI_SHOW)
GUICtrlSetState($Label_New_Maaltid, $GUI_SHOW)
GUICtrlSetState($Cancel_Edit, $GUI_SHOW)
GUICtrlSetState($Save_Edit, $GUI_SHOW)
$Chosen=GUICtrlRead($list1)
EndFunc

Func HideEdit()
GUICtrlSetState($Andre_Recipe, $GUI_HIDE)
GUICtrlSetState($Andre_Recipe_Label, $GUI_HIDE)
GUICtrlSetState($ingredients, $GUI_HIDE)
GUICtrlSetState($ingredients_Label, $GUI_HIDE)
GUICtrlSetState($Maaltidets_Name, $GUI_HIDE)
GUICtrlSetState($Maaltidets_Name_Label, $GUI_HIDE)
GUICtrlSetState($Label_New_Maaltid, $GUI_HIDE)
GUICtrlSetState($Cancel_Edit, $GUI_HIDE)
GUICtrlSetState($Save_Edit, $GUI_HIDE)
EndFunc

Func EditList1()
$Error=False
If GUICtrlRead($Maaltidets_Name)="" Then
MsgBox(0, "ERROR", "The meal må ha et Name!")
$Error=True
EndIf
If GUICtrlRead($ingredients)="" Then
MsgBox(0, "ERROR", "The meal må inneholde noe!")
$Error=True
EndIf
$CheckForSigns=GUICtrlRead($Maaltidets_Name)
$CheckForSigns=StringStripWS($CheckForSigns, 8)
If not StringRegExp($CheckForSigns, "(?i)^[0-9a-z]+$") Then
MsgBox(0, "ERROR", "The name contains illegal characters!")
$Error=True
EndIf
If $Error=False Then
If $ListActive=1 Then $Dir=@ScriptDir & "\Food Planner Data\Breakfast\"
If $ListActive=2 Then $Dir=@ScriptDir & "\Food Planner Data\Lunch\"
If $ListActive=3 Then $Dir=@ScriptDir & "\Food Planner Data\Dinner\"
If $ListActive=4 Then $Dir=@ScriptDir & "\Food Planner Data\Supper\"
DirRemove($Dir & $Chosen, 1)
While 1
$CheckForSpace=StringRight(GUICtrlRead($Maaltidets_Name), 1)
If $CheckForSpace=" " Then
GUICtrlSetData($Maaltidets_Name, StringTrimRight(GUICtrlRead($Maaltidets_Name), 1))
Else
ExitLoop
EndIf
WEnd
$Dir=$Dir & GUICtrlRead($Maaltidets_Name)
DirCreate($Dir)
FileWrite($Dir & "\" & "Name.txt", GUICtrlRead($Maaltidets_Name))
FileWrite($Dir & "\" & "Ingredients.txt", GUICtrlRead($ingredients))
If GUICtrlRead($Andre_Recipe) <> "" Then
FileWrite($Dir & "\" & "Recipe.txt", GUICtrlRead($Andre_Recipe))
EndIf
$Dir=@ScriptDir & "\Food Planner Data\Plandata\"
$Files=_Filelisttoarrayex($Dir)
If $Files<>0 Then
For $1=1 to $Files[0]
$ReadFile=FileRead($Files[$1])
If StringInStr($ReadFile, $OldName) Then
FileDelete($Files[$1])
FileWrite($Files[$1], GUICtrlRead($Maaltidets_Name))
EndIf
Next
EndIf
ResetNewMaaltidData()
HideEdit()
AddItemsToList()
EndIf
EndFunc

Func HideInfo()
GUICtrlSetState($list2, $GUI_HIDE)
GUICtrlSetState($list3, $GUI_HIDE)
GUICtrlSetState($Label_ingredients, $GUI_HIDE)
GUICtrlSetState($Label_Name, $GUI_HIDE)
GUICtrlSetState($Label_Recipe, $GUI_HIDE)
EndFunc

Func ShowInfo()
GUICtrlSetState($list2, $GUI_SHOW)
GUICtrlSetState($list3, $GUI_SHOW)
GUICtrlSetState($Label_ingredients, $GUI_SHOW)
GUICtrlSetState($Label_Name, $GUI_SHOW)
GUICtrlSetState($Label_Recipe, $GUI_SHOW)
EndFunc

Func UpdateInfo()
If $ListActive=1 Then $Dir=@ScriptDir & "\Food Planner Data\Breakfast\"
If $ListActive=2 Then $Dir=@ScriptDir & "\Food Planner Data\Lunch\"
If $ListActive=3 Then $Dir=@ScriptDir & "\Food Planner Data\Dinner\"
If $ListActive=4 Then $Dir=@ScriptDir & "\Food Planner Data\Supper\"
GUICtrlSetData($list2, "")
GUICtrlSetData($list3, "")
GUICtrlSetData($Label_Name, "")
$GetChosen=GUICtrlRead($list1)
$Line=1
While 1
$ReadFile=FileReadLine($Dir & $GetChosen & "\ingredients.txt", $Line)
If @error then ExitLoop
If $ReadFile="" Then
GUICtrlSetData($list2, @CRLF)
Else
GUICtrlSetData($list2, $ReadFile)
EndIf
$Line+=1
WEnd
$Line=1
While 1
$ReadFile=FileReadLine($Dir & $GetChosen & "\Recipe.txt", $Line)
If @error then ExitLoop
If $ReadFile="" Then
GUICtrlSetData($list3, @CRLF)
Else
GUICtrlSetData($list3, $ReadFile)
EndIf
$Line+=1
WEnd
$ReadFile=FileRead($Dir & $GetChosen & "\Name.txt")
GUICtrlSetData($Label_Name, $ReadFile)
EndFunc

Func ShowList()
GUICtrlSetState($list1, $GUI_SHOW)
GUICtrlSetState($Delete_Maaltid, $GUI_SHOW)
GUICtrlSetState($Radio_Breakfast, $GUI_SHOW)
GUICtrlSetState($Radio_Lunch, $GUI_SHOW)
GUICtrlSetState($Radio_Dinner, $GUI_SHOW)
GUICtrlSetState($Radio_Supper, $GUI_SHOW)
GUICtrlSetState($Label_List, $GUI_SHOW)
GUICtrlSetState($Hide_Maaltid, $GUI_SHOW)
GUICtrlSetState($Edit_Maaltid, $GUI_SHOW)
GUICtrlSetState($Get_Random, $GUI_SHOW)
EndFunc

Func DeleteMaaltid()
If MsgBox(52, "ADVARSEL", "Er du sikker på at du vil Deletee dette The meal?") <> 7 Then
If $ListActive=1 Then $Dir=@ScriptDir & "\Food Planner Data\Breakfast\"
If $ListActive=2 Then $Dir=@ScriptDir & "\Food Planner Data\Lunch\"
If $ListActive=3 Then $Dir=@ScriptDir & "\Food Planner Data\Dinner\"
If $ListActive=4 Then $Dir=@ScriptDir & "\Food Planner Data\Supper\"
$read=GUICtrlRead($list1)
DirRemove($Dir & $read, 1)
AddItemsToList()
EndIf
EndFunc

Func LeggTilNewMaaltid()
$Error=False
If GUICtrlRead($Maaltidets_Name)="" Then
MsgBox(0, "ERROR", "The meal must have a name!")
$Error=True
EndIf
$CheckForSigns=GUICtrlRead($Maaltidets_Name)
$CheckForSigns=StringStripWS($CheckForSigns, 8)
If not StringRegExp($CheckForSigns, "(?i)^[0-9a-z]+$") Then
MsgBox(0, "ERROR", "The name contains illegal characters!")
$Error=True
EndIf
If GUICtrlRead($ingredients)="" Then
MsgBox(0, "ERROR", "The meal must consist of something!")
$Error=True
EndIf

If $Error=False Then
$Dir=@ScriptDir & "\Food Planner Data\" & GUICtrlRead($KindOfMeal) & "\" & GUICtrlRead($Maaltidets_Name)
DirCreate($Dir)
If @error then $Error=True
If FileExists($Dir & "\" & "Name.txt") Then FileDelete($Dir & "\" & "Name.txt")
If FileExists($Dir & "\" & "Ingredients.txt") Then FileDelete($Dir & "\" & "Ingredients.txt")
If FileExists($Dir & "\" & "Recipe.txt") Then FileDelete($Dir & "\" & "Recipe.txt")
FileWrite($Dir & "\" & "Name.txt", GUICtrlRead($Maaltidets_Name))
If @error then $Error=True
  FileWrite($Dir & "\" & "Ingredients.txt", GUICtrlRead($ingredients))
If @error then $Error=True
If GUICtrlRead($Andre_Recipe) <> "" Then FileWrite($Dir & "\" & "Recipe.txt", GUICtrlRead($Andre_Recipe))
If @error then $Error=True
If $Error=True then MsgBox(0, "ERROR", "Could not add the new meal.")
If $Error=False then ResetNewMaaltidData()
If $Error=False then AddItemsToList()
EndIf
EndFunc

Func HideNewMaaltid()
GUICtrlSetState($KindOfMeal, $GUI_HIDE)
GUICtrlSetState($Andre_Recipe, $GUI_HIDE)
GUICtrlSetState($Andre_Recipe_Label, $GUI_HIDE)
GUICtrlSetState($Cancel_New_Maaltid, $GUI_HIDE)
GUICtrlSetState($Legg_Til, $GUI_HIDE)
GUICtrlSetState($ingredients, $GUI_HIDE)
GUICtrlSetState($ingredients_Label, $GUI_HIDE)
GUICtrlSetState($Maaltidets_Name, $GUI_HIDE)
GUICtrlSetState($Maaltidets_Name_Label, $GUI_HIDE)
GUICtrlSetState($Label_New_Maaltid, $GUI_HIDE)
ResetNewMaaltidData()
EndFunc

Func HideList()
GUICtrlSetState($list1, $GUI_HIDE)
GUICtrlSetState($Delete_Maaltid, $GUI_HIDE)
GUICtrlSetState($Radio_Breakfast, $GUI_HIDE)
GUICtrlSetState($Radio_Lunch, $GUI_HIDE)
GUICtrlSetState($Radio_Dinner, $GUI_HIDE)
GUICtrlSetState($Radio_Supper, $GUI_HIDE)
GUICtrlSetState($Label_List, $GUI_HIDE)
GUICtrlSetState($Hide_Maaltid, $GUI_HIDE)
GUICtrlSetState($Edit_Maaltid, $GUI_HIDE)
GUICtrlSetState($Get_Random, $GUI_HIDE)
EndFunc

Func ResetNewMaaltidData()
GUICtrlSetData($Andre_Recipe, "")
GUICtrlSetData($ingredients, "")
GUICtrlSetData($Maaltidets_Name, "")
EndFunc

Func ShowNewMaaltid()
GUICtrlSetState($KindOfMeal, $GUI_SHOW)
GUICtrlSetState($Andre_Recipe, $GUI_SHOW)
GUICtrlSetState($Andre_Recipe_Label, $GUI_SHOW)
GUICtrlSetState($Cancel_New_Maaltid, $GUI_SHOW)
GUICtrlSetState($Legg_Til, $GUI_SHOW)
GUICtrlSetState($ingredients, $GUI_SHOW)
GUICtrlSetState($ingredients_Label, $GUI_SHOW)
GUICtrlSetState($Maaltidets_Name, $GUI_SHOW)
GUICtrlSetState($Maaltidets_Name_Label, $GUI_SHOW)
GUICtrlSetState($Label_New_Maaltid, $GUI_SHOW)
ResetNewMaaltidData()
EndFunc

Func LagDirs()
If not FileExists(@ScriptDir & "\Food Planner Data") Then DirCreate(@ScriptDir & "\Food Planner Data")
If not FileExists(@ScriptDir & "\Food Planner Data\Breakfast") Then DirCreate(@ScriptDir & "\Food Planner Data\Breakfast")
If not FileExists(@ScriptDir & "\Food Planner Data\Lunch") Then DirCreate(@ScriptDir & "\Food Planner Data\Lunch")
If not FileExists(@ScriptDir & "\Food Planner Data\Dinner") Then DirCreate(@ScriptDir & "\Food Planner Data\Dinner")
If not FileExists(@ScriptDir & "\Food Planner Data\Supper") Then DirCreate(@ScriptDir & "\Food Planner Data\Supper")
If not FileExists(@ScriptDir & "\Food Planner Data\Plandata") Then DirCreate(@ScriptDir & "\Food Planner Data\Plandata")
EndFunc

Func AddItemsToList()
If $ListActive=1 Then $Dir=@ScriptDir & "\Food Planner Data\Breakfast\"
If $ListActive=2 Then $Dir=@ScriptDir & "\Food Planner Data\Lunch\"
If $ListActive=3 Then $Dir=@ScriptDir & "\Food Planner Data\Dinner\"
If $ListActive=4 Then $Dir=@ScriptDir & "\Food Planner Data\Supper\"
$AllFiles=_Filelisttoarrayex($Dir)
GUICtrlSetData($list1, "")
If $AllFiles<>0 Then
For $1=1 To $AllFiles[0]
If StringInStr($AllFiles[$1], "Name") Then
GUICtrlSetData($list1, FileRead($AllFiles[$1]))
EndIf
Next
EndIf
EndFunc

Share this post


Link to post
Share on other sites
Melba23

TheNorwegianUser,

Something like this perhaps? :huh:

Func UpdateInfo()
    Local $sData2 = ""
    Local $sData3 = ""
    If $ListActive = 1 Then $Dir = @ScriptDir & "\Food Planner Data\Breakfast\"
    If $ListActive = 2 Then $Dir = @ScriptDir & "\Food Planner Data\Lunch\"
    If $ListActive = 3 Then $Dir = @ScriptDir & "\Food Planner Data\Dinner\"
    If $ListActive = 4 Then $Dir = @ScriptDir & "\Food Planner Data\Supper\"
    $sData2 &= @CRLF
    $sData3 &= @CRLF
    GUICtrlSetData($Label_Name, "")
    $GetChosen = GUICtrlRead($list1)
    $Line = 1
    While 1
        $ReadFile = FileReadLine($Dir & $GetChosen & "\ingredients.txt", $Line)
        If @error Then ExitLoop
        If $ReadFile = "" Then
            $sData2 &= @CRLF
        Else
            $sData2 &= $ReadFile
        EndIf
        $Line += 1
    WEnd
    $Line = 1
    While 1
        $ReadFile = FileReadLine($Dir & $GetChosen & "\Recipe.txt", $Line)
        If @error Then ExitLoop
        If $ReadFile = "" Then
            $sData3 &= @CRLF
        Else
            $sData3 &= $ReadFile
        EndIf
        $Line += 1
    WEnd
    $ReadFile = FileRead($Dir & $GetChosen & "\Name.txt")
    GUICtrlSetData($Label_Name, $ReadFile)
    GUICtrlSetData($list2, $sData2)
    GUICtrlSetData($list3, $sData3)
EndFunc   ;==>UpdateInfo

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
TheNorwegianUser

TheNorwegianUser,

Something like this perhaps? :huh:

Func UpdateInfo()
Local $sData2 = ""
Local $sData3 = ""
If $ListActive = 1 Then $Dir = @ScriptDir & "\Food Planner Data\Breakfast\"
If $ListActive = 2 Then $Dir = @ScriptDir & "\Food Planner Data\Lunch\"
If $ListActive = 3 Then $Dir = @ScriptDir & "\Food Planner Data\Dinner\"
If $ListActive = 4 Then $Dir = @ScriptDir & "\Food Planner Data\Supper\"
$sData2 &= @CRLF
$sData3 &= @CRLF
GUICtrlSetData($Label_Name, "")
$GetChosen = GUICtrlRead($list1)
$Line = 1
While 1
$ReadFile = FileReadLine($Dir & $GetChosen & "\ingredients.txt", $Line)
If @error Then ExitLoop
If $ReadFile = "" Then
$sData2 &= @CRLF
Else
$sData2 &= $ReadFile
EndIf
$Line += 1
WEnd
$Line = 1
While 1
$ReadFile = FileReadLine($Dir & $GetChosen & "\Recipe.txt", $Line)
If @error Then ExitLoop
If $ReadFile = "" Then
$sData3 &= @CRLF
Else
$sData3 &= $ReadFile
EndIf
$Line += 1
WEnd
$ReadFile = FileRead($Dir & $GetChosen & "\Name.txt")
GUICtrlSetData($Label_Name, $ReadFile)
GUICtrlSetData($list2, $sData2)
GUICtrlSetData($list3, $sData3)
EndFunc ;==>UpdateInfo

M23

Thanks, it works now! :) Just had to modify it a bit ;)

Func UpdateInfo()
    Local $sData2 = ""
    Local $sData3 = ""
    If $ListActive = 1 Then $Dir = @ScriptDir & "\Food Planner Data\Breakfast\"
    If $ListActive = 2 Then $Dir = @ScriptDir & "\Food Planner Data\Lunch\"
    If $ListActive = 3 Then $Dir = @ScriptDir & "\Food Planner Data\Dinner\"
    If $ListActive = 4 Then $Dir = @ScriptDir & "\Food Planner Data\Supper\"
    $sData2 &= @CRLF
    $sData3 &= @CRLF
GUICtrlSetData($list2, "")
GUICtrlSetData($list3, "")
GUICtrlSetData($Label_Name, "")
    $GetChosen = GUICtrlRead($list1)
    $Line = 1
    While 1
        $ReadFile = FileReadLine($Dir & $GetChosen & "\ingredients.txt", $Line)
        If @error Then ExitLoop
        If $ReadFile = "" Then
            $sData2 &= "|" & @CRLF
        Else
FileReadLine($Dir & $GetChosen & "\ingredients.txt", $Line+1)
If @error then
$sData2 &= $ReadFile
Else
$sData2 &= $ReadFile & "|" & @CRLF
EndIf
        EndIf
        $Line += 1
    WEnd
    $Line = 1
    While 1
        $ReadFile = FileReadLine($Dir & $GetChosen & "\Recipe.txt", $Line)
        If @error Then ExitLoop
        If $ReadFile = "" Then
            $sData3 &= "|" & @CRLF
        Else
FileReadLine($Dir & $GetChosen & "\ingredients.txt", $Line+1)
If @error then
$sData3 &= $ReadFile
Else
$sData3 &= $ReadFile & "|" & @CRLF
EndIf
        EndIf
        $Line += 1
    WEnd
    $ReadFile = FileRead($Dir & $GetChosen & "\Name.txt")
    GUICtrlSetData($Label_Name, $ReadFile)
    GUICtrlSetData($list2, $sData2)
    GUICtrlSetData($list3, $sData3)
EndFunc   ;==>UpdateInfo
Edited by TheNorwegianUser

Share this post


Link to post
Share on other sites
Melba23

TheNorwegianUser,

Ah yes, the delimiters! :>

Glad it helped - I will try not to make such a silly mistake next time. :whistle:

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

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  

×