Split up String into chars (CALC-BLOCK)

Hello,

I'm trying to seperate the characters of '/^STRING_IN.CV' (which is ABCD) by using a calc block to get

'/^STRING_OUT1.CV' (A)  

'/^STRING_OUT2.CV' (B)  

'/^STRING_OUT3.CV' (C)  

'/^STRING_OUT4.CV' (D)  

Does someone has a hint for me?

after this I need to convert the characters into a HEX-code, but that won't be a problem.

Your help is very appreciated!

Marcel

11 Replies

  • Bad news: in a DeltaV module the only string operations that you can do are: concatenation and comparison (checking for equality). No way to split up a string or to access individual characters, as far as I know.
    You could pass the string to DeltaV Operate and split it up with some VBA code, but it's not a very nice solution.
  • In reply to István Orbán:

    Thanks for that, even it was not what I wanted to hear ;-)
    I'll consider about making a VBA-code.
  • Marcel, Could you explain why you need to perform this type of text manipulation in the controller? Maybe if we understood your root problem a better solution might emerge. Where does the original string come from, what are the HEX codes used for. You've described a very specific component of you problem but maybe there is a completely different way to solve the overall problem.

    Andre Dicaire

  • In reply to Andre Dicaire:

    I need to send the actual Material-ID(string) of a named set through modbus to a weight cell device.
    Unfortunatly the weight cell doesn't accept string values.
    Right now I am creating a Sub in IFix to load all named sets and its values, splitting them up into single characters, change them to ASCII code and send them back to a Parameter in Explorer.
    That parameter is a floating point array and can save all the Material-IDs. (5 rows for 5 letters in decimal numbers).
    Works out quite well, but I don't figure out how to write to an array in VBA.
    WriteValue Char1_Dec, "DVSYS.TEST_WEIGHT/MAT1_ARRAY[1][1]" <-- this is the way I try it, but it refuses to work (Data source undefined)
  • In reply to Marcel:

    Your format is correct except you are missing the .F_CV (Number) or .A_CV.

    WriteValue Char1_Dec, "DVSYS.TEST_WEIGHT/MAT1_ARRAY[1][1].F_CV"
  • In reply to Matt Stoner:

    If you are passing a Named set then surely the easiest way is to create a second named set with the hexedecimal equivalent of your strings in the first. The integer value of the first named set will be the same as the second one except it will have the hex characters. Then you have no conversion to perform. You can do this easily by exporting the named set and running it through a conversion in some other package i.e. Excel. Then you have two named sets MyData and MYData_Hex.
  • In reply to Matt Stoner:

    That works, thanks a lot !
  • In reply to Steve Linehan:

    We considered about that, but there is another problem when we do so.

    I need to send the Material (ABCD) through modbus with seperated characters. Byte1="A", Byte2="B" etc.
    As MYDATA_Hex will still be string datatype, I'll still need VBA to seperate the characters.
  • In reply to Matt Stoner:

    Now I want to increment the MAT1_ARRAY[1] by using MAT_ARRAY[i].
    Thats not working, any guesses why?

    Dim i As Variant
    ....
    WriteValue CHR1_STR, "DVSYS.TEST_WEIGHT/MAT1_ARRAY[i][1].F_CV"
    WriteValue CHR2_STR, "DVSYS.TEST_WEIGHT/MAT1_ARRAY[i][2].F_CV"
    WriteValue CHR3_STR, "DVSYS.TEST_WEIGHT/MAT1_ARRAY[i][3].F_CV"
    WriteValue CHR4_STR, "DVSYS.TEST_WEIGHT/MAT1_ARRAY[i][4].F_CV"
    WriteValue CHR5_STR, "DVSYS.TEST_WEIGHT/MAT1_ARRAY[i][5].F_CV"
    i = i + 1
    ....
  • In reply to Marcel:

    well.... [i] = [ i ]
  • In reply to Marcel:

    WriteValue CHR1_STR, "DVSYS.TEST_WEIGHT/MAT1_ARRAY[" & CStr(i) & "][1].F_CV"
    WriteValue CHR2_STR, "DVSYS.TEST_WEIGHT/MAT1_ARRAY[" & CStr(i) & "][2].F_CV"
    WriteValue CHR3_STR, "DVSYS.TEST_WEIGHT/MAT1_ARRAY[" & CStr(i) & "][3].F_CV"
    WriteValue CHR4_STR, "DVSYS.TEST_WEIGHT/MAT1_ARRAY[" & CStr(i) & "][4].F_CV"
    WriteValue CHR5_STR, "DVSYS.TEST_WEIGHT/MAT1_ARRAY[" & CStr(i) & "][5].F_CV"