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

    • nlta1992
      By nlta1992
      I want creat GUI, have button 1 to 10, but only use loop for ... to ... step ... next.
      Thanks.
    • SkysLastChance
      By SkysLastChance
      I keep losing the count of my $r varable when I go into the dropdown () function and call the same function.
      #include <Excel.au3> #include <AutoItConstants.au3> #include<GUIConstantsEx.au3> #include<EditConstants.au3> #include<GUIConstants.au3> Global $iBox, $oExcel, $oWorkbook, $r = 1, $x = 3 HowMany() Excel () Dropdown () Sleep (500) Func Dropdown () $list = GUICreate("Chart", 225, 80) $combobox = GUICtrlCreateCombo("Clinic 1", 10, 10, 120, 20) GUICtrlSetData(-1, "Clinic 2|Clinic 3|Clinic 4") $button = GUICtrlCreateButton("Select", 10, 40, 60, 20) GUISetState(@SW_SHOW) While 1 $guibox = GUIGetMsg() Select Case $guibox = $button Select Case GUICtrlRead($combobox) = "Clinic 1" GUIDelete($list) Auto () EndSelect Case $guibox = $GUI_EVENT_CLOSE EndSelect WEnd EndFunc Func HowMany() Local $iMsg While 1 ;~ Turn input into a number $iBox = Number(InputBox ("Regestration", "How Many Patients are there total?")) ;~ If user enters a string or cancels then get them to try again If $iBox = 0 Then $iMsg = MsgBox(1,'Regestration', 'Please enter a valid number') If $iMsg = 2 Then Exit Else ExitLoop EndIf WEnd EndFunc Func Excel() While ProcessExists("EXCEL.EXE") $ms = MsgBox(5,"","Process error. You have an Excel sheet open. You must close it in order to let this program work. Please close it now.") If $ms=2 Then Exit ;~ Doesn't require sleep since the script is paused by the MsgBox above ;~ Sleep(250) WEnd ;~ Shouldn't use Global Scope inside functions moved to top of script Local $sExcelFile = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsx)") If FileExists($sExcelFile) Then ;~ Shouldn't use Global Scope inside functions moved to top of script $oExcel = _Excel_Open () $oWorkbook = _Excel_BookOpen($oExcel,$sExcelFile) ;this will open the chosen xls file. Else $oExcel = _Excel_Open() $oWorkbook = _Excel_BookNew($oExcel, 2);this is here to create the xls file if it does not exist. EndIf EndFunc Func Auto() Local $aArray1 = _Excel_RangeRead($oWorkbook) ;~ If $iBox is greater than no. of rows in $aArray then $iBox equals the number of rows in $aArray If $iBox > (UBound($aArray1) - 1) Then $iBox = UBound($aArray1) - 1 For $i = 2 To UBound($aArray1) - 1 ;$i =0 Start from row A If $aArray1[$i][1] = "" Then Continueloop $sR0 = $aArray1[$i][0] ;status $sR1 = $aArray1[$i][1] ;Last Name $sR2 = $aArray1[$i][2] ;First Name $sR3 = $aArray1[$i][3] ;DOB $sR4 = $aArray1[$i][4] ;Sex $sR5 = $aArray1[$i][5] ;Mailling Address $sR6 = $aArray1[$i][6] ;Zip $sR7 = $aArray1[$i][7] ;Phone # $sR8 = $aArray1[$i][8] ;Visit Reason $sR9 = $aArray1[$i][9] ;Insurance $sR10 = $aArray1[$i][10] ;Clinic $sR11 = $aArray1[$i][11] ;Provider $sR12 = $aArray1[$i][12] ;Appt Time $sR13 = $aArray1[$i][13] ;Appt Date WinWaitActive ("Untitled - Notepad") ControlSend("Untitled - Notepad", "", "", $sR1 & ',' & $sR2 & @CR) $r += 1 If $r > $iBox Then Exit Dropdown () Next EndFunc so the second time I choose clinic 1 I want it to go to the next row which would be Champ brett in my example excel.
       
      Test.xlsx
      Example Format.xlsx
    • kevin42036
      By kevin42036
      Hi All,

      I am new to AutoIt and programming in general so any help would be greatly appreciated! 

      I am trying to create a script mainly using MouseClick and WinWait in order to automate some web processes. However, due to the lag time of the web pages and fields, sometimes my script does not run properly and I need to rerun it. I am trying to create a script that will check to see if the final line of the script was properly executed and if not, rerun the program and increase a count. Ultimately I would like some sort of report that tells me how many times it took to run to completion and total time. 

      Does anyone have any suggestions as to which functions I can use to accomplish this? I am also open to any suggestions on a better process to ensure that my program runs to completion.

      Thanks in advance!

      Kevin
    • SkysLastChance
      By SkysLastChance
      I know this code is not pretty by any means, but it will not loop. I have used this loop several diffrend times. 
      When I take out the this if statment it loops forever so I am guessing ti has to do with this.
      Any ideas on cleaning up code is appreciated too.
      If $r > $sBox Then Exit Endif #include <Excel.au3> #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> $sBox = InputBox ("Vital Site", "How Many Times") Excel () Logon () Sleep (2000) Auto () Func FormatDate($DATE) $SPLIT = StringSplit($DATE," ") $MM = StringMid($SPLIT[1],5,2) $YYYY = StringLeft($SPLIT[1],4) $DD = StringMid($SPLIT[1],7,2) Return $MM & "/" & $DD & "/" & $YYYY EndFunc Func Terminate() Exit EndFunc HotKeySet(("{ESC}"),"Terminate") Func Excel () While ProcessExists("EXCEL.EXE") $ms = MsgBox(5,"","Process error. You have an Excel sheet open. You must close it in order to let this program work. Please close it now.") If $ms=2 Then Exit Sleep(250) WEnd Global $sExcelFile = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsx)") If FileExists($sExcelFile) Then Global $oExcel = _Excel_Open () $oExcel = _Excel_BookOpen($oExcel,$sExcelFile) ;this will open the chosen xls file. Else $oExcel = _Excel_Open() $oWorkbook = _Excel_BookNew($oExcel, 2);this is here to create the xls file if it does not exist. EndIf EndFunc Func Logon () $portal = ShellExecute ("C:\Program Files (x86)\MEDITECH\SSDWEB.Universe\SSDWEB.LIVEF.Ring\Client.mtad") ;MediTech WinWaitActive ("[CLASS:MagicFS]", "", "MagicFS Dispaly5") Sleep (300) ControlSend("[CLASS:MagicFS]", "", "", ("{F12}")) Sleep (700) ControlSend("[CLASS:MagicFS]", "", "", ("{RIGHT}")) Sleep (700) ControlSend("[CLASS:MagicFS]", "", "", ("{DOWN}")) Sleep (700) ControlSend("[CLASS:MagicFS]", "", "", ("{RIGHT}")) Sleep (700) ControlSend("[CLASS:MagicFS]", "", "", ("{RIGHT}")) Sleep (700) ControlSend("[CLASS:MagicFS]", "", "", ("{RIGHT}")) EndFunc WinWaitActive ("[CLASS:MagicFS]", "", "MagicFS Dispaly6") Func Auto () $r = 1 Local $aArray = _Excel_RangeRead($oExcel, Default, Default,1) For $i = 1 To UBound($aArray) - 1 ;$i =0 Start from row A $sR0 = $aArray[$i][0] ;status $sR1 = $aArray[$i][1] ;first name $sR2 = $aArray[$i][2] ;Last name $sR3 = $aArray[$i][3] ;Last 4 SSN $sR4 = $aArray[$i][4] ;DOB $sR5 = $aArray[$i][5] ;Email Address $sR6 = $aArray[$i][6] ;Mailling Address $sR7 = $aArray[$i][7] ;City $sR8 = $aArray[$i][8] ;state $sR9 = $aArray[$i][9] ;Zip Code $sR10 = $aArray[$i][10] ;Gender $sR11 = $aArray[$i][11] ;Phone ControlSend("[CLASS:MagicFS]", "", "", ("{F8}")) Sleep (500) ControlSend("[CLASS:MagicFS]", "", "", ("{F8}")) Sleep (500) ControlSend("[CLASS:MagicFS]", "", "", ("N")) ControlSend("[CLASS:MagicFS]", "", "", ("{TAB}")) Sleep (3000) ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR1 & @CR) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "", ("{TAB}")) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR2 & @CR) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "", ("{TAB}")) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR6& @CR) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "", ("{TAB}")) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR7 & @CR) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR8 & @CR) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR9 & @CR) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR11& @CR) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR5 & @CR) ;Email7 Sleep (200) ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR5 & @CR) ;Email Sleep (200) ControlSend("[CLASS:MagicFS]", "", "", (FormatDate($sR4) & @CR)) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR10 & @CR) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR3 & @CR) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "", ("{F8}")) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "", ("P")) Sleep (200) $sBox = MsgBox($MB_OK & $MB_TOPMOST,"Patient Portal","After you have entered the patient push OK") Sleep (300) ControlSend("[CLASS:MagicFS]", "", "", ("{F8 3}")) Sleep (200) ControlSend("[CLASS:MagicFS]", "", "", ("{ESC}")) Sleep (200) ControlSend("[CLASS:MagicFS Modal(3)]", "", "", ("{ENTER}")) $r = $r + 1 If $r > $sBox Then Exit Endif Next EndFunc
    • rcmaehl
      By rcmaehl
      Alright, currently I'm trying to merge two loops:
       
      Local $aArray[99][13] For $iLoop = 1 to 100 $aArray[$iLoop - 1][0] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration", $iLoop) If @error <> 0 Then ReDim $aArray[$iLoop - 1][13] ExitLoop EndIf Next For $iLoop1 = 0 to UBound($aArray, 1) - 1 For $iLoop2 = 1 to 12 $aArray[$iLoop1][$iLoop2] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration\" & $aArray[$iLoop1][0], $iLoop2) If @error <> 0 Then ExitLoop Next Next  
      into one. Here's what I have so far:
       
      Local $aArray[99][13] For $iLoop1 = 0 to UBound($aArray, 1) - 1 For $iLoop2 = 0 to 12 ConsoleWrite("Loop1 = " & $iLoop1 & ", Loop2 = " & $iLoop2 & @CRLF) If $iLoop2 = 0 Then $aArray[$iLoop1][0] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration", $iLoop1 + 1) If @error <> 0 Then ReDim $aArray[$iLoop1 + 1][13] ExitLoop EndIf Else $aArray[$iLoop1][$iLoop2] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration\" & $aArray[$iLoop1][0], $iLoop2) If @error <> 0 Then ExitLoop EndIf Next Next And it keeps error-ing out trying to exceed the dimension range of the array. Does the Loop not recheck the size of the array after the original check or am I doing something else wrong.
       
      Thanks.