How to convert a string to number

Hi, I need to do a logic where if the minutes, (in string format), > 4 then…..
Due I have the minutes in string I Can´t use the statement “ >”…..is there anyway to convert the minutes in string to number?
I know If I use an assignment inside a calc or action block it works ….but with an integrity error and moreover depending on deltav Version this assignment is not supported….and perhaps it will no work on future version of deltaV
 
 
 

7 Replies

  • I found an option, using dynamic references
     
    From: Navas Guzman, Luis Alberto [PROCESS/PSS/BUEN]
    Sent: jueves, 21 de marzo de 2013 11:47 a.m.
    To: DeltaV@community.emerson.com
    Cc: Navas Guzman, Luis Alberto [PROCESS/PSS/BUEN]
    Subject: How to convert a string to number
     
    Hi, I need to do a logic where if the minutes, (in string format), > 4 then…..
    Due I have the minutes in string I Can´t use the statement “ >”…..is there anyway to convert the minutes in string to number?
    I know If I use an assignment inside a calc or action block it works ….but with an integrity error and moreover depending on deltav Version this assignment is not supported….and perhaps it will no work on future version of deltaV
     
     
     
  • In reply to Lucho:

    Looked up on web: will it work??

    1:

    Dim str As String

    Dim num As Integer

    str = "12345"

    num = val(str)

    2:

    Dim v As Integer

    v = Val("100 Blah Blah")

    Print v   ' prints 100

    v = Val("Nothing")

    Print v  ' Could not convert, prints 0

    Niklas Flykt 

    Klinkmann Oy

    Key Account Manager safety products

    nikfly@gmail.com

  • THANKS!, however the instruction “val”, doesn´t exist in DeltaV, (control studio)
    I found the solution using dynamic reference.
    Best Regards
     
     
    From: Niklas Flykt [mailto:bounce-nikfly@community.emerson.com]
    Sent: jueves, 21 de marzo de 2013 01:22 p.m.
    To: DeltaV@community.emerson.com
    Subject: RE: [EE365 DeltaV Track] How to convert a string to number
     

    Looked up on web: will it work??

    1:

    Dim str As String

    Dim num As Integer

    str = "12345"

    num = val(str)

    2:

    Dim v As Integer

    v = Val("100 Blah Blah")

    Print v   ' prints 100

    v = Val("Nothing")

    Print v  ' Could not convert, prints 0

  • In reply to Niklas Flykt:

    Niklas,  This would not work as the requirement is to run in the controller and DeltaV controllers do not use VB.  The CALC blocks use a Structured Text language with a slightly different syntax.

    I wonder what the root issue is?  The problem is not really converting a string to a number.  it is detecting when a time threshold is exceeded, (> than 4 minutes) but we don't know anything about how this string is derived, where it comes from or if there isa better way for DeltaV to detect this threshold.  Lucho might get more input from the community if he backed up and described the problem he is trying to solve, not the problem he has run into with his solution...  Something to think about when posting on a forum like this one.

    Andre Dicaire

  • In reply to Andre Dicaire:

    Hi, tought we were talking about iFix VB ? In DV you have these standard functions to change time to string/numbers and so on... Just make a block and assign the "chopped" up time parts to the out put side.

    Niklas Flykt 

    Klinkmann Oy

    Key Account Manager safety products

    nikfly@gmail.com

  • In reply to Lucho:

    Another option that can be used when the numbers are integers and there are less than 256 of them (like minutes 0 to 59) is to create a named set with the strings as names and values as the numbers.  You can assign the string value to a parameter using .CVS and read back the number using .CV

  • Look in BOL to the functions TIME and TIME_TO_STR.
    Use 2 parameters, one to receive time (32 bit unsigned integer), one string.
    Read actual time using TIME function. Store in first parameter.
    Convert actual time to desired string using TIME_TO_STR(format, actual time)
    to hour, minute or sec.
    Reverse: create a time-string by concetenation (in some future) and feed
    this to a DTE block.

    But maybe you just need an ON-DELAY or OFF-DELAY block.


    -----Oorspronkelijk bericht-----
    Van: Lucho [mailto:bounce-Lucho@community.emerson.com]
    Verzonden: donderdag 21 maart 2013 15:47
    Aan: DeltaV@community.emerson.com
    Onderwerp: [EE365 DeltaV Track] How to convert a string to number

    Hi, I need to do a logic where if the minutes, (in string format), > 4
    then…..
    Due I have the minutes in string I Can´t use the statement “ >”…..is there
    anyway to convert the minutes in string to number?
    I know If I use an assignment inside a calc or action block it works ….but
    with an integrity error and moreover depending on deltav Version this
    assignment is not supported….and perhaps it will no work on future version
    of deltaV