Solved

Change my ASP Function

Posted on 2014-12-15
19
136 Views
Last Modified: 2014-12-15
Public Function Logic

IF WarehouseID = 1 Then Len(ProductID) < 8 Then ProductID = Right(String(8, "0") & ProductID, 8)
    FormatTEDProductID = "ARP" & ProductID
elseif

   WarehouseID = 2 Then Len(ProductID) < 8 Then ProductID = Right(String(8, "0") & ProductID, 8)
    FormatTEDProductID = "ELI" & ProductID

My current fuction is just

Public Function FormatTEDProductID (ProductID)
    If Len(ProductID) < 8 Then ProductID = Right(String(8, "0") & ProductID, 8)
    FormatTEDProductID = "ARP" & ProductID
End Function

Open in new window


The table has both ProductID and WarehouseID


How would I go about doing this?
0
Comment
Question by:FreerTool
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
  • 5
19 Comments
 
LVL 33

Accepted Solution

by:
Big Monty earned 500 total points
ID: 40500799
try:

Public Function FormatTEDProductID (ProductID, WarehouseID)
    If WarehouseID = 1 and Len(ProductID) < 8  Then 
           ProductID = Right(String(8, "0") & ProductID, 8)
           FormatTEDProductID = "ARP" & ProductID
    elseif WarehouseID = 2 and Len(ProductID) < 8 Then 
           ProductID = Right(String(8, "0") & ProductID, 8)
           FormatTEDProductID = "ELI" & ProductID
   end if    
End Function

Open in new window


note the 2nd parameter of WarehouseID in your function
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40500810
this assumes both of your values are of valid INT types. You may want to check that before the if statement:

Public Function FormatTEDProductID (ProductID, WarehouseID)
    if not isNumeric( ProductID ) then
         ProductID = 0
    else
         ProductID = CInt( ProductID )
    end if
    if not isNumeric( WarehouseID ) then
         WarehouseID = 0
    else
         WarehouseID = CInt( WarehouseID )
    end if


    If WarehouseID = 1 and Len(ProductID) < 8  Then
           ProductID = Right(String(8, "0") & ProductID, 8)
           FormatTEDProductID = "ARP" & ProductID
    elseif WarehouseID = 2 and Len(ProductID) < 8 Then
           ProductID = Right(String(8, "0") & ProductID, 8)
           FormatTEDProductID = "ELI" & ProductID
   end if    
End Function
0
 

Author Comment

by:FreerTool
ID: 40500844
Getting error  An error occurred on the server when processing the URL. Please contact the system administrator

with both and yes they are both  integers.
0
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 
LVL 33

Expert Comment

by:Big Monty
ID: 40500848
post your updated code
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40500882
I just stuck the code below in a blank asp page and got the appropriate results. If you're getting  an error, it has to do with the values you're passing into the function

<%
Public Function FormatTEDProductID (ProductID, WarehouseID)
    if not isNumeric( ProductID ) then 
         ProductID = 0
    else
         ProductID = CInt( ProductID )
    end if
    if not isNumeric( WarehouseID ) then 
         WarehouseID = 0
    else
         WarehouseID = CInt( WarehouseID )
    end if

    If WarehouseID = 1 and Len(ProductID) < 8  Then 
           ProductID = Right(String(8, "0") & ProductID, 8)
           FormatTEDProductID = "ARP" & ProductID
    elseif WarehouseID = 2 and Len(ProductID) < 8 Then 
           ProductID = Right(String(8, "0") & ProductID, 8)
           FormatTEDProductID = "ELI" & ProductID
   end if    
End Function

    Response.Write FormatTEDProductID( 4, 1 ) & "<br/></br>"
    Response.Write FormatTEDProductID( 4, 2 )

    
%>

Open in new window

0
 
LVL 52

Expert Comment

by:Huseyin KAHRAMAN
ID: 40500941
here it is:

Public Function FormatTEDProductID (WarehouseID , ProductID)
    If Len(ProductID) < 8 Then ProductID = Right(String(8, "0") & ProductID, 8)
    FormatTEDProductID = iif(WarehouseID = 1, "ARP", "ELI") & ProductID
