none
Help - isNumeric, isEmpty var return RRS feed

  • Question

  • I am no VBScript expert in anyway and I am trying to take a vale from a MySQL DB field that is a semicolon delimited list of varying strings and use it for calculation.  Here is the variable assignment: 

    dim profile
    profile  = split(rec("profile").value & ";;;;;;;;;;;;;;;;;;;", ";")
    for i = 0 to 19
      if profile(i)  = "" then recTpl.removeBlock "Profile" & (i+1)
      recTpl.assignVariable "Profile"  & (i+ 1), profile(i)
    next

    I am then trying to take the 19th variable (Profile19) which contains either a numeric value or is empty and use it for calculation, however, no matter what type of function I use to test the contents, I am left with a default value of one as this is to catch the instances where this variable is empty.  Can anyone assist/explain why the value is not coming through?  I have gone through this with a bunch of other programmers but none of us are VBScript experts....   Thank you!!!!!

    if Not isEmpty(Profile19) then 
      if isNumeric(Profile19) then
        ASSIGN THE VARIABLE I AM TRYING TO PERFORM CALC
      else if Not isNmeric(Profile19) then
        VAR = CInt(Profile19) 
      end if 
    else if isEmpty(Profile19) then 
      ASSIGN THE VARIABLE I AM TRYING TO PERFORM CALC = 1 
    end if 

    Monday, October 6, 2014 3:15 PM

Answers

  • There is no way we can guess at what you are trying to do.  If you can't post an example that illustrates the problem then we cannot be of any help.


    ¯\_(ツ)_/¯

    Monday, October 6, 2014 6:47 PM

All replies

  • What's in rec? What's rec("profile")? What's in recTpl? What does recTpl.removeBlock do? What does recTpl.assignVariable do? What does "19th variable" mean?

    Sorry, but there is not nearly enough information in your question to provide a guess as to the problem.

    Usually, numbered variables are a sign that an array should be used.

    To get help with your question, write a short VBScript script that contains only the minimum amount of code needed to reproduce the problem. (Remember, we don't have access to your database, and we can't see your screen.) The idea here is to provide short and succinct code that fails for us in exactly the same way it fails for you.


    -- Bill Stewart [Bill_Stewart]

    Monday, October 6, 2014 3:22 PM
    Moderator
  • Sorry for that example.  This is as simple as I can get this portion - all aspects of the script are working fine other than the fact that the below is just always assigning the variable qty a one instead of the six that it should be.  Mostly, I just need verification that this should return the value of 6.5 / 6 without issue.  Thanks for any assistance!! 

    dim profile19, qty
    profile19 = 6

    if Not isEmpty(profile19) then
      if isNumeric(profile19) then 
        qty = profile19
      endif
      if Not isNumeric(profile19) then
        qty = CInt(profile19)
      endif
    else if isEmpty(profile19) then 
      qty = 1 
    end if 

    dim amount, amount1
    amount = 6.50

    amount1 = cDbl(amount / qty) 

     


    • Edited by jmatt1012 Monday, October 6, 2014 3:36 PM
    Monday, October 6, 2014 3:35 PM
  • The first two lines make little sense.

    dim profile
    profile  = split(rec("profile").value & ";;;;;;;;;;;;;;;;;;;", ";")

    This is unnecessary:

    rec("profile").value & ";;;;;;;;;;;;;;;;;;;"

    With this of course the 19th value is null.

    This makes more sense:
    Dim profile(19)
    profile(0) = rec("profile").Value

    If rec("profile") contains a semicolon delimited string then we could do this:

    profile = Split(rec("profile").Value,";")

    Now you will have as many array elements as you have delimited fields.

    But, as Bill has pointed out, your question is ambiguous.


    ¯\_(ツ)_/¯

    Monday, October 6, 2014 3:35 PM
  • Oh if you have a variable list and want to normalize it then you would need to do something like this.

    x = Split(rec(..),";")
    dim profile(19)

    For i = 0 to 18
         if i < UBound(x) Then  profile(i) = x(i)
    Next


    ¯\_(ツ)_/¯



    • Edited by jrv Monday, October 6, 2014 3:40 PM
    Monday, October 6, 2014 3:39 PM
  • Thank you very much for the answer - this was my first impression, however, a "web master" that wrote that original aspect indicated this was incorrect and it did not need to be normalized.  I will try this and with any luck it will do the trick.   Thanks again from a C++ programmer that is struggling through an undesirable web script... 
    Monday, October 6, 2014 3:47 PM
  • Thank you very much for the answer - this was my first impression, however, a "web master" that wrote that original aspect indicated this was incorrect and it did not need to be normalized.  I will try this and with any luck it will do the trick.   Thanks again from a C++ programmer that is struggling through an undesirable web script... 

    C++?  Shame on you.  It was an easy answer for a C programmer.  The issue is that you cannot reliably add semicolons and know what you are ending up with.  Copying is much easier.


    ¯\_(ツ)_/¯

    Monday, October 6, 2014 3:51 PM
  • This is actually cleaner:

    x = Split(rec(..),";")
    dim profile(19)
    For i = 0 to UBound(x)
         profile(i) = x(i)
    Next


    ¯\_(ツ)_/¯

    Monday, October 6, 2014 3:54 PM
  • I appreciate all the help - however - I still can't get a decent value regardless.  

    I'm going through ASP for a lot of sites that was written 10 - 15 years ago.  At this point, I'd love to rewrite it all the right way as it may take me less time...  

    Monday, October 6, 2014 6:42 PM
  • There is no way we can guess at what you are trying to do.  If you can't post an example that illustrates the problem then we cannot be of any help.


    ¯\_(ツ)_/¯

    Monday, October 6, 2014 6:47 PM
  • I ran this script:


    dim profile19, qty
    profile19 = 6
    
    if Not isEmpty(profile19) then
      if isNumeric(profile19) then
        qty = profile19
      end if
      if Not isNumeric(profile19) then
        qty = CInt(profile19)
      end if
    elseif isEmpty(profile19) then
      qty = 1
    end if
    
    WScript.Echo qty
    
    dim amount, amount1
    amount = 6.50
    
    amount1 = cDbl(amount / qty)
    
    WScript.Echo TypeName(amount1)
    WScript.Echo amount1
    

    Output is:


    6
    Double
    1.08333333333333
    

    Just as expected.

    -- Bill Stewart [Bill_Stewart]

    Monday, October 6, 2014 7:27 PM
    Moderator