Jump to content
• Sign Up

# 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 this 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

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 this post

##### Share on other sites

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

- 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

Thanks for your  great help!!

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

Thanks for your  great help!!

Edited by Peggy

#### Share this 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

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

#### Share this 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

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

• 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
• By Inpho
Hi All,
I intend on keeping custom functions/UDFs (works in progress) here; if anyone wants to use any code, feel free.
String functions:
#AutoIt3Wrapper_AU3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include-once ; #FUNCTION# ==================================================================================================================== ; Name ..........: _DateTimeGet ; Description ...: Returns the date and time formatted for use in sortable filenames, logs, listviews, etc. ; Syntax ........: _DateTimeGet(iType = 1[, \$bHumanFormat = False]) ; Parameters ....: \$iType - [optional] an integer value. Default is 1. ; 1 - Date and time in file-friendly format; 20190115_113756 ; 2 - Date in file-friendly format; 20190115 ; 3 - Time in file friendly format; 113756 ; \$bHumanFormat - [optional] a boolean value. Default is False. ; True - Includes slashes in the date and colons in the time with a space inbetween ; False - No slashes or colons included with an underscore inbetween ; Return values .: Success - String ; Failure - Sets @error to non-zero and returns an empty string ; Author ........: Sam Coates ; =============================================================================================================================== Func _DateTimeGet(\$iType = 1, \$bHumanFormat = False) If \$iType < 1 Or \$iType > 3 Then Return (SetError(-1, 0, "")) ;; Param1: ;; 1 = Date and time in file friendly format: 20190115_113756 ;; 2 = Date in file friendly format: 20190115 ;; 3 = Time in file friendly format: 113756 ;; Param2: ;; True = Use human-readable format: 15/01/2019 11:37:56 Local \$sTime = @HOUR & ":" & @MIN & ":" & @SEC Local \$sDate = @MDAY & "/" & @MON & "/" & @YEAR If \$iType = 1 Then If \$bHumanFormat = False Then \$sTime = StringReplace(\$sTime, ":", "") \$sDate = StringReplace(\$sDate, "/", "") \$sDate = StringTrimLeft(\$sDate, 4) & StringMid(\$sDate, 3, 2) & StringLeft(\$sDate, 2) Return (\$sDate & "_" & \$sTime) Else Return (\$sDate & " " & \$sTime) EndIf ElseIf \$iType = 2 Then If \$bHumanFormat = False Then \$sDate = StringReplace(\$sDate, "/", "") \$sDate = StringTrimLeft(\$sDate, 4) & StringMid(\$sDate, 3, 2) & StringLeft(\$sDate, 2) EndIf Return (\$sDate) ElseIf \$iType = 3 Then If \$bHumanFormat = False Then \$sTime = StringReplace(\$sTime, "/", "") EndIf Return (\$sTime) EndIf EndFunc ;==>_DateTimeGet ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFileExtension ; Description ...: Returns a file extension from a filename/FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFileExtension(\$sPath) ; Parameters ....: \$sPath - a string value. ; Return values .: Success - String ; Failure - Empty string as returned from StringTrimLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFileExtension(\$sPath) Return (StringTrimLeft(\$sPath, StringInStr(\$sPath, ".", 0, -1))) EndFunc ;==>_FileToFileExtension ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFileName ; Description ...: Returns a filename from a FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFileName(\$sPath[, \$bIncludeExtension = True]) ; Parameters ....: \$sPath - a string value. ; \$bIncludeExtension - [optional] a boolean value. Default is True. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFileName(\$sPath, \$bIncludeExtension = True) Local \$sReturn = StringTrimLeft(\$sPath, StringInStr(\$sPath, "\", 0, -1)) If \$bIncludeExtension = False Then \$sReturn = StringLeft(\$sReturn, StringInStr(\$sReturn, ".", 0, -1) - 1) Return (\$sReturn) EndFunc ;==>_FileToFileName ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFilePath ; Description ...: Returns a folder path from a FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFilePath(\$sPath) ; Parameters ....: \$sPath - a string value. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFilePath(\$sPath) Return (StringLeft(\$sPath, StringInStr(\$sPath, "\", 0, -1) - 1)) EndFunc ;==>_FileToFilePath ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringLeft ; Description ...: Searches for a string inside a string, then removes everything on the right of that string ; Syntax ........: _StringLeft(\$sString, \$sRemove[, \$iCaseSense = 0, \$iOccurrence = 1]) ; Parameters ....: \$sString - a string value. The string to search inside. ; \$sRemove - a string value. The string to search for. ; \$iCaseSense - an integer value. Flag to indicate if the operations should be case sensitive. ; \$iOccurrence - an integer value. Which occurrence of the substring to find in the string. Use a ; negative occurrence to search from the right side. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringLeft(\$sString, \$sRemove, \$iCaseSense = 0, \$iOccurrence = 1) Return (StringLeft(\$sString, StringInStr(\$sString, \$sRemove, \$iCaseSense, \$iOccurrence) - 1)) EndFunc ;==>_StringLeft ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringRandom ; Description ...: Returns a string of random characters ; Syntax ........: _StringRandom(\$iAmount[, \$iType = 1]) ; Parameters ....: \$iAmount - an integer value. Length of returned string ; \$iType - [optional] an integer value. Default is 1. ; 1 - Return digits (0-9) ; 2 - Return hexadecimal (0-9, A - F) ; 3 - Return Alphanumeric upper (0-9, A - Z) ; 4 - Return Alphanumeric (0-9, A - Z, a - z) ; 5 - Return Alpha upper (A - Z) ; 6 - Return Alpha (A - Z, a - z) ; Return values .: Success - String ; Failure - Empty string and @error flag as follows: ; @error : 1 - \$iAmount is not a positive integer ; 2 - \$iType is out of bounds ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringRandom(\$iAmount, \$iType = 1) If \$iAmount < 1 Or IsInt(\$iAmount) = 0 Then Return (SetError(-1, 0, "")) Local \$sString = "" Local \$iRandomLow = 1, \$iRandomHigh = 62 #Tidy_Off Local Static \$aCharId[63] = [0, Chr(48), Chr(49), Chr(50), Chr(51), Chr(52), Chr(53), Chr(54), Chr(55), Chr(56), Chr(57), Chr(65), Chr(66), Chr(67), _ Chr(68), Chr(69), Chr(70), Chr(71), Chr(72), Chr(73), Chr(74), Chr(75), Chr(76), Chr(77), Chr(78), Chr(79), Chr(80), _ Chr(81), Chr(82), Chr(83), Chr(84), Chr(85), Chr(86), Chr(87), Chr(88), Chr(89), Chr(90), Chr(97), Chr(98), Chr(99), _ Chr(100), Chr(101), Chr(102), Chr(103), Chr(104), Chr(105), Chr(106), Chr(107), Chr(108), Chr(109), Chr(110), Chr(111), _ Chr(112), Chr(113), Chr(114), Chr(115), Chr(116), Chr(117), Chr(118), Chr(119), Chr(120), Chr(121), Chr(122)] #Tidy_On If \$iType = 1 Then ;; digits: 1 - 10 \$iRandomHigh = 10 ElseIf \$iType = 2 Then ;; hexadecimal: 1 - 16 \$iRandomHigh = 16 ElseIf \$iType = 3 Then ;; alnumupper: 1 - 36 \$iRandomHigh = 36 ElseIf \$iType = 4 Then ;; alnum: 1 - 62 \$iRandomHigh = 62 ElseIf \$iType = 5 Then ;; alphaupper: 11 - 36 \$iRandomLow = 11 \$iRandomHigh = 36 ElseIf \$iType = 6 Then ;; alpha: 11 = 62 \$iRandomLow = 11 \$iRandomHigh = 62 Else Return (SetError(-2, 0, "")) EndIf For \$i = 1 To \$iAmount \$sString &= \$aCharId[Random(\$iRandomLow, \$iRandomHigh, 1)] ;; append string with corresponding random character from ascii array Next Return (\$sString) EndFunc ;==>_StringRandom ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringTrimLeft ; Description ...: Searches for a string inside a string, then removes everything on the left of that string ; Syntax ........: _StringTrimLeft(\$sString, \$sRemove[, \$iCaseSense = 0, \$iOccurrence = 1]) ; Parameters ....: \$sString - a string value. The string to search inside. ; \$sRemove - a string value. The string to search for. ; \$iCaseSense - an integer value. Flag to indicate if the operations should be case sensitive. ; \$iOccurrence - an integer value. Which occurrence of the substring to find in the string. Use a ; negative occurrence to search from the right side. ; Return values .: Success - String ; Failure - Empty string as returned from StringTrimLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringTrimLeft(\$sString, \$sRemove, \$iCaseSense = 0, \$iOccurrence = 1) Return (StringTrimLeft(\$sString, StringInStr(\$sString, \$sRemove, \$iCaseSense, \$iOccurrence) + StringLen(\$sRemove) - 1)) EndFunc ;==>_StringTrimLeft Examples:
ConsoleWrite(_StringRandom(100, 6) & @CRLF) ConsoleWrite(_StringTrimLeft("C:\Windows\System32\cmd.exe", "C:\Windows\System32\") & @CRLF) ConsoleWrite(_StringLeft("C:\Windows\System32\cmd.exe", "cmd.exe") & @CRLF) ConsoleWrite(_FileToFileName("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_FileToFilePath("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_FileToFileExtension("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_StringRandom(6, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(6, 4)& @CRLF)
• By VinMe
I am unable compare two 1d arrays  and to assign values to third array \$aDSloc1, Please help me out
Local \$aDSloc1[\$LastRow]
For \$i = 1 To \$LastRow
For \$j = 1 To \$LastRow1
If \$aDSlist1[\$i]== \$aLocDS1[\$j] Then
\$aDSloc1[\$i] = \$aDSloc1[\$i]+"," + \$aLocNr1[\$j]
EndIf
Next
Next
• By ThePoro
Hi everyone.
I want to ask about this :
I want it runs from 1 to 100 and It opens 10 firefox profiles then access youtube. After I close a firefox window, the loop runs and wait for another window close until loop ends
I have a loop like this.
Func launch() Local \$from = Int(GUICtrlRead(\$input1)) Local \$to = Int(GUICtrlRead(\$input2)) If \$to <> "" Then While \$from <= \$to Local \$profile = \$to _RunDos("start firefox.exe -p " & \$profile & " -no-remote youtube.com") \$to=\$to+1 WEnd Else Local \$profile = \$to _RunDos("start firefox.exe -p " & \$profile & " -no-remote youtube.com") EndIf EndFunc Is there any solution?
Thank you!
• By Rhidlor
First off, the project I'm working on revolves around AS/400 "Client Access software", it's foundation is directly influenced by the thread linked at the bottom of this post. Moving on, to explain the problem I'm facing; my project utilizes an infinite While loop and automatically performs semi-hard coded monotonous tasks to save users time and effort, the problem is, occasionally and unexpectedly "Display Messages" will popup and the core script will continue executing instead of dismissing said message and the script "breaks". As a countermeasure I've added some code to the While loop in an effort to intervene and dismiss these display messages before the core script has a chance to do anything... however it doesn't work. I hope I didn't do too bad of a job explaining that.
So I think my question is: How can I temporarily "pause" the core script when these messages spontaneously appear?
The only other solution I thought of would be to check if a display message has appeared before executing every line of code but that obviously isn't very practical.
Any and all help is greatly appreciated!
Thanks

;Loop to keep script running and handle display messages While 1 dismiss_display_messages() Sleep(50) WEnd ;Function to dismiss display messages Func dismiss_display_messages() If \$ps.SearchText("Display Messages") Then \$ps.SendKeys("[enter]", 8, 1) ;This while loop waits until the display message has disappeared to resume the core script While \$ps.SearchText("Display Messages") Sleep(100) WEnd EndIf EndFunc

×

• Wiki

• Back

• #### Beta

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