+ Post New Thread
Results 1 to 4 of 4
Scripts Thread, VBS debugging help please in Coding and Web Development; ...
  1. #1
    contink's Avatar
    Join Date
    Jul 2006
    Location
    South Yorkshire
    Posts
    3,791
    Thank Post
    303
    Thanked 327 Times in 233 Posts
    Rep Power
    118

    Question VBS debugging help please

    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.

    Code:
    ' 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...

  2. #2
    contink's Avatar
    Join Date
    Jul 2006
    Location
    South Yorkshire
    Posts
    3,791
    Thank Post
    303
    Thanked 327 Times in 233 Posts
    Rep Power
    118
    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.

  3. #3

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,498
    Thank Post
    1,456
    Thanked 1,201 Times in 814 Posts
    Rep Power
    712
    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:

    Code:
    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!

  4. Thanks to LosOjos from:

    contink (20th September 2011)

  5. #4
    contink's Avatar
    Join Date
    Jul 2006
    Location
    South Yorkshire
    Posts
    3,791
    Thank Post
    303
    Thanked 327 Times in 233 Posts
    Rep Power
    118
    Quote Originally Posted by LosOjos View Post
    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:

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

    Code:
    ' 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

SHARE:
+ Post New Thread

Similar Threads

  1. A little .vbs help please
    By ozzy in forum Scripts
    Replies: 9
    Last Post: 27th February 2009, 08:07 AM
  2. small vbs help please
    By RabbieBurns in forum Scripts
    Replies: 4
    Last Post: 20th May 2008, 03:30 PM
  3. Replies: 5
    Last Post: 4th July 2006, 05:39 PM
  4. questionaire linked to database help please!!!!!!!!!!!!!!!!!
    By suesmate in forum Educational Software
    Replies: 8
    Last Post: 3rd May 2006, 06:07 PM
  5. E Learning Credits - Help Please
    By MuppetQueen in forum Budgets and Expenditure
    Replies: 4
    Last Post: 12th December 2005, 03:10 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •