Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted

I've been back into the "fun" place that is VBS scripting and hit a stonewall that I'm sure a fresh pair of eyes could spot and point out.

 

' Version #1
' RoyalMail DMO system script for Packing Partner
' 
' Service Mappings (Data.Service):
'	STL1	1st Class (Standard) 	
'	STL2	2nd Class (Standard)
'	CRL1	1st Class PacketPost
'	CRL2	2nd Class PacketPost
'	OLA		International
'	SD5		Special Delivery £500 Comp
'	SD1K	Special Delivery £1,000 Comp
'	SD2K	Special Delivery £2,500 Comp
'
' Service Reference (Data.Account):
'	1		Service Reference 1 (Company)
'	2		Service Reference 2 (Company)
'
' Enhancement Mappings (Data.Code):
'	REC		Recorded
'	SFE		International Signed For - EU
'	SFR		International Signed For - RoW
'	ASE		AirSure - EU
' 	ASR		AirSUre	- RoW
'
' Service Class (Data.Class):
'	1ST		First Class
'	2ND		Second Class
'	BFP		British Forces
'	INT		International
'	SD		Special Delivery
'
' Service Format (Data.Format):
'	LL		Large Letter (UK)
'	UKP		Packet (UK)
'	INP		International Packet
'



Data.Carrier = "DM"
Data.Account = "1"
Data.Format = "1"
Data.Code = "1"

' Interspire Shopping Cart Shipping Services
'===========================================
If Data.RecordShipBy = "Royal Mail (1st Class Recorded)" Then
Data.Service = "CRL1"
Data.Code = "REC"
Data.Class = "1ST"

Else If Data.RecordShipBy = "Royal Mail (1st Class)" Then
Data.Service = "CRL1"
Data.Class = "1ST"

Else If Data.RecordShipBy = "Royal Mail (2nd Class Recorded)" Then
Data.Service = "CRL2"
Data.Code = "REC"
Data.Class = "2ND"

Else If Data.RecordShipBy = "Royal Mail (2nd Class)" Then
Data.Service = "CRL2"
Data.Class = "2ND"

Else If Data.RecordShipBy = "Royal Mail (Special Delivery 1pm)" Then
Data.Service = "SD5"

' === European ===	
Else If Data.RecordShipBy = "Royal Mail (Airmail Signed-For)" Then
Data.Service = "OLA"
Data.Code = "SFE"

Else If Data.RecordShipBy = "Royal Mail (Airsure)" Then
Data.Service = "OLA"
Data.Code = "ASE"

Else If Data.RecordShipBy = "Royal Mail (Airmail)" Then
Data.Service = "OLA"


' === Rest of World ===
Else If Data.RecordShipBy = "Royal Mail (Airmail Signed For)" Then
Data.Service = "OLA"
Data.Code = "SFR"

Else If Data.RecordShipBy = "Royal Mail (AirSure)" Then
Data.Service = "OLA"
Data.Code = "ASR"

Else If Data.RecordShipBy = "Royal Mail (Airmail Packets)" Then
Data.Service = "OLA"



' Ebay Shipping Services
'=======================
Else If Data.RecordShipBy = "Royal Mail (1st Class)" Then
Data.Service = "1ST"

Else If Data.RecordShipBy = "Royal Mail International Signed-for" Then	
Data.Service = "OLA"
If Data.CountryZone = "EU" Then
	Data.Code = "SFE"
Else
	Data.Code = "SFR"
End If

Else If Data.RecordShipBy = "Royal Mail Airmail (Small Packets)" Then
Data.Service = "OLA"

Else If Data.RecordShipBy = "Royal Mail Airsure" Then
Data.Service = "OLA"

' In an AirSure zone?
If Instr(Data.RecordSpecial, "XA") Then
	If EUCountry(Data.Country) = True Then
		Data.Code = "ASE"
	Else
		Data.Code = "ASR"
	End If
	
' Ok, not in AirSure but is it International?
Else If Instr(Data.RecordSpecial, "XD") Then
	If EUCountry(Data.Country) = True Then
		Data.Code = "SFE"
	Else
		Data.Code = "SFR"
	End If
	
' Default to Packetpost domestic just in case
Else
	Data.Service = "CRL1"
End If


Else If Data.RecordShipBy = "Standard Int''l Postage" Then
Data.Service = "OLA"

Else If Data.RecordShipBy = "Economy Int''l Postage" Then
Data.Service = "OLA"

Else If Data.RecordShipBy = "Express Int''l Postage" Then
Data.Service = "OLA"

' In an AirSure zone?
If Instr(Data.RecordSpecial, "XA") Then
	If EUCountry(Data.Country) = True Then
		Data.Code = "ASE"
	Else
		Data.Code = "ASR"
	End If
	
