cancel
Showing results for
Did you mean:

Solved!
Go to solution

## multiply channels with a constant

Hi

I want to multiply all my channles with a constant value say 4.3

So I thought of generating a new channel with all its value as 4.3 and multiplying this channel with my current channel . I used

Dim MyChnName, i

MyChnName = ChnAlloc("Mass", 2400, 1,DataTypeFloat64,"Numeric")     'Allocate text channel
For i = 1 to 200
CHT(i,MyChnName(0)) = "4.3" & i        'Create text value
Next

But it generates values as 4.31, 4.32, .....4.3xxx

I want all values to be constant. How can i modify my code to do this??

Or to multiply all my channle values with 4.3 directly(without creatin a channel) How to go ahead with this??

Message 1 of 4
(4,675 Views)
Solution
Accepted by topic author Rash.patel

## Re: multiply channels with a constant

Hi Rash.patel,

Are you really talking about a text - which means "abc123...."? I think not because you define a numeric channel with chnalloc.And in the next line you connect tow strings: ...= "4.3" & i. In VBS a string connection just puts the strings together like "abc" & "123" -> "abc123". I think this is not what you would like to do. If you use a loo you must define: ... = 4.3 + i

But in general you should use the standard mathematical functions of DIAdem because they are much faster than a loop over the single channel values.

In the DIAdem Base Mathematic you find the functions you need, like Scaling, Offset correction ....

Greetings

Walter

Message 2 of 4
(4,674 Views)

## Re: multiply channels with a constant

Hey Walter,

Thanks for your idea. I modified my script like this and now I can generate a channel with all its value as 4.3.

MyChnName = ChnAlloc("Mass", 2400, 1,DataTypeFloat64,"Numeric")     'Allocate text channel
For i = 1 to 2400
CHT(i,MyChnName(0)) = 4.3 + 0        'Create text value
Next

Message 3 of 4
(4,660 Views)

## Re: multiply channels with a constant

Hi Patel,

This was not what Walter said at all-- he said to use the standard ANALYSIS functions for this sort of thing.  The standard ANALYSIS functions are much faster and easier than a VBScript loop.  Here's what you should use to create a channel like that instead:

`Call ChnLinGen("Mass", 4.3, 4.3, 2400, "kg")`