Jump to content

Recommended Posts

Posted

Hi all,

can anyone tell me why this code does not run as expected.

;Pick out last 2 characters 
Local $sString = StringRight($sText, 2) ; Retrieve 2 characters from the right of the string.

If $sString == 'RE' Then
   $OutputDir = 'C:\Folder1'
 
ElseIf $sString == 'RF' Then
   $OutputDir = 'C:\Folder2'
  
ElseIf $sString == '9J' or 'JA' or 'JB' or 'JC' or 'S1' Then
   $OutputDir = 'C:\Folder3'
  
ElseIf $sString == '6E' or '7E' or '8E' Then
   $OutputDir = 'C:\Folder4'

Else
   MsgBox($MB_SYSTEMMODAL, "", "Type Not Recognised") ;unrecognised part, exit program
   Exit
EndIf

Its supposed to work like this:

1) get last two characters from string

2) If characters match change  $OutputDir

3)If none of the characters match produce error message.

It sort of works but the message box error message never seems to trigger regardless.

thanks

Posted (edited)

this is not what you think:

ElseIf $sString == '9J' or 'JA' or 'JB' or 'JC' or 'S1' Then

this does not translate to English as if string equals "9J" or string equals "JA" etc.

it translates to if string equals the result of the mathematical operation ("9J" Or "JA" etc.) - which i have no idea what that is, but most definitely not what you meant.

use Switch...Case...EndSwitch instead of If..ElseIf...Then...EndIf.

Edited by orbs

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

WinPose - simultaneous fluent move and resize

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

Magic Math - a math puzzle

Demos:

Title Bar Menu - click the window title to pop-up a menu

 

Posted

it translates to if string equals the result of the mathematical operation ("9J" Or "JA" etc.) - which i have no idea what that is, but most definitely not what you meant.

 

actually, my mistake. it translates to if string equals "9J" or the boolean result of "JA" (which is always True) etc.

still, this suggestion still applies:

use Switch...Case...EndSwitch instead of If..ElseIf...Then...EndIf.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

WinPose - simultaneous fluent move and resize

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

Magic Math - a math puzzle

Demos:

Title Bar Menu - click the window title to pop-up a menu

 

Posted

Switch $sString
    Case 'RE'
        $OutputDir = 'C:\Folder1'
    Case 'RF'
        $OutputDir = 'C:\Folder2'
    Case '9J','JA','JB','JC','S1'
        $OutputDir = 'C:\Folder3'
    Case '6E','7E','8E'
        $OutputDir = 'C:\Folder4'
    Case Else
        MsgBox($MB_SYSTEMMODAL, "", "Type Not Recognised") ;unrecognised part, exit program
        Exit
EndSwitch

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

WinPose - simultaneous fluent move and resize

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

Magic Math - a math puzzle

Demos:

Title Bar Menu - click the window title to pop-up a menu

 

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
×
×
  • Create New...