Jump to content

Array to GUICtrlCreateListView


Recommended Posts

OK, my latest project (I like finding projects that will increase my scripting knowledge) is one that will allow me to add dinner recipes to a database and the ingredients in a seperate database. With the press of a button I will randomly choose (ever how many I enter when it asks) these recipes and I will add them to the menu in that order.

It has three Tabs. The first one will show all available recipes in a window, have an input box for the number desired and a button to randomly choose them. The second Tab will be where they are imported and the third will be where I could choose them manually.

Now my problem......I can't get my mind wrapped around Arrays. I've scoured the forum for 2 days, read the Wiki, and the help file and I still can't figure it out.

1. Is it possible to randomly pick items from an array list?

2. What type of window should I be trying to read the arrays into on the first tab? Currently I am trying GUICtrlCreateListView

3. How the heck do I do it?

I don't expect anyone to write it for me, just get me pointed in the right direction. I will post my code but it's not pretty, it's just how I have taught myself to write.

#ce ----------------------------------------------------------------------------

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <File.au3>
#include <AVIConstants.au3>
#include <TreeViewConstants.au3>
#Include <GuiEdit.au3>
#Include <Array.au3>
#Include <GuiListView.au3>
;Opt('MustDeclareVars', 1)

;----------------------------------These are the variables
Dim $recipeDATABASE = "C:\Documents and Settings\dmassey\My Documents\Recipe Wiz\RecipeDB\"
Dim $ingedientDATABASE = "C:\Documents and Settings\dmassey\My Documents\Recipe Wiz\IngredientsDB\"
Dim $InstalDIR =  @MyDocumentsDir & "\Recipe Wiz\"
Dim $Msg
Dim $Font1
Dim $Color1
Dim $RecPIN
Dim $IngrIN
Dim $ImportBUTTON
Dim $FileREC
Dim $FileING
Dim $ReadING
Dim $ReadRECP
Dim $RecipeLIST
;---------------------------------------------------------------------------------This is the main Window

GUICreate ("Recipe WiZ")            
GUISetIcon ($InstalDIR & "Home.ico")

TABS() ;This will start the function

Func TABS()
;---------------------------------------------------------------------------------This creates all my TABs
GuiCtrlCreateTab(10, 5, 380, 390) 
$RecipeLIST =_FileListToArray($recipeDATABASE)

;--------------------------------------------------------------------------

GuiCtrlCreateTabItem("Generate Menu")
$11 = GUICtrlCreateListView("", 170, 60, 205, 275)
$12 = _ArrayDisplay("TEST", $RecipeLIST)
GuiCtrlCreateLabel("From here you can create your dinner menu",85, 40)   
GuiCtrlCreateTabItem("Add New Recipe")

;---------------------------------------------------------------------------------This is the Generate Menu TAB will list avail. recipes and prompt for action

;--------------------------------------------------------------------------

;---------------------------------------------------------------------------------This is the Edit fields on teh ADD Recipe TAB
GuiCtrlCreateLabel("From here you can add recipes to the database", 80, 40)
GuiCtrlCreateLabel("Recipe                                              Ingredients", 80, 320)
GuiCtrlCreateLabel("Paste your recipe and ingredients above to import",25, 365)
$RecPIN = GuiCtrlCreateEdit(@CRLF & "", 20, 60, 180, 250)
$IngrIN = GuiCtrlCreateEdit(@CRLF & "", 210, 60,170, 250)   
$ImportBUTTON = GUICtrlCreateButton("Import", 300, 355, 75, 30)
GuiCtrlCreateTabItem("Manually Create Menu")        
GuiCtrlCreateLabel("From here you can create your dinner menu manually", 70, 40)
;---------------------------------------------------------------------------------This is the Creat Menu Manually TAB
;---------------------------------------------------------------------------------
GUISetState (@SW_SHOW)
GuiSetState()

;---------------------------------------------------------------------------------This is where the Manual TAB will allow you to create your own Menu
;---------------------------------------------------------------------------------

EndFunc

;--------------------------------------------------------------------------------This loops the program and waits for the message

