Peggy

excel table with arrary and for next loop for scheduling problems_2

6 posts in this topic

#1 ·  Posted (edited)

[Rule]
1. A start would be to get this excel spreadsheet, people called the group, a total divided into two groups: Mary, Sam, Jack

1.thumb.jpg.fbde7c98e1c9ffd7f6557dcd7ec1
2. Every person eating a fruit, and each times one person can eat the same fruit (or random fruit)
3. Last eaten fruit can not eat
4. so be scheduled
5. If the previous round fruits are finished, the remaining number can pick one randomly 
6. If I have more than 100 the number of Name(people), how can I to code it?


Picture:
1. The first time Mary eat Apple, Sam  can  eat Apple(or random),and Jack chose random first to eat.

2.thumb.jpg.6688381fa3a5b3b41c32c2339378
2. The second They are chose random first to eat.

3.thumb.jpg.f4d7feefb9c8e81dd9cdbce4f3e1
3. Third  They are chose random first to eat.

4.thumb.jpg.74c2575768754dab0472b90ea449
4. Fourth Sam chose tomato,because the previous round fruits are finished, the remaining number can pick one randomly ,Jack is too.

5.thumb.jpg.7836a56d5a33b26ed88d7ee564e1
5. Fifth Sam chose tomato,because the previous round fruits are finished, the remaining number can pick one randomly ,Jack is too.

 

6.thumb.jpg.64950d4f51ef58151cdac005d58d


Currently only think of using arrary and for next loop to write it, but I do not know to write Detailing, want to please help me, thank you very much !!!! Thank you!!:D:D

 

 

 

 

 

 

Edited by Peggy

Share this post


Link to post
Share on other sites



Peggy,

A couple of your requirements are unclear:

- Every person eating a fruit, and each times one person can eat the same fruit (or random fruit): Does this mean that in each round several pairs can eat the same fruit or that only one pair may do so?

- If the previous round fruits are finished, the remaining number can pick one randomly: So those with a smaller range from which to choose just repeat choices from that range until the end of the largest range? What if there are no unique (or double) choices left in the round after all the previous selections? What do they choose then?

As to doing this for 100+ people, I think that you might begin to struggle. What exactly are you doing? If we get a better idea of the purpose of all this we might be able to offer a better solution.

M23

 

1 person likes this

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

#3 ·  Posted (edited)

Hi Melba23,
Thanks for your reply!!!I feel very moved!! :D


- Every person eating a fruit, and each times one person can eat the same fruit (or random fruit):
each round one person can eat the same fruit,but next time one person can't eat previous eaten fruit(Unless the previous have all finished).

- If the previous round fruits are finished, the remaining number can pick one randomly:
This function can be deleted, if the previous finish, behind may be left blank.(If that can to do, can be randomly selected)

As shown below

[Rule]
1. A start would be to get this excel spreadsheet, people called the group, a total divided into two groups: Mary, Sam, Jack , Jason, Susan

47.thumb.jpg.4ff74b560b00ddc5c1e64a4f7ff

1. Round 1: each one Random choice.(Each one can choose the same fruit)

 

48.thumb.jpg.6c6f4a914cdc841a749be657ef6

