In wincc, a large amount of data is needed for software simulation, so scripts are needed to realize the function of generating random numbers.
entry | description |
---|---|
Operating environment | wincc7.5 SP1 |
Run screen
Operating procedures
Create variable
1. Create data variables in variable management
Create a global script function
Create project functions in Global Script. Note that the creation here is a Function process, not a Sub process. The Sub procedure does not return a value, and the Function procedure returns a process value.
Function MyRnd(min,max)
MyRnd=Rnd*(max-min+1)+min '在(min,max)之间取随机数
End Function
Configuration screen
Screen object | name |
---|---|
Input and output domain | default |
Button | default |
Static text | default |
- Add 12 input and output domains, and manage variables in turn, and map Data1 in the variable table to the input and output domains one by one.
- Add a button, which is used to write randomly generated data into the input and output fields. The button event script is as follows:
'随机产生0-1000内的数据
HMIRuntime.Tags("Data1").Write MyRnd(0,1000)
HMIRuntime.Tags("Data2").Write MyRnd(0,1000)
HMIRuntime.Tags("Data3").Write MyRnd(0,1000)
HMIRuntime.Tags("Data4").Write MyRnd(0,1000)
HMIRuntime.Tags("Data5").Write MyRnd(0,1000)
HMIRuntime.Tags("Data6").Write MyRnd(0,1000)
HMIRuntime.Tags("Data7").Write MyRnd(0,1000)
HMIRuntime.Tags("Data8").Write MyRnd(0,1000)
HMIRuntime.Tags("Data9").Write MyRnd(0,1000)
HMIRuntime.Tags("Data10").Write MyRnd(0,1000)
HMIRuntime.Tags("Data11").Write MyRnd(0,1000)
HMIRuntime.Tags("Data12").Write MyRnd(0,1000)