' Ok, not in AirSure but is it International?
Else If Instr(Data.RecordSpecial, "XD") Then
	If EUCountry(Data.Country) = True Then
		Data.Code = "SFE"
	Else
		Data.Code = "SFR"
	End If
	
' Default to Packetpost domestic just in case
Else
	Data.Service = "CRL1"
End If


 
' Amazon Shipping Services
'=========================
Else If Data.RecordShipBy = "Standard" Then
If Instr(Data.RecordSpecial, "XD") Then
	Data.Service = "OLA"
Else 
	Data.Service = "CRL1"
End If

Else If Data.RecordShipBy = "Expedited" Then
If Instr(Data.RecordSpecial, "XD") Then
	Data.Service = "OLA"
	
	If EUCountry(Data.Country) = True Then
		Data.Code = "SFE"
	Else
		Data.Code = "SFR"
	End If
	
Else 
	Data.Service = "SD5"
End If

Else
Data.Service = "CRL1"
End If



' Figure out if this country is in the EU or not
' This sudo code assumes a field in Data called country but not sure it exists
Function EUCountry(varIn)
EUCountry = False

'Sudo Code
If(varIn = true) Then
	EUCountry = True
End If
End Function

 

Could any of you more experienced folks, take a peek and tell me what I've missed or borked in writing this nugget as I keep getting an "Expected End" error for lines 135 onwards... I thought it was the single quotes needing escaping but not so sure now.

 

Thanks in advance... :)

Posted
Sleep sometimes helps and it turns out part of my problem is the use of "Else If" instead of concatenated "ElseIf"... Still got a bug in there but seems to be related to the Function call and probably the way I'm passing an object variable.
Posted

Sorry I can't spot any obvious problem with the code, but it might be a good idea to change your dozens of "ElseIf" blocks in to a "Select Case" statement, it'll be easier to read and I believe it has performance benefits.

 

Also, your function ("EUcountry") seems pointless, why not just check that Data.Country is true in the If statement?

 

This would achieve exactly the same thing:

 

If EUCountry(Data.Country) = True Then

is the same as

If Data.Country Then

 

I've also noticed you say in the function you're not sure if Data.Country exists - that could be your problem!

  • Thanks 1
Posted
Sorry I can't spot any obvious problem with the code, but it might be a good idea to change your dozens of "ElseIf" blocks in to a "Select Case" statement, it'll be easier to read and I believe it has performance benefits.

Now that I've got a working script I'll probably go back through and sort that out but initially I didn't want to add another variable into the troubleshooting equation.

 

Also, your function ("EUcountry") seems pointless, why not just check that Data.Country is true in the If statement?

 

This would achieve exactly the same thing:

 

If EUCountry(Data.Country) = True Then

is the same as

If Data.Country Then

 

The reason for that code was that I still don't know if there is a Data.Country field available and it was more Sudo-code so I could replace it later with whatever field was later shown to be available. I'm waiting on that information now but hopefully I'll have that tomorrow.

 

I've also noticed you say in the function you're not sure if Data.Country exists - that could be your problem!

That had occured to me which is why I commented out all the relevant code... Didn't make a blind bit of difference though...

 

Anyway, here's the code now that I've messed around with it and gotten something reasonably close to working.

 

' Version #1
' RoyalMail DMO system script for Packing Partner
' 
' Service Mappings (Data.Service):
'	STL1	1st Class (Standard) 	
'	STL2	2nd Class (Standard)
'	CRL1	1st Class PacketPost
'	CRL2	2nd Class PacketPost
'	OLA		International
'	SD5		Special Delivery £500 Comp
'	SD1K	Special Delivery £1,000 Comp
'	SD2K	Special Delivery £2,500 Comp
'
' Service Reference (Data.Account):
'	1		Service Reference 1 (Company)
'	2		Service Reference 2 (Company)
'
' Enhancement Mappings (Data.Code):
'	REC		Recorded
'	SFE		International Signed For - EU
'	SFR		International Signed For - RoW
'	ASE		AirSure - EU
' 	ASR		AirSUre	- RoW
'
' Service Class (Data.Class):
'	1ST		First Class
'	2ND		Second Class
'	BFP		British Forces
'	INT		International
'	SD		Special Delivery
'
' Service Format (Data.Format):
'	LL		Large Letter (UK)
'	UKP		Packet (UK)
'	INP		International Packet
'


' Figure out if this country is in the EU or not
' This sudo code assumes a field in Data called country but not sure it exists

'Sudo Code
Dim euCountry