2. Round 2: each one Random choice.(each one can't eat Previous fruit Unless all eaten up)

49.thumb.jpg.255a6b2020594034b5344c98b93

3. Round 3,4,5,6: And so on,  each one Random choice.(each one can't eat Previous fruit Unless all eaten up,This feature is not essential

50.thumb.jpg.1ede09792d8c69ed8043b97ba46

Thanks for your  great help!! :D

 

p.s.
If name more than the amount of fruits (Ex: name x7, fruit max: 5), than someone will be blank at previous round, we hope to end with five round.

44.thumb.jpg.03215a14ba4bff1a15ea0a57735

we hope result is  .. 

 

43.thumb.jpg.a3ae7c8c35dff59f1732562709d

Thanks for your  great help!! :D:D

Edited by Peggy

Share this post


Link to post
Share on other sites

Peggy,

I am afraid I am still not altogether clear about your requirements, but this seems to match your final state:

3. Round 3,4,5,6: And so on,  each one Random choice.(each one can't eat Previous fruit Unless all eaten up

 

#include <Array.au3>

; Array of groups (in priority order) and possible choices
Global $aData[][] = [["Mary", 5, "Apple", "Banana", "Tomato", "Watermelon", "Strawberry"], _
                    ["Sam", 2, "Apple", "Tomato"], _
                    ["Jack", 3, "Banana", "Watermelon", "Strawberry"], _
        ["Jason", 2, "Banana", "Watermelon"], _
        ["Susan", 6, "Watermelon", "Strawberry", "Apple", "Tomato", "Banana", "Orange"]]

; Determine the size of the display
Global $iRows = 0
For $i = 0 To UBound($aData) - 1
    $iRows += $aData[$i][1]
Next
Global $iCols = UBound($aData, $UBOUND_COLUMNS)

; Create array to hold display
Global $aDisplay[$iRows][$iCols]

; Create array to hold group data
Global $aGroupInfo[UBound($aData)][4] = [[0]]
Local $iRow = 0
For $i = 0 To UBound($aData) - 1
    If $i Then
        $iRow += $aData[$i - 1][1]
        $aGroupInfo[$i][0] = $iRow          ; Start row
    EndIf

    $aGroupInfo[$i][1] = $aData[$i][1]      ; Total number of choices
    $aGroupInfo[$i][2] = $aData[$i][1]      ; Choice index
    Local $aChoices[$aData[$i][1]]
    For $j = 2 To $aData[$i][1] + 1
        $aChoices[$j - 2] = $aData[$i][$j]
    Next
    _ArrayShuffle($aChoices)
    $aGroupInfo[$i][3] = $aChoices          ; Shuffled array of choices
Next

; Fill display with groups names and choices
$iRow = 0
For $i = 0 To UBound($aData) - 1
    For $j = 2 To $aData[$i][1] + 1
        $aDisplay[$iRow][0] = $aData[$i][$j]
        $aDisplay[$iRow][1] = $aData[$i][0]
        $iRow += 1
    Next
Next

; Run through choice rounds
For $iChoice = 2 To $iCols - 1
    ; For each group in turn
    For $iGroup = 0 To UBound($aData) - 1
        ; Get next choice from the shuffled array
        $sChoice = ($aGroupInfo[$iGroup][3])[$aGroupInfo[$iGroup][2] - 1]
        ; Check choices remain
        If $aGroupInfo[$iGroup][2] > 1 Then
            ; Move to next choice for next round
            $aGroupInfo[$iGroup][2] -= 1
        Else
            ; Reset choice count and reshuffle array
            $aGroupInfo[$iGroup][2] = $aGroupInfo[$iGroup][1]
            _ArrayShuffle($aGroupInfo[$iGroup][3])
        EndIf

        ; Find choice in the original array
        $iIndex = _ArraySearch($aData, $sChoice, Default, Default, Default, Default, Default, $iGroup, True)
        ; Add to display in correct row
        $aDisplay[$aGroupInfo[$iGroup][0] + $iIndex - 2][$iChoice] = $sChoice

    Next
Next

_ArrayDisplay($aDisplay, "", Default, 8)

Does it do what you want? If not, what needs to be changed?

M23

P.S. And I am still curious as to what exactly you are doing as this algorithm is obviously not meant for fruit selection in the real world and there might be a better way to do it if we knew the overall purpose.


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

Hi Melba23,

That is the  fuction I want, thank you for helping me so much ,I'm so happy!!
About this program, this is the process of class scheduling
.I just say for an example:eating fruit, that will be easy to understand for you.
Thank you very very much !!!!!You're the best person I've ever seen~!!:lol:^_^

Share this post


Link to post
Share on other sites

Peggy,

Delighted I could help. Do not hesitate to let me know if your supervisor changes the requirements again!

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

  • Similar Content

    • 0Ethan0
      By 0Ethan0
      Ahoy Autoit Community!
      After many trials and errors I am unable to solve a problem I am facing and would appreciate any kind of input or better yet a solution 
      The Premise: An embeded slideshow viewer that runs after double-clicking an item in a ListView (each item will generate a different slideshow images).
      The Setup: GUI with a ListView Control and a simple exit button.
      The Issue: Once double clicked the slide plays however the GUI "locks"/non responsive until the slide is over. Same thing if I click on the "Test" button.
      The Culprit: I believe since it's in the images loop it can't accept any other commands until that loop is over.
      The Wish: I want to be able to use the GUI functions (selecting other items, clicking on button etc.) while the slideshow plays.
      The Code (stripped and simplified as much as I could):
      #include <GuiListView.au3> #include <File.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) HotKeySet("{Esc}", "_Exit") Global $c=0 Global $ssGDI[3], $ssGraphic[2], $ssImage Global Const $bg_color = "000000" Global Const $ssW = 480, $ssH = 320 Global $aFiles = _FileListToArrayRec("d:\testStage\", "*.jpg;*.png;*.bmp;*.gif;*.JPG;*.PNG;*.BMP;*.GIF", $FLTAR_FILES, $FLTAR_NORECUR ,$FLTAR_SORT ,$FLTAR_FULLPATH ) $guiW = 1200 $guiH = 726 $mainWindow = GUICreate("Slideshow Viewer", $guiW, $guiH, -1, -1, $WS_POPUP) $Button1 = GUICtrlCreateButton("Exit", 0, 0, 50, 50) GUICtrlSetOnEvent($Button1, "_Exit") $Button1 = GUICtrlCreateButton("Test", 60, 0, 50, 50) GUICtrlSetOnEvent($Button1, "Test") Global $ListView = GUICtrlCreateListView("Entry Name|Category", 5, 75, 195, 280) _GUICtrlListView_SetColumnWidth ($ListView, 0, 100) _GUICtrlListView_SetColumnWidth ($ListView, 1, 100) GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT) GUICtrlCreateListViewItem("Name 1|Category 1", $ListView) GUICtrlCreateListViewItem("Name 2|Category 2", $ListView) screenshotWidgetInit($ssW,$ssH, 690, 100) GUISetState(@SW_SHOW, $mainWindow) GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _Exit() EndSwitch WEnd Func Test() For $k = 1 To UBound($aFiles) - 1 screenshotWidgetTransition($aFiles[$k]) Next EndFunc Func ListView_Click() ConsoleWrite("Left Click") EndFunc Func ListView_DoubleClick() ConsoleWrite("Double Left Click") Test() EndFunc Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $tagNMHDR, $event, $hwndFrom, $code $tagNMHDR = DllStructCreate("int;int;int", $lParam) If @error Then Return $event = DllStructGetData($tagNMHDR, 3) Select Case $wParam = $ListView Select Case $event = $NM_CLICK ListView_Click () Case $event = $NM_DBLCLK ListView_DoubleClick () EndSelect EndSelect Return $GUI_RUNDEFMSG EndFunc Func screenshotWidgetTransition($image, $delay = 0, $speed = 1, $sleep = 2000) Local $a, $d = $c, $iX, $iY $ssImage = _GDIPlus_ImageLoadFromFile($image) $iX = _GDIPlus_ImageGetWidth($ssImage) $iY = _GDIPlus_ImageGetHeight($ssImage) $FDesktop=$ssH/$ssW $Fact =1 If $iX > $ssW And $FDesktop > ($iY/$iX) Then $Fact=$ssW/$iX ElseIf $iY > $ssH Then $Fact=$ssH/$iY EndIf $H1 = Round(($Fact * $iY),0) $W1 = Round(($Fact * $iX),0) _GDIPlus_GraphicsDrawImageRect($ssGraphic[$d], $ssImage,($ssW - $W1)/2, ($ssH - $H1) / 2,$W1,$H1) WinSetTrans($ssGDI[$d], "", 0) WinSetOnTop($ssGDI[$d], "", 1) For $a = 0 To 254 Step $speed WinSetTrans($ssGDI[$d], "", $a) Sleep($delay) Next WinSetTrans($ssGDI[$d], "", 254) WinSetOnTop($ssGDI[Not ($d)], "", 0) WinSetTrans($ssGDI[Not ($d)], "", 0) _GDIPlus_GraphicsClear($ssGraphic[Not ($d)]) $c = 1 - $d _GDIPlus_ImageDispose ($ssImage) ; very important to realease the pics Sleep($sleep) EndFunc ;==>screenshotWidgetTransition Func screenshotWidgetInit($ssW,$ssH,$ssX,$ssY) $ssGDI[2] = GUICreate("", $ssW, $ssH, $ssX, $ssY, $WS_POPUP, $WS_EX_MDICHILD, $mainWindow) $ssGDI[0] = GUICreate("", $ssW, $ssH, 3, 3, $WS_POPUP, $WS_EX_MDICHILD, $ssGDI[2]) $ssGDI[1] = GUICreate("", $ssW, $ssH, 3, 3, $WS_POPUP, $WS_EX_MDICHILD, $ssGDI[2]) ; GUISetBkColor("0x" & $bg_color, $ssGDI[2]) GUISetState(@SW_SHOW, $ssGDI[2]) GUISetState(@SW_SHOW, $ssGDI[0]) GUISetState(@SW_SHOW, $ssGDI[1]) WinSetTrans($ssGDI[0], "", 0) WinSetTrans($ssGDI[1], "", 0) _GDIPlus_Startup() $ssGraphic[0] = _GDIPlus_GraphicsCreateFromHWND($ssGDI[0]) $ssGraphic[1] = _GDIPlus_GraphicsCreateFromHWND($ssGDI[1]) _GDIPlus_GraphicsClear($ssGraphic[0], "0xFF" & $bg_color) _GDIPlus_GraphicsClear($ssGraphic[1], "0xFF" & $bg_color) EndFunc ;==>screenshotWidgetInit Func _Exit() _GDIPlus_ImageDispose($ssImage) _GDIPlus_GraphicsDispose($ssGraphic[0]) _GDIPlus_GraphicsDispose($ssGraphic[1]) GUIDelete($ssGDI[0]) GUIDelete($ssGDI[1]) GUIDelete($ssGDI[2]) _GDIPlus_Shutdown() Exit EndFunc ;==>_Exit I hope someone can shed light on this; perhaps a different approach is needed?
      Thank you in advance!
      P.S.
      The script is patched from different scripts of different users in the forum - thank you again users!
    • Patryk
      By Patryk
      Dear Colleagues,
      I have no idea how to refer to style.display in my loop. There is a button like: 
      <input name="ctl00$bodyPlaceholder$btnFecharProcessamento" class="button" id="bodyPlaceholder_btnFecharProcessamento" style="display: none;" onclick="FecharJanelaProcessamento();return false;" type="submit" value="Fechar"> I want it to be clicked as soon as button's style change from style="display: none;" to  style= ="display: inline-block;" 
      This is what I got, but it's not working...
      Func GetButtons() $oButtons = _IEGetObjByName($oForm,"ctl00$bodyPlaceholder$btnFecharProcessamento",-1) $i = 0 While $i <> 1 For $oBtn In $oButtons If _IEFormElementGetValue($oBtn) = "Fechar" And $oBtn.document.style.display = "display: inline-block;" Then $i = 1 _IEAction($oBtn, "focus") _IEAction($oBtn, "click") ExitLoop EndIf Next WEnd EndFunc  
      I will really appreciate if you could help me with these loop!
    • Nareshm
      By Nareshm
      How to repeat my script when my control class does not match ?
       
      My Script : winActivate ( " PS :: Version - 2.2.0.0  - [PS Bill]")                   ControlClick ( "PS :: Version - 2.2.0.0  - [PS Bill]", "", "[NAME:btnSavebyFP]")                   ControlSend(" PS :: Version - 2.2.0.0  - [PS Bill]", "", "[NAME:btnSavebyFP]", "{enter}")                   WinActive ("Verification Number Entry ::")                   ControlClick("Next >", "","[NAME:btnNext]") ;if   >>>> Control <<<<  does not match repeat my script, ;if match exit script  

      Class:    WindowsForm734a
      Instance:    15
      ClassnameNN:    WindowsForm34a15
      Name:    BillPrint
      Advanced (Class):    [NAME:BillPrint]
      ID:    7875
      Text:    
      Position:    39, 310
      Size:    1221, 306
      ControlClick Coords:    745, 20
      Style:    0x56010000
      ExStyle:    0x00000000
      Handle:    0x00000000000C0468
    • JustinZandee
      By JustinZandee
      I need a random string generator which creates 15 letters/numbers.
      How can I make that?
    • SkysLastChance
      By SkysLastChance
      I am not sure why I am getting the this error on my second pass of the code.
      1 - $oWorkbook is not an object or not a workbook object
      Any help or advice on my code appreciated. 
      #include <Excel.au3> #include <Array.au3> #include <MsgBoxConstants.au3> Global $sExcelFile1 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsm)") Global $sExcelFile2 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "Excel Sheet (*.xlsx;*.xls)|All (*.*)") Global $vRow = 2 If FileExists($sExcelFile2) Then Global $oExcel2 = _Excel_Open () $oExcel2 = _Excel_BookOpen($oExcel2,$sExcelFile2) EndIF If FileExists($sExcelFile1) Then Global $oExcel1 = _Excel_Open () $oExcel1 = _Excel_BookOpen($oExcel1,$sExcelFile1,Default,Default,"2007") EndIF $oRead = _Excel_RangeRead ($oExcel2,"Untitled","A2",3) $oFind = _Excel_RangeFind ($oExcel1,$oRead,"E4:FD92",Default,$xlWhole) $Clip = _ArrayToClip($oFind,"",0,0,"",2,2) Send("{ScrollLock Off}") $hWnd = WinWait("[CLASS:XLMAIN]") ControlSend($hWnd, "", "", ("^g")) WinWait("[CLASS:bosa_sdm_XL9]") ; Go To ControlSend($hWnd, "", "", ("^v")) ControlSend($hWnd, "", "", ("{Enter}")) ControlSend($hWnD, "", "", "{Down " & $vRow & "}") Do $oTime = _Excel_RangeRead ($oExcel2,"Untitled","B2",3) If @error Then Exit MsgBox(0, "Error", "Error" & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox(0,"Test",$oTime) IF $oTime = "7:10:00 AM" Then $oCalls1 = _Excel_RangeRead ($oExcel2,Default,"C" & $vRow,3) $oCalls2 = _Excel_RangeRead ($oExcel2,Default,"D" & $vRow,3) ControlSend($hWnd, "", "", $oCalls1) ControlSend($hWnd, "", "", ("{RIGHT}")) ControlSend($hWnd, "", "", $oCalls2) $vRow = $vRow + 1 ContinueLoop Else $vRow = $vRow + 1 EndIf Until $vRow = 4 1.xlsm
      2.xlsx