- プロジェクトの作成
- オブジェクトと変数のリファレンス
- プロジェクトの拡張
- チュートリアル
- グラフィックオブジェクト チュートリアル
ランダム値を挿入するための NetLogic を開発する
この NetLogic スクリプトは、データベースの
Table1
テーブルにランダムな値を挿入します。前提条件
デフォルトの外部コード エディターを設定します。「デフォルトのコード エディターを設定する」を参照してください。
- NetLogic を開発するには
- [プロジェクトビュー]で、[データストア]フォルダーを展開します。
- データベースを右クリックし、を選択します。
- NetLogic にカーソルを合わせ、を選択し、EmbeddedDatabase1NetLogicと入力します。
- NetLogic をダブルクリックします。外部コード エディターが開きます。
- コード エディターで、既存のコードを次のコードに置き換えます。#region Using directives using System; using FTOptix.HMIProject; using FTOptix.NetLogic; using FTOptix.Store; #endregion public class EmbeddedDatabase1NetLogic : BaseNetLogic { public override void Start() { // Insert code to be executed when the user-defined logic is started } public override void Stop() { // Insert code to be executed when the user-defined logic is stopped } [ExportMethod] public void InsertRandomValues (){ // Get the current project folder. var project = Project.Current; // Save the names of the columns of the table to an array string[] columns = { "Column1", "Column2", "Column3" }; // Create and populate a matrix with values to insert into the odbc table var rawValues = new object[1000, 3]; Random randomNumber = new Random (); for (UInt16 i = 0; i < 1000; ++i) { // Column1 rawValues[i, 0] = i; // Column2 rawValues[i, 1] = randomNumber.Next(0, 5000); // Column3 rawValues[i, 2] = randomNumber.NextDouble() * 5000; } var myStore = LogicObject.Owner as Store; // Get Table1 from myStore var table1 = myStore.Tables.Get<Table>("Table1"); // Insert values into table1 table1.Insert(columns, rawValues); } }
- コードを保存します。
ご質問やご意見