Jump to content

Strange problem with case statements


Recommended Posts

I'm trying to install a series of files, and I'm using select/case to stop it if any of the installs fail.

In the code below, $App('Path_IcoSetup') is pointing to the path for the installed icon file - in this case, it's a subfolder under 'Program Files'.

When I try this, the file does not get installed, and the error is displayed:

Case Not FileInstall('c:\temp\setup.ico', $App('Path_IcoSetup'), 1)
      MsgBox(0, '', 'Unable to install: ' & $App('Path_IcoSetup'))

Just for the hell of it, I tried this, and much to my surprise, it worked:

Case True 
      If Not FileInstall('c:\temp\setup.ico', $App('Path_IcoSetup'), 1) Then
        MsgBox(0, '', 'Unable to install: ' & $App('Path_IcoSetup'))
      Else
        ContinueCase
      EndIf

This code has been around for about a week now, and every other time I tested it, the first example worked. Any ideas why it wouldn't be working now, and why the second one is?

Thanks, in advance.

edit: modified paths.

Edited by aGorilla
Link to comment
Share on other sites

If you are FileInstalling to a folder path, then ensure you use a trailing backslash.

ContinueCase may not suit your purpose as it skips checking the next case statement and simply runs the code after the case statement as the below will show.

Select
    Case Not 1
        MsgBox(0, 'False', '1')
    Case Not 1
        MsgBox(0, 'False', '2')
    Case Not 0
        MsgBox(0, 'True', '3')
        ContinueCase; will not check the state of next case statement
        ; but ContinueCase will run the next MsgBox anyway.
    Case Not 1
        MsgBox(0, 'False', '4')
EndSelect

:)

Link to comment
Share on other sites

If you are FileInstalling to a folder path, then ensure you use a trailing backslash.

ContinueCase may not suit your purpose as it skips checking the next case statement and simply runs the code after the case statement as the below will show.

Select
    Case Not 1
        MsgBox(0, 'False', '1')
    Case Not 1
        MsgBox(0, 'False', '2')
    Case Not 0
        MsgBox(0, 'True', '3')
        ContinueCase; will not check the state of next case statement
        ; but ContinueCase will run the next MsgBox anyway.
    Case Not 1
        MsgBox(0, 'False', '4')
EndSelect

:)

I always wondered why there is a ContinueCase but there isn't something like 'ExitCase',it would save me lots of code lines and make my code much more readable. Edited by danielkza
Link to comment
Share on other sites

ContinueCase may not suit your purpose as it skips checking the next case statement and simply runs the code after the case statement as the below will show.

I managed to solve my problem with a bit of rewriting, but I bet that was it. Why doesn't it check the next case statement? That seems like the logical thing to do after a 'continue'.

I always wondered why there is a ContinueCase but there isn't something like 'ExitCase',it would save me lots of code lines and make my code much more readable.

That's essentially what I was trying to do. I ended up using a wrapper function to pull it off. I like the one-liner effect, and if everthing works, it just sort of 'falls through':

Func Install()
  Select
    Case Not DoOrWarn(DirCreate($App('Dir_File')), $App('Err_MkDir') & $App('Dir_File'))
    Case Not DoOrWarn(DirCreate($App('Dir_Menu')), $App('Err_MkDir') & $App('Dir_Menu'))
    Case Not DoOrWarn(DirCreate($App('Dir_Boot')), $App('Err_MkDir') & $App('Dir_Boot'))
    Case Not DoOrWarn(DirCreate($App('Dir_Data')), $App('Err_MkDir') & $App('Dir_Data'))
    Case Else
      $App('App_Installed') = True
  EndSelect
  ...
EndFunc

Func DoOrWarn($act, $err_msg)
  Local $test = (($act > 0) and not @error)
  If Not $test Then MsgBox(0, 'Warning:', $err_msg)
  Return $test
EndFunc

Edit: If the action fails, DoOrWarn returns false, which exits the case statement (by falling into that branch, which is empty). Just in 'case' it wasn't clear :)

Edited by aGorilla
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...