While $msg  <> $GUI_EVENT_CLOSE
$msg = GuiGetMsg()

  Select
   Case $msg = $ImportBUTTON
   $ReadRECP = GUICtrlRead($RecPIN)
   $1 = StringLeft($ReadRECP, 25)
   $2 = InputBox("Your Recipe Name", "Your recipe name will be saved as noted in the box, please correct any errors" , $1)
    If @error Then
    
    Else
    Call ("Import")
    EndIf
    
  EndSelect
WEnd


;This Imports the Recipes and Ingredients
Func Import()
   $3 = _FileCreate($recipeDATABASE & $2 & ".txt")
   $4 = FileOpen($recipeDATABASE & $2 & ".txt" ,1)
   $5 = FileWrite($recipeDATABASE & $2 & ".txt", $ReadRECP)
   $6 = FileClose($recipeDATABASE & $2 & ".txt")
   GUICtrlSetData($RecPIN,"")   
   $ReadING = GUICtrlRead($IngrIN)
   $7 = _FileCreate($ingedientDATABASE & $2 & ".txt")
   $8 = FileOpen($ingedientDATABASE & $2 & ".txt",1)
   $9 = FileWrite($ingedientDATABASE & $2 & ".txt",$ReadING)
   $10 = FileClose($ingedientDATABASE & $2 & ".txt")
   GUICtrlSetData($IngrIN,"")
   MsgBox(0,"Success!!", "Import Successful!",2)
EndFunc

I do plan on cleaning it up and renaming my variables.

Thanks in advance for ANY help!

[size="2"][u]Beer is living proof that God loves us and wants us to be happy.-- Ben Franklin[/u][/size]

Link to comment
Share on other sites

I also meant to add that the shopping list will be pulled from the ingredients database to a text doc so it will be printable.

[size="2"][u]Beer is living proof that God loves us and wants us to be happy.-- Ben Franklin[/u][/size]

Link to comment
Share on other sites

 Maybe this will help:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

$Form1 = GUICreate("Random example", 528, 327, 192, 124)
$ListView1 = GUICtrlCreateListView("Items", 8, 8, 161, 305)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 150)
$ListView1_0 = GUICtrlCreateListViewItem("Orange", $ListView1)
$ListView1_1 = GUICtrlCreateListViewItem("Kiwi", $ListView1)
$ListView1_2 = GUICtrlCreateListViewItem("Bananas", $ListView1)
$ListView1_3 = GUICtrlCreateListViewItem("Peach", $ListView1)
$ListView1_4 = GUICtrlCreateListViewItem("Lemon", $ListView1)
$ListView1_5 = GUICtrlCreateListViewItem("Plum", $ListView1)
$Button1 = GUICtrlCreateButton("&Press me!", 192, 144, 97, 33, $WS_GROUP)
$Label1 = GUICtrlCreateLabel("We have:", 192, 40, 51, 17)
$Label2 = GUICtrlCreateLabel("", 256, 40, 120, 17)
GUISetState(@SW_SHOW)

While 1
    Sleep(10)
    $nMsg = GUIGetMsg()
    Switch $nMsg
         Case $GUI_EVENT_CLOSE
                      Exit
         Case $Button1
                      _Push()
    EndSwitch
WEnd

Func _Push()
     Local $rand_item = Random(0,_GUICtrlListView_GetItemCount($ListView1)-1,1) ;we pick randomly items IDs from the ListView (0 based array)
     Local $rand_value = _GUICtrlListView_GetItemText($ListView1, $rand_item)       ;and the corresponding text
     GUICtrlSetData($Label2, "Item no." & $rand_item & ": " & $rand_value)              ;and pass it to the label, for example
EndFunc

What kind of database you will use?

Edited by taietel
Link to comment
Share on other sites

1. Is it possible to randomly pick items from an array list?

$sString = "1234567890"
$aArray = StringSplit($sString,"")
MsgBox(0,"",$aArray[Random(0,ubound($aArray-1),1)])
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

Thank you for the replies, I will study them.

What I'm calling a database is just a folder, nothing special.

[size="2"][u]Beer is living proof that God loves us and wants us to be happy.-- Ben Franklin[/u][/size]

Link to comment
Share on other sites

OK I give up could sombody help me list a _FileListToArray into a gui listview that I have created, I just cannot figure it out Posted Image

[size="2"][u]Beer is living proof that God loves us and wants us to be happy.-- Ben Franklin[/u][/size]

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...