FlexPro
HistoryBase
Engineering
Training
Downloads
FlexPro-Support
Wissen
Community
Über Uns
Referenzen
Jobs
Allgemeiner Kontakt
Händlerverzeichnis
FlexPro-Support
DE
EN
FR
Placeholder
Produkte und Lösungen
Support und Downloads
Unternehmen
Magazin
Kontakt
Sprache
MyWeisang

Account Einstellungen

Topic

Hex to Dez conversion

Startseite ' Community ' FPScript ' Hex to Dez conversion

Anzeigen von 7-Stellen - 1 bis 7 (von insgesamt 7)
  • Autor
    Beiträge
  • #33298

    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

    #33304

    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

    #33299
    Bernhard Kantz
    Teilnehmer

    Try this:

    [code]
    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
    [/code]

    support@weisang.com

    #33300

    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

    #33301
    Bernhard Kantz
    Teilnehmer

    Use the [b]index[/b] operator to get a scalar value from a data set.

    Example:
    [code]
    Dim i, result
    result = 0 # NumberOfRows(Test)
    For Each Row i In Test Do
    result[i] = HexToDez(Test[i])
    End
    result
    [/code]
    The HexToDez is a FPScript formula which converts Hex values into decimal values. This formula uses the [b]Arguments[/b] statement.

    See also
    FlexPro Online Help (F1)

    Support@weisang.com

    #33302

    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[i])
    If D>60000 then D=D-65536
    end
    D=D/500
    result[i] = 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

    #33303
    Bernhard Kantz
    Teilnehmer

    Here is an alternative FPScript-Function:
    [code]
    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
    [/code]
    You can convert your FPScript formula into a dataset. Alternatively you could use VBA with FlexPro Professional to convert your values.

    Support@weisang.com

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