Jump to content

Formatting help on multiple if elseif and else and if statements


Go to solution Solved by computergroove,

Recommended Posts

Here is my train of logic:

Create a GUI Window and listen for user input

1. If userinput doesnt have valid data then send a gui error message.

2. If userinput has valid data then perform action A (play a specific video)

3. If there is no user input and the last video has completed playing then start playing a random video.

Things that I need to happen.

1. No matter what is happening I need the active window to be the "Video Player" so someone can at all times scan a new barcode to start playing a new video.

2. If a barcode is scanned and a video starts to play, the only reason that the video stops before it is done is if a user scans another barcode.

*There is not a standard video length. They are all random lengths and I want a random video to start playing 20 seconds after the last user input or 20 seconds after the last video scanned has finished playing. The random videos can then play back to back (no 20 second delay between videos).

While 1
    FileDelete("C:\BestOptionBeta\Videos\*.sfl");Removes ghost files from teh Videos Folder - I think they are error logs from crashed MPC
    $msg = GUIGetMsg();listen to the GUI Window for a barcode to be scanned
    Switch $msg
        Case $GUI_EVENT_CLOSE
            FileClose(@ScriptDir & "\" & "Videos.ini")
            Exit
        Case $edit_field
            $user_input = GUICtrlRead($edit_field); sets $user_input to whatever was typed in the edit box
            $video_file = (@ScriptDir & "\Videos\" & IniRead("Videos.ini", "Videos", $user_input, "no entry"))
            If IniRead("Videos.ini", "Videos", $user_input, "no entry") = "no entry" Then;If a barcode is not found then send a message saying do
                MsgBox(262144, "Code not found", "The Barcode you entered "&$user_input&" does not have a video.",2);Error message on screen for user that will close in 2 seconds
                WinActivate("Video Player") ; makes the scan barcode user input window the active window
                GUICtrlSetData($edit_field, "");erases data in the user input field
            Else
                GUICtrlSetData($edit_field, "");erases input in gui window
                ProcessClose("mpc-hc64.exe")
                Sleep(100)
                Run(@ScriptDir & '\MPC-HC\mpc-hc64.exe /play /fullscreen /close "' & $video_file & '"')
                WinActivate("Video Player")
                FileDelete("C:\BestOptionBeta\Videos\*.sfl");Removes ghost files from teh Videos Folder - I think they are error logs from crashed MPC
            ElseIf
                If TimerDiff($timer) > 20000 Then
                    Local $aFileList = _FileListToArray(@ScriptDir & "\Videos", "*.mpg");reads all files from videos directory and places them into a numbered 1d array
                    local $arrNum = Ubound($aFileList,1);counts the total number of entrys in the array
                    Local Const $iRandom = Random(1,$aFileList[0],1);creates a random number between 1 and the counted number of array list items. $aFile[0] is the first entry in the array which is a count of all the items in the array
                    Local $RandomVideo = ('"' &@ScriptDir & "\Videos\" & $aFileList[$iRandom]& '"');creates a random video file name with " around it
                    Local $RandomCommandPath = (@ScriptDir & "\MPC-HC\mpc-hc64.exe /play /fullscreen /close " & $RandomVideo);plays random file from videos
                            GUICtrlSetData($edit_field, "");erases input in gui window
                            FileDelete("C:\BestOptionBeta\Videos\*.sfl");Removes ghost files from teh Videos Folder - I think they are error logs from crashed MPC
                            Run ($RandomCommandPath)
                            If ProcessExists("mpc-hc64.exe")Then
                                Sleep(500)
                                WinActivate("Video Player")

                            EndIf
                EndIf
            EndIf
    EndSwitch

Im getting a lot of errors in the compiler about REF: Missing Wend, Missing EndSwitch, Missing EndIf. Please help.

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

  • Developers

Just run it through Tidy and it shows this issue:

While 1
    FileDelete("C:\BestOptionBeta\Videos\*.sfl");Removes ghost files from teh Videos Folder - I think they are error logs from crashed MPC
    $msg = GUIGetMsg();listen to the GUI Window for a barcode to be scanned
    Switch $msg
        Case $GUI_EVENT_CLOSE
            FileClose(@ScriptDir & "\" & "Videos.ini")
            Exit
        Case $edit_field
            $user_input = GUICtrlRead($edit_field); sets $user_input to whatever was typed in the edit box
            $video_file = (@ScriptDir & "\Videos\" & IniRead("Videos.ini", "Videos", $user_input, "no entry"))
            If IniRead("Videos.ini", "Videos", $user_input, "no entry") = "no entry" Then;If a barcode is not found then send a message saying do
                MsgBox(262144, "Code not found", "The Barcode you entered " & $user_input & " does not have a video.", 2);Error message on screen for user that will close in 2 seconds
                WinActivate("Video Player") ; makes the scan barcode user input window the active window
                GUICtrlSetData($edit_field, "");erases data in the user input field
            Else
                GUICtrlSetData($edit_field, "");erases input in gui window
                ProcessClose("mpc-hc64.exe")
                Sleep(100)
                Run(@ScriptDir & '\MPC-HC\mpc-hc64.exe /play /fullscreen /close "' & $video_file & '"')
                WinActivate("Video Player")
                FileDelete("C:\BestOptionBeta\Videos\*.sfl");Removes ghost files from teh Videos Folder - I think they are error logs from crashed MPC
;### Tidy Error: If/ElseIf statement without a then..
            ElseIf
                If TimerDiff($timer) > 20000 Then
                    Local $aFileList = _FileListToArray(@ScriptDir & "\Videos", "*.mpg");reads all files from videos directory and places them into a numbered 1d array
                    Local $arrNum = UBound($aFileList, 1);counts the total number of entrys in the array
                    Local Const $iRandom = Random(1, $aFileList[0], 1);creates a random number between 1 and the counted number of array list items. $aFile[0] is the first entry in the array which is a count of all the items in the array
                    Local $RandomVideo = ('"' & @ScriptDir & "\Videos\" & $aFileList[$iRandom] & '"');creates a random video file name with " around it
                    Local $RandomCommandPath = (@ScriptDir & "\MPC-HC\mpc-hc64.exe /play /fullscreen /close " & $RandomVideo);plays random file from videos
                    GUICtrlSetData($edit_field, "");erases input in gui window
                    FileDelete("C:\BestOptionBeta\Videos\*.sfl");Removes ghost files from teh Videos Folder - I think they are error logs from crashed MPC
                    Run($RandomCommandPath)
                    If ProcessExists("mpc-hc64.exe") Then
                        Sleep(500)
                        WinActivate("Video Player")

                    EndIf
                EndIf
            EndIf
    EndSwitch
;### Tidy Error -> while is never closed in your script.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Just run it through Tidy and it shows this issue:

While 1
    FileDelete("C:\BestOptionBeta\Videos\*.sfl");Removes ghost files from teh Videos Folder - I think they are error logs from crashed MPC
    $msg = GUIGetMsg();listen to the GUI Window for a barcode to be scanned
    Switch $msg
        Case $GUI_EVENT_CLOSE
            FileClose(@ScriptDir & "\" & "Videos.ini")
            Exit
        Case $edit_field
            $user_input = GUICtrlRead($edit_field); sets $user_input to whatever was typed in the edit box
            $video_file = (@ScriptDir & "\Videos\" & IniRead("Videos.ini", "Videos", $user_input, "no entry"))
            If IniRead("Videos.ini", "Videos", $user_input, "no entry") = "no entry" Then;If a barcode is not found then send a message saying do
                MsgBox(262144, "Code not found", "The Barcode you entered " & $user_input & " does not have a video.", 2);Error message on screen for user that will close in 2 seconds
                WinActivate("Video Player") ; makes the scan barcode user input window the active window
                GUICtrlSetData($edit_field, "");erases data in the user input field
            Else
                GUICtrlSetData($edit_field, "");erases input in gui window
                ProcessClose("mpc-hc64.exe")
                Sleep(100)
                Run(@ScriptDir & '\MPC-HC\mpc-hc64.exe /play /fullscreen /close "' & $video_file & '"')
                WinActivate("Video Player")
                FileDelete("C:\BestOptionBeta\Videos\*.sfl");Removes ghost files from teh Videos Folder - I think they are error logs from crashed MPC
;### Tidy Error: If/ElseIf statement without a then..
            ElseIf
                If TimerDiff($timer) > 20000 Then
                    Local $aFileList = _FileListToArray(@ScriptDir & "\Videos", "*.mpg");reads all files from videos directory and places them into a numbered 1d array
                    Local $arrNum = UBound($aFileList, 1);counts the total number of entrys in the array
                    Local Const $iRandom = Random(1, $aFileList[0], 1);creates a random number between 1 and the counted number of array list items. $aFile[0] is the first entry in the array which is a count of all the items in the array
                    Local $RandomVideo = ('"' & @ScriptDir & "\Videos\" & $aFileList[$iRandom] & '"');creates a random video file name with " around it
                    Local $RandomCommandPath = (@ScriptDir & "\MPC-HC\mpc-hc64.exe /play /fullscreen /close " & $RandomVideo);plays random file from videos
                    GUICtrlSetData($edit_field, "");erases input in gui window
                    FileDelete("C:\BestOptionBeta\Videos\*.sfl");Removes ghost files from teh Videos Folder - I think they are error logs from crashed MPC
                    Run($RandomCommandPath)
                    If ProcessExists("mpc-hc64.exe") Then
                        Sleep(500)
                        WinActivate("Video Player")

                    EndIf
                EndIf
            EndIf
    EndSwitch
;### Tidy Error -> while is never closed in your script.

Jos

 

I didnt know there was a Tidy, Thanks,

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

  • Developers

I didnt know there was a Tidy, Thanks,

Just install the Full SciTE4AutoIt3 separate installer and do Ctrl+T in SciTE.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Solution

lol I think I got it. I was already looking at this before I posted. I added

If IniRead("Videos.ini", "Videos", $user_input, "no entry") <> "no entry" Then

and it looks like it worked. Thanks.

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

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