End Function

Open in new window


pass WarehouseID , ProductID to the function...
0
 

Author Comment

by:FreerTool
ID: 40500974
I think thats my problem is that i am not passing the warehouseID properly to the function.


<p class="listProductPartNumber"><b>Product Number:</b> <%=FormatTEDProductID(RsProduct("ProductID").Value)%>

Is where I am Formatting my ProductID   I am just trying to figure how i pass it to the function here.
0
 
LVL 52

Expert Comment

by:Huseyin KAHRAMAN
ID: 40500982
use function i posted above with this:

<p class="listProductPartNumber"><b>Product Number:</b> <%=FormatTEDProductID(RsProduct("WarehouseID").Value, RsProduct("ProductID").Value)%>
0
 
LVL 52

Expert Comment

by:Huseyin KAHRAMAN
ID: 40500988
remember, the function I posted above assumes, you have only 1 or 2 as WarehouseID

Logic is this: Add "ARP" if warehouse=1 or add "ELI" otherwise...
0
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
ID: 40501025
assuming WarehouseID is from your recordset, you would do:

<p class="listProductPartNumber"><b>Product Number:</b> <%=FormatTEDProductID(RsProduct("ProductID").Value, RsProduct("WarehouseID").Value)%> 

Open in new window


Using the function I gave does an error check for you, if your ProductIDs and WarehouseID's are empty, or not int values, it makes sure no error is produced.

also, sometimes values from a recordset are treated as strings, even if they are numbers, so it's a good idea to convert them (using CInt()) to make sure the if statement works properly
0
 

Author Comment

by:FreerTool
ID: 40501205
Yeah i have troubleshoot some more but neither of your guys code is working for me.  I must not be passing the WarehouseID properly. I get a blank white page when i update.
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40501210
where is WarehouseID coming from, the recordset? can you confirm there is ALWAYS a WarehouseID in the data set coming back from the database?

if you hard code values in the function, does it work then?
0
 
LVL 52

Expert Comment

by:Huseyin KAHRAMAN
ID: 40501223
this should work fine

<p class="listProductPartNumber"><b>Product Number:</b> <%=FormatTEDProductID(RsProduct("WarehouseID").Value, RsProduct("ProductID").Value)%>

with this code

Public Function FormatTEDProductID (WarehouseID , ProductID)
    If Len(ProductID) < 8 Then ProductID = Right(String(8, "0") & ProductID, 8)
    FormatTEDProductID = iif(WarehouseID = 1, "ARP", "ELI") & ProductID
End Function

Open in new window


what do you get here?

Product Number: ??????

if you do not get any error, warehouseid is not coming from db correctly, o/w you get error!

try passing 1 as hardcoded value and try

<p class="listProductPartNumber"><b>Product Number:</b> <%=FormatTEDProductID(1, RsProduct("ProductID").Value)%>
0
 

Author Comment

by:FreerTool
ID: 40501251
so I am checking all my pages that have the warehouseID  that i need to pass.  for example.

http://www.automationrecovery.com/categories/Automation-Surplus/
0
 
LVL 33

Assisted Solution

by:Big Monty
Big Monty earned 500 total points
ID: 40501268
and did you try hard coding the IDs like I suggested? are there ALWAYS productIDs as well?
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40501284
it looks like product number is displaying properly as I see it shown in your page.

it looks like your link is not correct, can you post the code for it and what you expect to happen on the next page along with its code?
0
 

Author Comment

by:FreerTool
ID: 40501319
sorry take a look at it now.
0
 

Author Comment

by:FreerTool
ID: 40501363
Its working fine now, thanks for your assistance Big Monty
0
 
LVL 52

Expert Comment

by:Huseyin KAHRAMAN
ID: 40501386
and what is the solution & why I did not get any share?
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Subtraction v Hex2Dec in vbscript 6 30
ASP and Extracting XML 7 30
Want an individual results display div 8 47
Validating number not work with decimal 4 29
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question