Hex to Dez conversion

SupportCommunity FPScript Hex to Dez conversion

Ansicht von 7 Beiträgen - 1 bis 7 (von insgesamt 7)
  • Autor
    Beiträge
  • #12509

    I am trying to convert data in hex format to dez numbers using the following script. It won’t run because of a syntax error (behind the first else). The numbers are in the following format: 0xFFFF

    Script is:

    for i = 6 to 3 do

    b = stringmid(test,i,1)
    if (b = ‘F’) then (b=15) else
    if (b = ‘E’) then b=14 else
    if (b = ‘D’) then b = 13 else
    if (b= ‘C’) then b =12 else
    if (b = ‘B’) then b = 11 else
    if (b= ‘A’) then b =10
    end
    end
    end
    end
    end
    end
    D = D + (b * 16^(6-i))
    end
    return D

    Thanks already

    Peter

    #8172

    I am trying to convert data in hex format to dez numbers using the following script. It won’t run because of a syntax error (behind the first else). The numbers are in the following format: 0xFFFF

    Script is:

    for i = 6 to 3 do

    b = stringmid(test,i,1)
    if (b = ‘F’) then (b=15) else
    if (b = ‘E’) then b=14 else
    if (b = ‘D’) then b = 13 else
    if (b= ‘C’) then b =12 else
    if (b = ‘B’) then b = 11 else
    if (b= ‘A’) then b =10
    end
    end
    end
    end
    end
    end
    D = D + (b * 16^(6-i))
    end
    return D

    Thanks already

    Peter

    #8815
    Bernhard KantzBernhard Kantz
    Moderator

    Try this:

    
    Dim i, b, D
    D = 0
    
    For i = 3 to 6 do
    	
       b = stringmid(test,i,1)
       
       if (b == "F") then (b=15) 
       elseif (b == "E") then b=14 
       elseif (b == "D") then b = 13 
       elseif (b== "C")  then b = 12 
       elseif (b == "B") then b = 11 
       elseif (b == "A") then b = 10 
       end
       D = D + (b * 16^(6-i))
    end
    return D
    

    support@weisang.com

    #8816

    Thanks!

    The next problem is that I have a “Datenreihe mit … Zeichenketten” called ‘Test’ that I want to convert. The function Stringmid(Test,i,1) gives me the following error message: “Das erst Argument der Funktion Stringmid() hat falsche Datenstruktur. Das Argument muss ein Zeichenketten Einzelwert sein.”

    How can I get the function to convert all the values ?

    Thanks

    Peter

    #8817
    Bernhard KantzBernhard Kantz
    Moderator

    Use the index operator to get a scalar value from a data set.

    Example:

    
    Dim i, result
    result = 0 # NumberOfRows(Test)
    For Each Row i In Test Do
    	result = HexToDez(Test)
    End
    result
    

    The HexToDez is a FPScript formula which converts Hex values into decimal values. This formula uses the Arguments statement.

    See also
    FlexPro Online Help (F1)

    Support@weisang.com

    #8818

    Thanks a lot! This works for me now.

    I have to use slightly different function (maybe because I am using FlexPro 6?):

    Dim i,D, result
    result = 0 # Numberofvalues(Weg)
    For Each value i In Weg Do
    D = HextoDez(Weg)
    If D>60000 then D=D-65536
    end
    D=D/500
    result = D
    End
    result

    and I had to do my own hextodez function which looks like this:

    arguments h
    Dim D,i

    D = 0
    For i = 2 to 5 do

    b = stringmid(h,i,1)

    if (b == “F”) then (b=15)
    elseif (b == “E”) then b=14
    elseif (b == “D”) then b = 13
    elseif (b == “C”) then b = 12
    elseif (b == “B”) then b = 11
    elseif (b == “A”) then b = 10
    end
    D = D + (b * 16^(5-i))
    end

    The only problem is that this is quite slow (with 130000 numbers). Is there any possibility to speed the function up, or at least to have it calculate everything again as soon as I use the function in a diagram etc. ?

    Thanks

    Peter

    #8819
    Bernhard KantzBernhard Kantz
    Moderator

    Here is an alternative FPScript-Function:

    
    dim chars, idx
    dim a, res, i, n
    chars = "0123456789ABCDEF"
    a = "2FFF"
    res = 0L
    n = StringLength(a) - 1
    For i = 0 to n Do
       idx = StringFind(chars, StringMid(a, i, 1))
       if idx < 0 then
    	return 0
       End
       res = res * 16 + idx
    End
    res
    

    You can convert your FPScript formula into a dataset. Alternatively you could use VBA with FlexPro Professional to convert your values.

    Support@weisang.com

Ansicht von 7 Beiträgen - 1 bis 7 (von insgesamt 7)
  • Du musst angemeldet sein, um auf dieses Thema antworten zu können.