Sage 100

 View Only
Expand all | Collapse all

Seemingly simple question

  • 1.  Seemingly simple question

    Posted 01-28-2021 00:13
    Hi All,   I think I am going blind.   I have what should be a really simple script but part of is is not working & I don't understand why.  It generates a UPC for a client. They enter part in the Category 1 field and the UPC number is that plus a fixed string added to the beginning.  That part works fine.  What I want also is for it to wipe out the UPC if the Category 1 field is wiped out.   But what it does is leave the fixed string in place.   Something is wrong I think with the test the blank field but not sure what.   Let me know if you can see the error of my ways...
    I did move an end if right after that test, before they were all at the end.   Maybe an exit sub instead? 

    'Generate UPC No
    'Bob Osborn ACI

    sUPC = "" : sCat1 = ""

    if oSession.CompanyCode = "ATP" then

    RetVal = oBusObj.GetValue("Category1$",sCat1)
    retMsg = oSession.AsObject(oSession.UI).MessageBox("", sCat1)

    if sCat1 = "" then
    RetVal = oBusObj.SetValue("UDF_UPC$", " ")
    end if
    else
    if sCat1 <> "" then
    sUPC = "799158" & sCat1
    RetVal = oBusObj.SetValue("UDF_UPC$", sUPC)
    end if
    end if

    ------------------------------
    Bob Osborn
    Consultant
    ACI Consulting
    ------------------------------


  • 2.  RE: Seemingly simple question

    Posted 01-28-2021 09:03
    Request:

    Please title posts as specifically as possible. These forums are also used by people to research issues before posting or in response to customer questions.

    The Higher Logic search prominently displays the post titles and therefore it is important for search that the title accurately and specifically describe the main content.

    Also, please wherever possible always post a followup when you’ve found a solution. We get a ton of “ hey, did you ever figure this out” type posts and when that post is 5 years after-the-fact it’s very difficult to remember what the resolution was unless it is written down.



    ---------------------------------
    Wayne Schulz - Schulz Consulting - 860-516-8990
    ---------------------------------





  • 3.  RE: Seemingly simple question

    Posted 01-28-2021 22:44
    Hi Wayne,  Will do.  Was a very long frustrating day...

    ------------------------------
    Bob Osborn
    Consultant
    ACI Consulting
    ------------------------------



  • 4.  RE: Seemingly simple question

    Posted 01-28-2021 09:36
    You might try testing for null instead of = ""

    ------------------------------
    Eric Lunceford
    First Mate Business Solutions
    Oklahoma City, OK
    877-880-8960
    https://www.firstmatellc.com/
    ------------------------------



  • 5.  RE: Seemingly simple question

    Posted 01-28-2021 09:43
    Edited by Doug Higgs 01-28-2021 09:45
    or testing for a blank space <> " "

    ------------------------------
    Doug Higgs
    Midwest Commerce Solutions, Inc
    (312) 315-0960
    Assistant to the Traveling Secretary
    ------------------------------



  • 6.  RE: Seemingly simple question

    Posted 01-28-2021 09:46
    Edited by Doug Higgs 01-28-2021 09:46
    edited previous post.  try  if sCat1 <> " " then


    ------------------------------
    Doug Higgs
    Midwest Commerce Solutions, Inc
    (312) 315-0960
    Assistant to the Traveling Secretary
    ------------------------------



  • 7.  RE: Seemingly simple question

    Posted 01-28-2021 09:47
    try if sCat1 <> " " then

    ------------------------------
    Doug Higgs
    Midwest Commerce Solutions, Inc
    (312) 315-0960
    Assistant to the Traveling Secretary
    ------------------------------



  • 8.  RE: Seemingly simple question

    Posted 01-28-2021 12:53
    Edited by Alnoor Cassim 01-28-2021 13:00
    Bob - I assume script is running on Post-Val of Cat1. You could rearrange it like this where you're checking the Length and checking if an error occurred:

    sUPC = "" : sCat1 = ""
    If oSession.CompanyCode = "ATP" then
    	sCat1 = value
    	nLen = Len(sCat1)
    	sMsg = "Cat1 = " & sCat1 & "  Length of Cat1 = " & nLen
    	rMsg=oSession.AsObject(oSession.UI).MessageBox("",sMsg)
    	
    	Select Case nLen
    	Case 0
    		rV = oBusObj.SetValue("UDF_UPC$", "")
    		If rV <= 0 Then
    			'0 is an error and -1 is a warning
    			sMsg = "SetValue of UPC from blank Cat1 = " & rV & vbCrLf & oBusObj.LastErrorMsg
    		Else
    			sMsg = "SetValue of UPC from blank Cat1 successful"
    		End If
    		rMsg = oSession.AsObject(oSession.UI).MessageBox("", sMsg)
    	Case > 0
    		sUPC = "799158" & sCat1
    		rV = oBusObj.SetValue("UDF_UPC$", sUPC)
    		'Just in case
    		If rV <= 0 Then
    			sMsg = "Last Error/Warning on SetValue of " & sUPC & _
    					" to " & sCat1 & " = " & oBusObj.LastErrorMsg
    			rMsg = oSession.AsObject(oSession.UI).MessageBox("", sMsg)
    		End If
    	Case Else
    			'Drop thru
    	End Select
    End If 'check for CompanyCode


    ------------------------------
    Alnoor Cassim

    Email: alnoor@asifocus.com
    Ph: 949-689-9887
    Orange County, CA
    ------------------------------



  • 9.  RE: Seemingly simple question

    Posted 01-29-2021 09:24
    I would also recommend wrapping Trim() around the value to eliminate any leading or lagging empty spaces, which will also set the length = 0 if there are only spaces.

    sCat1 = Trim(value​)


    ------------------------------
    Steve Iwanowski, NextStep Technology Advisors, aka DSD Lancaster PA ¯\_(ツ)_/¯
    ------------------------------



  • 10.  RE: Seemingly simple question

    Posted 01-30-2021 23:44
    Hi All,
      Thanks for all the suggestion but still no luck on the conditional setting of the UPC.   In the end, I do not thing it will be a big issue for the client, but my concern was/is that someone could make a type on the Cat1 field that would require the UPC to be updated.   
      I left out that is a post validate on Cat1.  Even tried changing it table pre write but it did not change the outcome. 
      Alnoor, I love the idea of case statements but for what ever reason they never work for me.  Even using yours exactly would not pass syntax test (syntax is the bane of my existence in scripting as I don't do it enough to really "get it" well enough)
      Dan, the company code condition is because this UPC code only applies to this company.  Others have a different code.   What I was trying to do was set a condition to have it wipe out the UPC entry if the Cat1 field was empty rather than just write the prefix of the UPC. 

    I tried two if statements and the len test still did not seem to work, in spite of trying the different ideas on testing the length.  

    So went with a "single" pass script for now - it works but does not,  for what ever reason, update the UPC if the cat1 is changed. .   
    'Generate UPC No
    'Bob Osborn ACI

    sUPC = "" : sCat1 = ""

    if oSession.CompanyCode = "ATP" then
            RetVal = oBusObj.GetValue("Category1$",sCat1)
            sUPC = "799158" & sCAt1
           SMsg = sUPC
          ' rMsg = oSession.AsObject(oSession.UI).MessageBox("", sMsg)
           RetVal = oBusObj.SetValue("UDF_UPC$", sUPC)

    end if ' Company Code

    ------------------------------
    Bob Osborn
    Consultant
    ACI Consulting
    ------------------------------



  • 11.  RE: Seemingly simple question

    Posted 01-31-2021 20:57
    Robert,
    Thank you for following up with your resolution. I have two final points:
    1. I understood the purpose for the company code condition, the point I was trying to convey was that your ELSE statement was unnecessary. Without it the script worked for me. With it, the section with the SetValue statement would never be entered for company ATP.
    2. I am confused by the statement in your last reply that "...it works but does not, for what ever reason, update the UPC if the cat1 is changed."
      I understood that updating the UPC when Cat1 is changed was the point? I don't understand why you say that "it works".


    ------------------------------
    Dan Burleson
    Software Consultant
    Connex Software
    Corvallis OR
    541-224-6642
    ------------------------------



  • 12.  RE: Seemingly simple question

    Posted 01-31-2021 22:09

    Hi Dan,

       You guys are nice enough to reply, I don't like to just drop it without some sort of resolution.

     

      The Else was if Cat1 was blank so that the UPC would be set to "nothing".  Without that, it gets set to 799158 which is not really good since it's not valid UPC.  The test on blank is the what I could not get to work.

     

      The odd thing that I see is that If I change the Cat1 field on the item it either does not update or updates to 799158.  Very strange but at this point I have to move on as I have spent way too much time on something that looked to be a 30-minute job..     Thanks for following up.

     

    Thank you,

     

    Bob Osborn

    ACI Consulting

    p 714.282.0378 ext. 402    f 714.282.0235

     

    Bob@ACIconsulting.com

     

     ACISignature1                  

    MCP_SE_Small.bmp

    This communication, including attachments, is confidential and may contain proprietary information intended only for the proposed recipient. Please notify the sender and delete this message if you believe that you have received this message in error or if you are not the proposed recipient. Unauthorized disclosure, copying, or distribution of the information is strictly prohibited.

     

     

     

     






  • 13.  RE: Seemingly simple question

    Posted 01-31-2021 23:49
    What you aren't seeing is that the "Else" statement isn't part of your if sCat="" conditional.

    It is part of your if oSession.CompanyCode = "ATP" conditional. I deleted your "Else" and it works fine in both cases. 'Just trying to impress you with the importance of indenting which helps to avoid this mistake in the future.

    ------------------------------
    Dan Burleson
    Software Consultant
    Connex Software
    Corvallis OR
    541-224-6642
    ------------------------------



  • 14.  RE: Seemingly simple question

    Posted 02-01-2021 01:26

    HI Dan,

    Well as my opening statement said, it appears I am going blind.   Lesson learned.   

     

    One question.  In this isn't it possible to use Else, without an end if?    It never seems to work for me.  One of the fine points on syntax that I do not always understand. And if you use the else, would If be included or not?  I have also tried Else If without success.  The part in italics is what I am referring to.  

     

    'Generate UPC No
    'Bob Osborn ACI

    sUPC = "" : sCat1 = ""

    if oSession.CompanyCode = "ATP" then

    RetVal = oBusObj.GetValue("Category1$",sCat1)
    retMsg = oSession.AsObject(oSession.UI).MessageBox("", sCat1)

     

    if sCat1 = "" then
          RetVal = oBusObj.SetValue("UDF_UPC$", " ")
    ' end if  - commenting out to ask about use of else in If structure

    else


    if sCat1 <> "" then

    (would this line be "sCat1 <> "" then" without an if? Or with Else IF?  )
          sUPC = "799158" & sCat1
           RetVal = oBusObj.SetValue("UDF_UPC$", sUPC)
    'end if   - commented out asking if it is needed with Else instead of End If. 
    end if ' For company

     

    Thank you,

     

    Bob Osborn

    ACI Consulting

    p 714.282.0378 ext. 402    f 714.282.0235

     

    Bob@ACIconsulting.com

     

     ACISignature1                  

    MCP_SE_Small.bmp

    This communication, including attachments, is confidential and may contain proprietary information intended only for the proposed recipient. Please notify the sender and delete this message if you believe that you have received this message in error or if you are not the proposed recipient. Unauthorized disclosure, copying, or distribution of the information is strictly prohibited.

     

     

     

     






  • 15.  RE: Seemingly simple question

    Posted 02-01-2021 02:35
    Edited by Dan Burleson 02-01-2021 02:38
    An "ElseIf" could be used since you've now commented out the 1st "End If". This brings it into the realm of your 2nd "If", but you'll need another "End If" at the end to keep it balanced. You're making it hard on yourself by not indenting even in this latest example. Or maybe I'm dyslexic. I updated my structured example below to comment out your "Else" statement. That's the ONLY change I made to your original version for it to work (other than indenting). I recommend a simple editor like VBSEdit $59 or UltraEdit $99.

    Alnoor's indented script works well also if you replace the 2nd Case statement with Case nLen > 0.

    ------------------------------
    Dan Burleson
    Software Consultant
    Connex Software
    Corvallis OR
    541-224-6642
    ------------------------------



  • 16.  RE: Seemingly simple question

    Posted 02-01-2021 11:29

    Hi Dan,

       The indents seem to have gotten "lost" when I copied it into the email.  They are there, as I mentioned – lesson learned.   I did have to go back to the Len test as just testing for blank did not work.  I believe this test is much better.  

     

    The script as below "works".  No errors, the message box returns the expected values including when Cat1 is changed,  BUT the field is not updated.   I am thinking it has something to do with the way the field is setup.  We just recently became their reseller and the previous reseller did a lot of "ad hoc" programming that we are slowly uncovering.

     

    'Generate UPC No

    'Bob Osborn ACI

     

    sUPC = "" : sCat1 = "" : nLen = 0

     

    if oSession.CompanyCode = "FAT" then

     

    RetVal = oBusObj.GetValue("Category1$",sCat1)

    retMsg = oSession.AsObject(oSession.UI).MessageBox("", sCat1)

    nLen = len(sCat1)

     

    if nLen = 0 then

                    RetVal = oBusObj.SetValue("UDF_UPC$", " ")

     

    else if nLen > 0 then

                    sUPC = "799158" & sCat1

     

                    RetVal = oBusObj.SetValue("UDF_UPC$", sUPC)

                    retMsg = oSession.AsObject(oSession.UI).MessageBox("", sUPC)

     

    end if  ' else if

    end if   ' Cat1 test

     

    End if ' For company

     

    Thank you,

     

    Bob Osborn

    ACI Consulting

    p 714.282.0378 ext. 402    f 714.282.0235

     

    Bob@ACIconsulting.com

     

     ACISignature1                  

    MCP_SE_Small.bmp

    This communication, including attachments, is confidential and may contain proprietary information intended only for the proposed recipient. Please notify the sender and delete this message if you believe that you have received this message in error or if you are not the proposed recipient. Unauthorized disclosure, copying, or distribution of the information is strictly prohibited.

     

     

     

     






  • 17.  RE: Seemingly simple question

    Posted 02-01-2021 11:38
    Did you try:
    nLen = len(trim(sCat1))

    Instead of:
    nLen = len(sCat1)
    ?  If your method of blanking out the field is to press the space bar, that is still counted unless you trim invisible characters.

    ------------------------------
    Kevin Moyes
    Technical Systems Analyst
    Munjal White Consulting Co.
    Toronto ON
    ------------------------------



  • 18.  RE: Seemingly simple question

    Posted 02-01-2021 12:03

    Hi Kevin

      Good point.  Thanks

     

    Thank you,

     

    Bob Osborn

    ACI Consulting

    p 714.282.0378 ext. 402    f 714.282.0235

     

    Bob@ACIconsulting.com

     

     ACISignature1                  

    MCP_SE_Small.bmp

    This communication, including attachments, is confidential and may contain proprietary information intended only for the proposed recipient. Please notify the sender and delete this message if you believe that you have received this message in error or if you are not the proposed recipient. Unauthorized disclosure, copying, or distribution of the information is strictly prohibited.

     

     

     

     






  • 19.  RE: Seemingly simple question

    Posted 02-01-2021 11:43
    1. Check the the UDF_UPC isn't defined as a numeric
    2. Add "RetVal" to your MessageBox
    3. Consider using Debug mode to monitor return values and results instead of MessageBox
    4. Use {i} (Insert/Edit code sample) for code snippets so that proportional fonts don't screw up your code
    5. Your first "If" statement still isn't indented (I'm being picky)


    ------------------------------
    Dan Burleson
    Software Consultant
    Connex Software
    Corvallis OR
    541-224-6642
    ------------------------------



  • 20.  RE: Seemingly simple question

    Posted 01-29-2021 02:48
    Edited by Dan Burleson 02-01-2021 02:17
    As Alnoor demonstrates, Indenting helps with even the smallest script. Your script leaves any string in the Category1 field in place because - for company "ATP" it only checks for empty strings. The path for companies other than "ATP" does check for non-empty strings, but that path doesn't get the value of Category1. Below, I've indented your script so the flaw is more easily seen. Shorter days work too!

    sUPC = "" : sCat1 = ""

    if oSession.CompanyCode = "ATP"then

        RetVal = oBusObj.GetValue("Category1$",sCat1)
        retMsg = oSession.AsObject(oSession.UI).MessageBox("", sCat1)
        if sCat1 = ""Then
            RetVal = oBusObj.SetValue("UDF_UPC$", " ")
        endIf
        
    'Else Not needed

        if sCat1 <> ""Then
            sUPC = "799158" & sCat1
            RetVal = oBusObj.SetValue("UDF_UPC$", sUPC)
        endIf
        
    endif


    ------------------------------
    Dan Burleson
    Software Consultant
    Connex Software
    Corvallis OR
    541-224-6642
    ------------------------------