IF Case Statement can't seem to get working?

This is my code that i wrote awhile ago but i’m not wanted to hard code in my “SKU” numbers i want it to pick up off a name, say it was for Apples and i had Apples black, Apples Blue, Apples Red … etc. and i wanted to pick up every apple and change a price on it.

Heres my code at the moment

If ( (Year(docThis.PF_Dates_BuyIn(0))) )=>2009 Then

	Select Case sSKU

	Case 11829,11834,11832,11833,11831,11986,11987,12026,11908,11964,11830,12092,12133,12273,12274,12275,12276,12277,12493,12494,12495,12496 :	

		Call docThis.ReplaceItemValue(sPrefix+"Product_Royalty"+sLine, "7")

	Case 11983,12047,11981,11975,12046,11944,12220,11982,11980,11943,12389,12390,12507,12508,12490,12491,12492 :	

		Call docThis.ReplaceItemValue(sPrefix+"Product_Royalty"+sLine, "8")	

	Case Else    :  

		Call docThis.ReplaceItemValue(sPrefix+"Product_Royalty"+sLine, docProducts.p_Royalty(0))

	End Select

Else

	Call docThis.ReplaceItemValue(sPrefix+"Product_Royalty"+sLine, docProducts.p_Royalty(0))

	

End If

Here you can see my sSku(the 5 digit numbers) are the unique IDs for the Apples but i dont want to hard code them in like this as more sSku’s can come in and are deleted so i would want to change it to something like this:

If ( (Year(docThis.PF_Dates_BuyIn(0))) )=>2009 Then

	Select Case sSKU

	Case 11829,11834,11832,11833,11831,11986,11987,12026,11908,11964,11830,12092,12133,12273,12274,12275,12276,12277,12493,12494,12495,12496 :	

		Call docThis.ReplaceItemValue(sPrefix+"Product_Royalty"+sLine, "7")

	Case "*Apples*" :	

		Call docThis.ReplaceItemValue(sPrefix+"Product_Royalty"+sLine, "8")	

	Case Else    :  

		Call docThis.ReplaceItemValue(sPrefix+"Product_Royalty"+sLine, docProducts.p_Royalty(0))

	End Select

Else

	Call docThis.ReplaceItemValue(sPrefix+"Product_Royalty"+sLine, docProducts.p_Royalty(0))

	

End If

i have put in *'s as i want it to pickup if it was black Apple or Apple Black.

Cheers

Chris.

Subject: rather than hard code the mapping

I would do this via configuration data

Your code is difficult to read on screen

but it looks to me that you need 2 types of data

a) mapping from the fruit name to a royalty level code

b) mapping from royalty level code to actual royalty value

You would need forms for (a) and (b)

views to create the documents

views to lookup

Once in place you could then code to use the lookup views and alter the data

Perhaps this sounds like a lot of work

but it means that if you add a new fruit there is no need for code changes, only data

AND

the views of config documents make it easy to see what the current settings actually are

This might be less work for you as a developer in the long term :slight_smile:

BTW: you could easily extend to having a separate royalty value in any given year

again using only data

again saving developer time come December 2009

Subject: IF Case Statement can’t seem to get working?

What i would do is build a string

CheckSKUs = “11829,11834,…” (Build as desired)

Then use a set of IFs with InStr to check for existence

IF Instr(CheckSKUs, SKUtoCheck) > 0 then “FOUND IT”