How do I use a switch with a null variable?

Here is my current situation...
I have a form that will take the inputted information in the field "LEDIR" and divide it by the information in field "AMMO".  I get errors when the form is first loaded because the field "AMMO" is blank and causes a "Divide by 0" problem.   I tried to solve the problem with a switch, but an not sure how to create a "null" switch case.  Here is what I have.. any ideas as to how I can set the second case so it returns a "0" for a null AMMO field?
var InvR = this.getField("LEDIR").valueAsString;
var AmmoPk = this.getField("AMMO").valueAsString;
switch (Ammo)
case "0":
   event.value = 0;
   break;
case "[what do i put here?] ":
   event.value = 0;
   break;
default:
   event.value = (Math.floor(InvR/AmmoPk))
any ideas as to how I can set the second case so it returns a "0" when the AMMO field is empty?

You can even stack the 'case' to create and 'OR' type of selection:
var InvR = this.getField("LEDIR").valueAsString;
var AmmoPk = this.getField("AMMO").valueAsString;
switch (Ammo) {
case "0":
case "":
   event.value = 0;
   break;
default:
   event.value = (Math.floor(InvR/AmmoPk))
But it is just as easy to use:
var InvR = Number(this.getField("LEDIR").value);
var AmmoPk = Number(this.getField("AMMO").value);
event.value = "";
if(AmmoPk != 0) {
  event.value = (Math.floor(InvR/AmmoPk))

Similar Messages

  • How do I use setString() method with multiple bind variables

    I have two setString() statements and a select union statement. My class compiles but only displays the data for the first table ignoring the second setString() statement. But When I replace the "where id=?" with "where id=12 or someid", it works and displays all data found in both tables.
    Am I not properly using the setString() method?
    public class LdData{
    private String id;
    public LdData(){
    public void setId(String id)
        this.id = id;
      public String getId()
        return id;
    public Collection getLdData() throws Exception{
                    List rows = new ArrayList();
    //connection statement
    String sql_query="SELECT a,b FROM table1 WHERE id = ? " + " UNION " + "SELECT a,b FROM table2 WHERE id= ?";
    try {
                            conn = ds.getConnection();
    pstmt = conn.prepareStatement( sql_query );
    pstmt.setString(1, this.id);
    pstmt.setString(2, this.id);
    rst = pstmt.executeQuery();
    while (rst.next()) {
    //dataEntry.java - contains my getter and setter
    dataEntry info = new dataEntry(rst.getString("a"), rst.getString("b"), this.id);
    rows.add(info);
    //catch all SQLexceptions, NamingExceptions
    //close all connection
    return rows;
    //dataEntry.java - dataEntry class
    private String a;
    private String b;
    private String id;
    public dataEntry(String a, String b, String id){
    seta(a);
    setb(b);
    setbdate(bcode);
    this.a = a;
    this.b = b;
    this.id = id;
    public String getA(){
    return a;
    public String getB(){
    return b;
    public String getId(){
    return id;
    public void setA(String a){
    this.a = a;
    public void setB(String b){
    this.b = b;
    public void setId(String id){
    this.id = id;
    //index.jsp - displays data
    <jsp:useBean id="test" class="lddata" scope="request">
    <jsp:setProperty name="test" property="id" param="id"/>
    </jsp:useBean>
    <display:table name="${test.lddata}"/>

    This just doesnt make sense to me at all. :( Could it be a naming issue? I mean both tables have the same field names but different data information
    so the union will never sort and choose. And the weirdest thing is that
    //this works -
    ->String sql_query="SELECT a,b FROM table1 WHERE id = TU234 " + " UNION ALL" + "SELECT a,b FROM table2 WHERE id= TU234";
    //I also tried this, but the second statement doesnt work
    ->pstmt.setString(1, "TU234"); //this works.
    ->pstmt.setString(2, "TU234"); //this doesnt
    //It also tried this, it worked for both set statements, but I need it in an list or so.
    while (rst.next()) {
    String a = rst.getString(a);
    String b = rst.getString(b);
    String id = rst.getString(id);
    System.out.println(a+""+b+""+id);
    }Is there anyother way I can collect the data into a jsp page without using javabean?

  • How do I use my ipad with Apple TV?

    How do i use my iPad2 with Apple TV?

    If it's an ATV2 or 3, you can use AirPlay. AirPlay automatically becomes available when the two devices are on the same Wi-Fi network.
    HOWEVER! You should be aware of that AirPlay is, in some circumstances, far inferior to VGA / HDMI-cabled solutions. Please see my posts at https://discussions.apple.com/message/18697551?ac_cid=sa123456#18697551 for more info.

  • How do I use apple remote with iPhone 5 ?

    How do I use apple remote with iPhone 5 ?

    Iphones dont have ir at all which the remote use for comm
    Only option is to use a dock which have ir

  • When I try to sign in to iTunes, it tells me that my Apple ID has not yet been used with the iTunes Store. How do I use my account with the iTunes Store?

    When I try to sign in to iTunes, it tells me that my Apple ID has not yet been used with the iTunes Store. How do I use my account with the iTunes Store?

    Hello Daijalove97,
    Thanks for using Apple Support Communities.
    For more information on this, take a look at:
    Using an existing Apple ID with the iTunes Store and Mac App Store
    http://support.apple.com/kb/HT2589
    To use your Apple ID at the iTunes Store
    Open the latest version of iTunes.
    Choose Store > Sign In from the Store menu.
    Enter your Apple ID and password, then click Sign In.
    Click Review when asked to review your information.
    Enter your billing information, a credit card will be required.
    Click Continue when you're done entering your credit card and billing information.
    Best of luck,
    Mario

  • How can I use an iPad with two itunes accounts?

    How can I use an iPad with two itunes accounts?
    Hi there
    My partner has a works iPad, which has her works Apps on (ones that are specifically made by her company and are NOT available in the App store).
    What I want to be able to do is to ALSO have my itunes account on there so that I can put all the apps I have purchased previously from my iPhone on it.
    This is so I can put on VLC player (thats already in my itunes account) so I can add videos to the iPad.
    How do I do this please?
    I tried it before by connecting it to my mac, but it wiped everything off the iPad completely and also deleted the data settings for using 3G.
    So I want to avoid this happening again the future as it had to be sent back to her head office to be sorted again.
    Any advise please?
    Thanks

    You can't. The iPad is desgined to be a 'one user' device and only really works with one apple ID at a time.
    The only way would be if she, at work and with her work apple id, downloaded your apps (repurchasing them of course).
    It's not meant to be a multiple user/multiple ID device.

  • How can i use text expander with the new Mavericks,

    how can i use text expander with the new Mavericks,

    I regret upgrading to mavericks for the same reason
    ftamez wrote:
    how can i use text expander with the new Mavericks,
    Now I have been searching - and you have to buy an app and it will cost you $34.99 (what a rip off)

  • TS1629 How do I use home sharing with direct TV / Verizon internet. I have turned on Home sharing on apple tv and in iTunes but can't see the library in apple tv. I can see the photo stream but thats it. Any Ideas????

    How do I use home sharing with direct TV / Verizon internet. I have turned on Home sharing on apple tv and in iTunes but can't see the library in apple tv. I can see the photo stream but thats it. Any Ideas????

    go to home-sharing on Apple TV and type in your info as ask.
    hope this help

  • How do I use Home Sharing with two different apple accounts?

    How do I use Home Sharing with two different apple accounts?

    Morning Saintine,
    Thanks for using Apple Support Communities.
    Home Sharing enables you to stream or transfer music, movies, TV shows, apps, and more among up to five authorized computers in your household. To do so, you will need to Turn on Home Sharing on each computer using the same Apple ID.
    Understanding Home Sharing
    http://support.apple.com/kb/HT3819
    Hope this helps,
    Mario

  • How do i use itunes server with itunes match?

    Hi all,
    I am using itunes server on my synology NAS. On my desktop i've always used itunes with match. How can I combine the two? In other words, how can i use itunes match with itunes server?
    thanx

    I don't know if you've already solved it yourself, but I had this problem too. Try signing out of iTunes Store under 'Settings', then signing back in with JUST your iTunes user name, with no '.mac' or '.me' suffix. If, for example, your usual sign-in method is '[email protected]' try using 'joebloggs'.
    Worked for me.

  • How do I use my iPad with a digital projector

    How do I use my iPad with a projector

    Have a look at this:
    http://www.epson.com/cgi-bin/Store/jsp/Landing/ProjectorApp.do

  • How do you use an iPad with Apple TV

    How do I use an iPad with Apple TV?

    Read the iPad manual:  http://support.apple.com/manuals/#ipad
    See this article: http://support.apple.com/kb/HT4437

  • How can i use "icloud backup" with ios 4.2.1?

    How can i use "icloud backup" with ios 4.2.1? I tried to update my ihpone 3G wih the newest IOs. Seems not to be possible.

    You cannot.
    It requires ios 5.
    Your iphone can only go to 4.2.1

  • How can I use the NI PXI-6508 with Lab View 7? what are the first steps to get started??How can I use the channels with lab view 7????

    I have a 8 slot PXI system with 2 NI PXI 6508 and 1 DMM 4070 in it. I want to get started with programming the digital I/O cards (6508)! How can I use this cards with LabView 7?what is the best way to get started, or where can I get examples showing how to use the several channels?
    Thanks!
    Philipp

    Philipp,
    The best way to get started is to decide if you want to use traditional NI-DAQ or NI-DAQmx. Recently we released NI-DAQ 7.1 which provides NI-DAQmx support for the PXI-6508. In my opinion, NI-DAQmx is more efficient and much easier to use.
    To get started with examples, simply launch LabVIEW and go to Help>>Find Examples. Then expand Hardware Input and Output>>DAQmx and select the appropriate digital group for your application. This should help get you started.
    Please repost if you need addition assistance. Good luck with your application!

  • How can I use the DBAdapter with SequencingPollingStrategy in OSB Cluster?

    Hi!
    I have a OSB cluster. I need to read a view with the DBAdapter. I use SequencingPollingStrategy to implement the adapter.
    Then I import it into OSB and make it work and the service works normally in the single node.
    But if I import it into OSB cluster, the service always read the duplication records from the view.(the Distrbute polling is not worked in SequencingPollingStrategy )
    So how can I use the DBAdapter with SequencingPollingStrategy in OSB Cluster?
    Thank you!

    Nope. Version 5 is a fashion accessory: it looks like software, but it doesn;t actually do anything. Sort of like a sports car with a lawn-mower engine. Looks snzzy. Doesn't really work. (And given how buggy it is, I should further specifiy that the lawn-mower engine comes with a blade: it chews up your old templates, produces files that cannot be sent as email attahcments [yes, really], and—this just in—doesn;t play well with the new SMB facility of Mavericks. In short, as one reviewer put it, "un unmitigated disaster."

Maybe you are looking for

  • How can I allow a "0.00" dollar amount in a required field?

    I'm creating an expense form that has several fields marked a required. I've also included a java base print button that checks the fields and will open the print dialogue box if all the fields are completed. I'm wanting to allow a zero dollar amount

  • Need information on BAPI for Sales Process ?

    Hello SAP folks, I am currently involved in Consumer Portal integration with SAP System. I need information about the right kind of BAPI that would help me to enter and retrieve data from SAP database. I have noted down following funtionality in Sale

  • Photo's on your Mac

    Hi I have a mini SD card with some photos on and need to get them onto my MacBook Pro. I presume I need a card reader of sorts but unsure which one, I know there is a slot on the side of my MacBook, is this a card slot? Appreciate any advice. Regards

  • FI-GL(Income Statements) problems while extracting from R/3?

    Hi Guru's, I will be working on FI-Gl(Income Statement) for the first time, could someone please tell me what problems i would face when getting data from R/3. I have read that they are few problems in transferring Special Ledger Data from R/3. Like:

  • Add a partner at sales order item level?

    According to SAP note 380507 there is no partner determination on sales order item level. I've the following requirement: When an item with a certain item category is created a partner role/function should be added at the sales order item level. I've