From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.


Showing results for 
Search instead for 
Did you mean: 

multiply channels with a constant

Go to solution


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


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??

0 Kudos
Message 1 of 4
Accepted by topic author Rash.patel

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 ....




0 Kudos
Message 2 of 4

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

0 Kudos
Message 3 of 4

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")


Brad Turpin

DIAdem Product Support Engineer

National Instruments

Message 4 of 4