DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Function Val(String) doesn't work in a data plugin

Function Val(String) doesn't work in a data plugin (I think because it is only for use in VB Skript of DIAdem!?)
 
What can I use e.g. for
MyError = Val("error=5") to get the integer 5 in my variable?
Maybe there is a work around?
0 Kudos
Message 1 of 9
(3,993 Views)

Hello Moos,

In the context of a Dataplugin the DIAdem specific function are not available. Did you download the helpfile for DataPlugin developers ? You definitely should. In the helpfile you will find all function which are available in addition to the VBScript runtime specific function.

Back to your question : If you have "Error=5" what you could do is split up the string into two parts, the parameter name and the value. Use Split to do this. Split splits a given string into token separated by a delimiter you can define. As a result you get an array of tokens. In this case you would get "error" in the first array element and "5" in the second. In a second step you can use ParseString (please refer to the DataPlugin OLH) to read the number from the "5" string. If the string is simple as "5" you could also use "Clng" which is a built in VbScript function. Still ParseString is more reliable when it comes to values like "5.34E04"

Please ask if you have further questions

Andreas

0 Kudos
Message 2 of 9
(3,987 Views)
Hello Andreas,
how can I change
MyScale = "10.0 " to
MyScale = "10,0 " programatical?
 
Thank you.
0 Kudos
Message 3 of 9
(3,980 Views)
Moos,
 
I am not sure whether I understand your question. Assuming that you want to know how ParseString can be configured to read "10,0" or "10.0" correctly, here is the answer :
 
File.Formatter.DecimalPoint = ","
or
File.Formatter.DecimalPoint = "."
 
Let me know if you have further questions.
Andreas
 


 
0 Kudos
Message 4 of 9
(3,979 Views)

Hello Andreas,

thank you for your help. But I still can't go on.

With your proposal 'Split' I got the values with a point between. I use GetNextLine and than I split the line by my keywords.

MyScale = "10.1 " ' a point

MyScale = CDbl(MyScale)

Call MsgBox (MyScale) ' here I see 101

But with a comma I could use it for further calculations

MyScale = "10,1 " ' a comma

MyScale = CDbl(MyScale)

Call MsgBox (MyScale) ' here I see 10,1 and I can do calculations with it.

But I only get the string with a point between (because in the file I take the value out, it is also written with a point)! And I want to change it to a comma.

0 Kudos
Message 5 of 9
(3,975 Views)

Moos,

because of this problem I mentioned ParseString. What you want to do is use the string which contains "10.1" and parse it with ParseString :

dValue = File.Formatter.ParseString(string, eR64)

This gives you 10.1 assuming that you have set the decimal point to "." Use File.Formatter.DecimalPoint = "." to do this before you call ParseString. The VBScript function CDbl uses the Windows system settings to convert a string to a numeric value. This behaviour makes it more or less unusable for your purpose.

Hope this helps

Andreas


 

0 Kudos
Message 6 of 9
(3,972 Views)

Sorry, I think I still didn't get you. I don't understand how to use File.Formatter.

 

My configuration file looks like that:

....

scale=1000.0

offset=0.0

unit=V

.....

My data plugin looks like that:

....

Set MyCfgFile = Openfile("configurationfile.cfg") ' a second file to work with

MyCfgFile.Formatter.DecimalPoint = "." ' is this right?????

....

MyChnComment = MyCfgFile.GetNextLine

MySplit = Split(MyChnComment, "scale=", -1, 1)

MyScale = MySplit(1)

MyScale = CDbl(MyScale)

MsgBox (MyScale) ' it shows me also 10000 (and not 1000,0 or 1000.0)

...

 
0 Kudos
Message 7 of 9
(3,969 Views)

Moos,

Sorry for double posting. Here is what I meant to send :

Its CDbl which creates the problem. Please do not use CDbl, use ParseString instead.

This is what you do :

MyChnComment = MyCfgFile.GetNextLine
MySplit = Split(MyChnComment, "scale=", -1, 1)
MyScale = MySplit(1)
MyScale = CDbl(MyScale)

This is what you should do :

File.Formatter.Decimalpoint = "."

MyChnComment = MyCfgFile.GetNextLine
MySplit = Split(MyChnComment, "=", -1, 1) 
MyScale = MySplit(1)
MyScale = File.Formatter.ParseString(MyScale,eR64)

Please let me know how this works

Andreas

0 Kudos
Message 8 of 9
(3,951 Views)

Hello Andreas,

it works!!! 🙂 Thank you very much for your help.

Moos

0 Kudos
Message 9 of 9
(3,940 Views)