# excel table with arrary and for next loop for scheduling problems_2

## Recommended Posts

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

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. The second They are chose random first to eat.

3. Third  They are chose random first to eat.

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

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

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

Edited by Peggy
##### Share on other sites
• Moderators

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

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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 on other sites

Hi Melba23,

- 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

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

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

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

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.

we hope result is  ..

Edited by Peggy
##### Share on other sites
• Moderators

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
Next

; Create array to hold display

; Create array to hold group data
Local \$iRow = 0
For \$i = 0 To UBound(\$aData) - 1
If \$i Then
\$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
For \$j = 2 To \$aData[\$i][1] + 1
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
\$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

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

Open spoiler to see 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 on other sites

Hi Melba23,

That is the  fuction I want, thank you for helping me so much ,I'm so happy!!
.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~!!

##### Share on other sites
• Moderators

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

Open spoiler to see 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

## Create an account

Register a new account

• ### Similar Content

• By mmoalem
Hi all - I have created a simple script that turn on cctv software (contacam)  when my phone does not ping back (when I'm out of range of home network)
#include <MsgBoxConstants.au3> \$iPing = 0 For \$i = 5 To 1 Step -1 ; this 5 loops cycle is just for testing - please ignnore - when complete it will be an endless loop Example() Sleep(120000) Next Func Example() ; Ping the phone. \$iPing = Ping("192.168.1.102") If \$iPing Then ; If a value greater than 0 was returned then turn off camera. _endCCTV() Else _startCCTV() ; If a value of 0 was returned then turn on camera. EndIf EndFunc ;==>Example Func _startCCTV() ShellExecute("C:\contacam capture\FJ Camera\CAMERA.bat", "on") Sleep(10000) ShellExecute("C:\contacam capture\FJ Camera\CAMERA_REC_SENSITIVITY.bat", "50") EndFunc Func _endCCTV() ShellExecute("C:\contacam capture\FJ Camera\CAMERA_REC_SENSITIVITY.bat", "0") Sleep(10000) ShellExecute("C:\contacam capture\FJ Camera\CAMERA.bat", "off") EndFunc

the problem I have is that in this format the script run the bat file that turn on the camera (or off) everytime the ping runs but obviously once the ping returns 0 and the camera starts I only want to run the bat on ping NOT 0 (turn off camera)

• include-once #include <File.au3> #include <Excel.au3> #include <String.au3> #include <MsgBoxConstants.au3> Local \$file = "TEST.log" FileOpen(\$file, 0) \$TTLPax = 1 For \$i = _FileCountLines(\$file) - \$TTLPax to _FileCountLines(\$file) \$line = FileReadLine(\$file, \$i) Global \$TktNo = StringMid(\$line, 8, 13) ; reads 13 characters from \$Line starting from the 8th character msgbox(0,'',\$TktNo) ; This is just for me to debug For \$NoOfPax = 1 to 2 local \$TTLSeg = 2 msgbox(0,'',\$TTLSeg) msgbox(0,'',"7ABC"& \$TktNo &"'N"& \$NoOfPax &".1'C1,2'S1,2'B") ; This makes 7ABC1234567890123'N1.1'C1,2'S1,2'B ;But in the next loop I want the value to be 7ABC1234567890333'N2.1'C1,2'S1,2'B Next ExitLoop Next *TEST
JAMES BAKER
1.NYC-23JAN
2.TJ 1234567890123
3.TJ 1234567890333
I am reading a file with last 5 lines as above. I want to be able to loop through and pick the values as follows
1- Pick 1234567890123
2- Use it to build a format with N1.1
3- Pick 1234567890333
2- Use it to build a format with N2.1
Need help with the loop. Thank You

• For \$A1 = 12 To 11 + \$Total For \$B1 = 1 To (\$oExcel.Application.Cells(\$A1,6).Value) ; This value is from the Excel file. It can be from 1 - 9. For \$N1 = 7 To ??? ; This is based on the value of \$B1 ((1 = 7, 2 = 17, 3 = 27, 4 = 37, 5 = 47) Send("-"& (\$oExcel.Application.Cells(\$A1,\$N1).Value) &"/"& (\$oExcel.Application.Cells(\$A1,\$N1+1).Value)) Sleep(400) Send("{ENTER}") Sleep(700) Next Next Next I am not able to figure how to loop \$N1 as follows
If the Value of \$B1 = 1 then \$N1 = 7
If the Value of \$B1 = 2 then \$N1 = 17
If the Value of \$B1 = 3 then \$N1 = 27
If the Value of \$B1 = 4 then \$N1 = 37
The value of \$N1 comes from \$B1 where 1 = 7, 2 = 17, 3 = 27, 4 = 37, 5 = 47)
Thank You
• By ssah8
So im creating a bot that logs in on a website. The website got a dropdown menu, and I have to choose the right one to login (Student)
#include <IE.au3>
#inculude <Inet.au3>
\$oIE = _IECreate("<snip>")
\$dropdown = _IEGetObjByName(\$oIE, "usertype")
_IEPropertySet(\$Name, 'innerText', 'censored')
_IEPropertySet(\$Pass, 'innerText', 'censored')
_IEPropertySet(\$dropdown, 'innerText', 'Student') <------ How do I make the dropdown list select "Student"?

• By Garrik
Hi guys!

I need some help here, is there a way to use Random with While?
I need this script to run in between 1 and 4 times but I dont know how to do it, can you please help me?

dim \$i=1
While \$i<=4
Sleep(3000)
Send("{LWINDOWN}r{LWINUP}")
Sleep(3000)
Send("C:\Users\123\Catalogos\tags.txt{ENTER}")
Sleep(3000)
WinActivate("tags: Bloc de notas","")
Sleep(3000)
Send("{SHIFTDOWN}{END}{SHIFTUP}{CTRLDOWN}c{CTRLUP}{DEL}{DEL}")
Sleep(3000)
Send("{CTRLDOWN}g{CTRLUP}{ALTDOWN}{F4}{ALTUP}")
Sleep(3000)
Send("{CTRLDOWN}v{CTRLUP}{SPACE}")
\$i=\$i+1
WEnd
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...