Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - SUBSTRING AND SUBSTR FUNCTION PROBLEMS
  FAQ FAQ  Forum Search   Register Register  Login Login


Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

SUBSTRING AND SUBSTR FUNCTION PROBLEMS

 Post Reply Post Reply
Author
lhasha View Drop Down
New Member
New Member
Avatar

Joined: 02 Jun 2016
Location: California
Points: 3
Post Options Post Options   Quote lhasha Quote  Post ReplyReply Direct Link To This Post Topic: SUBSTRING AND SUBSTR FUNCTION PROBLEMS
    Posted: 02 Jun 2016 at 7:31pm
Greetings:

I suspect this is just one of those times when the hidden issue is actually obvious but I need help none-the-less. And I thank all in advance. 

I CANNOT extract the last three characters of an eight character string. Question

Here is my code. I have commented it for clarity purposes:

001 // **** GENERATE NEW INVOICE NUMBER ****
002 // ---------------------------------------------------------------------------------------------------------------------
003 // This code is located in the 'Mouse Up' event of a button controllers
004
005 // Constructs the invoice number preface based upon the current year and month with a '1' preceding ("1" + "16" + "06")
006 var invPreface = "1" + util.printd ("yy", new Date()) + util.printd ("mm", new Date());
007
008 var lInv = this.getField("lastInvNo").value; // This is a hidden text field with a current value of: 11606001 (VERIFIED)
009 var InvNo = this.getField("InvoiceNumber").value; // This is the visible text field which displays the invoice number.
010 // Invoice numbers are ALWAYS 8 characters long
011
012 // If there is no previous invoice number
013 if (this.getField("lastInvNo").value == ""){ // Creates the first invoice number if none exists
014 this.getField("lastInvNo").value = invPreface + "001";
015 this.getField("InvoiceNumber").value = this.getField("lastInvNo").value;
016
017 // Otherwise increment last invoice number
018 }else{
019 var getSequence;
020 getSequence = lInv.substring(5,7); // I need the last three characters on lInv. I have also tried lInv.substring(5)
021 // and lInv.substr(5,3)
022
023 this.getField("Test").value = getSequence; // Used only during development and unit testing. Successfully shows
024 // lInv without substring or substr functions.
025
026 app.beep(); // Used as a pass through test alert. Successfully beeps when lInv is without substring or substr
027 // functions otherwise fails.
028
029 // Once the last three characters are retrieved, this value (001-998) will be incremented
030 // by 1. Then the results on this increase in value, the new value is add to the string
031 // "00" and then the last three characters of this string is add to the preface ("11606"
032 // + "002") thus creating the new invoice number (11606002).
034
035 // ISSUE: Regardless of what I try or how I construct the above "getSequence =" using the
036 // substring or substr functions, the value of 'getSequence' does not change.
039 // 
040 // I WOULD APPRECIATE ANY HELP IN SOLVING THIS ISSUE!
041
042 }

AGAIN, I WOULD APPRECIATE ANY HELP! Handshake
Greatly Appreciated!
Larry Bear
Back to Top
Sponsored Links


Back to Top
BAlheit View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 1112
Post Options Post Options   Quote BAlheit Quote  Post ReplyReply Direct Link To This Post Posted: 03 Jun 2016 at 7:45am
Use this:

lInv.substr(-3)

Back to Top
lhasha View Drop Down
New Member
New Member
Avatar

Joined: 02 Jun 2016
Location: California
Points: 3
Post Options Post Options   Quote lhasha Quote  Post ReplyReply Direct Link To This Post Posted: 03 Jun 2016 at 6:07pm
THANKS FOR THE HELP !

BAlheit:

I had no idea that the substr could be notated that way. However, when it did not work in my instance, I revisited my code. Perhaps it should have been obvious to me before but it just hit me - this is a variable type issue. lInv = this.getField("lastInvNo").value sees the field value as an integer and not a string and, for obvious reasons, cannot extract the last three digits as a string.
    
  var lInv = ((this.getField("lastInvNo").value).toString()).substr(-3);
    
Does do the trick!!!! Beer

Thanks again for the kick (re) start!!! Thumbs Up



Edited by lhasha - 03 Jun 2016 at 6:20pm
Greatly Appreciated!
Larry Bear
Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4106
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post Posted: 04 Jun 2016 at 6:01pm
You could have also used the String constrictor.
 
var lInv = String((this.getField("lastInvNo").value).substr(-3);
Back to Top
lhasha View Drop Down
New Member
New Member
Avatar

Joined: 02 Jun 2016
Location: California
Points: 3
Post Options Post Options   Quote lhasha Quote  Post ReplyReply Direct Link To This Post Posted: 04 Jun 2016 at 10:40pm
COOL!
Greatly Appreciated!
Larry Bear
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.10
Copyright ©2001-2017 Web Wiz Ltd.

This page was generated in 0.063 seconds.