If Instr(Data.RecordSpecial, "CN22") Then
euCountry = True
Else
euCountry = False
End If



Data.Carrier = "DM"
Data.Account = "1"

' Get rid of any trailing/prepended whitespace
TrRecordShipBy = Trim(Data.RecordShipBy)

If Instr(Data.RecordSpecial, "XD") Then
Data.Format = "INP"
Else
Data.Format = "UKP"
End If




' Interspire Shopping Cart Shipping Services
'===========================================
If TrRecordShipBy = "Royal Mail (1st Class Recorded)" Then
Data.Service = "CRL1"
Data.Code = "REC"
Data.Class = "1ST"

ElseIf TrRecordShipBy = "Royal Mail (1st Class)" Then
Data.Service = "CRL1"
Data.Class = "1ST"

ElseIf TrRecordShipBy = "Royal Mail (2nd Class Recorded)" Then
Data.Service = "CRL2"
Data.Code = "REC"
Data.Class = "2ND"

ElseIf TrRecordShipBy = "Royal Mail (2nd Class)" Then
Data.Service = "CRL2"
Data.Class = "2ND"

ElseIf TrRecordShipBy = "Royal Mail (Special Delivery 1pm)" Then
Data.Service = "SD5"

' === European ===	
ElseIf TrRecordShipBy = "Royal Mail (Airmail Signed-For)" Then
Data.Service = "OLA"
Data.Code = "SFE"

ElseIf TrRecordShipBy = "Royal Mail (Airsure)" Then
Data.Service = "OLA"
Data.Code = "ASE"

ElseIf TrRecordShipBy = "Royal Mail (Airmail)" Then
Data.Service = "OLA"


' === Rest of World ===
ElseIf TrRecordShipBy = "Royal Mail (Airmail Signed For)" Then
Data.Service = "OLA"
Data.Code = "SFR"

ElseIf TrRecordShipBy = "Royal Mail (AirSure)" Then
Data.Service = "OLA"
Data.Code = "ASR"

ElseIf TrRecordShipBy = "Royal Mail (Airmail Packets)" Then
Data.Service = "OLA"



' Ebay Shipping Services
'=======================
ElseIf TrRecordShipBy = "Royal Mail (1st Class)" Then
Data.Service = "1ST"

ElseIf TrRecordShipBy = "Royal Mail International Signed-for" Then	
Data.Service = "OLA"
If euCountry = True Then
	Data.Code = "SFE"
Else
	Data.Code = "SFR"
End If

ElseIf TrRecordShipBy = "Royal Mail Airmail (Small Packets)" Then
Data.Service = "OLA"

ElseIf TrRecordShipBy = "Royal Mail Airsure" Then
Data.Service = "OLA"

' In an AirSure zone?
If Instr(Data.RecordSpecial, "XA") Then
	If euCountry = True Then
		Data.Code = "ASE"
	Else
		Data.Code = "ASR"
	End If
	
' Ok, not in AirSure but is it International?
ElseIf Instr(Data.RecordSpecial, "XD") Then
	If euCountry = True Then
		Data.Code = "SFE"
	Else
		Data.Code = "SFR"
	End If
	
' Default to Packetpost domestic just in case
Else
	Data.Service = "CRL1"
End If

ElseIf TrRecordShipBy = "Standard Int''l Postage" Then
Data.Service = "OLA"

ElseIf TrRecordShipBy = "Economy Int''l Postage" Then
Data.Service = "OLA"

ElseIf TrRecordShipBy = "Express Int''l Postage" Then
Data.Service = "OLA"

' In an AirSure zone?
If Instr(Data.RecordSpecial, "XA") Then
	If euCountry = True Then
		Data.Code = "ASE"
	Else
		Data.Code = "ASR"
	End If
	
' Ok, not in AirSure but is it International?
ElseIf Instr(Data.RecordSpecial, "XD") Then
	If euCountry = True Then
		Data.Code = "SFE"
	Else
		Data.Code = "SFR"
	End If
	
' Default to Packetpost domestic just in case
Else
	Data.Service = "CRL1"
End If


 
' Amazon Shipping Services
'=========================
ElseIf TrRecordShipBy = "Standard" Then
If Instr(Data.RecordSpecial, "XD") Then
	Data.Service = "OLA"
Else 
	Data.Service = "CRL1"
End If

ElseIf TrRecordShipBy = "Expedited" Then
If Instr(Data.RecordSpecial, "XD") Then
	Data.Service = "OLA"
	
	If euCountry = True Then
		Data.Code = "SFE"
	Else
		Data.Code = "SFR"
	End If
	
Else 
	Data.Service = "SD5"
End If

Else
Data.Service = ""
End If

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