home *** CD-ROM | disk | FTP | other *** search
/ Robotics & Artificial Int…3 (Professional Edition) / Robotics & Artificial Intelligence Tools 2003 (Professional Edition).iso / neural network tool and application / nsinstall.exe / data1.cab / CustomSolutionWizard_Files / ProjectShells / VBShellDlg.vb < prev    next >
Encoding:
Text File  |  2002-03-08  |  17.0 KB  |  360 lines

  1. Option Strict Off
  2. Option Explicit On
  3. Imports VB = Microsoft.VisualBasic
  4. Friend Class VBShellDlg
  5.     Inherits System.Windows.Forms.Form
  6. #Region "Windows Form Designer generated code "
  7.     Public Sub New()
  8.         MyBase.New()
  9.         If m_vb6FormDefInstance Is Nothing Then
  10.             If m_InitializingDefInstance Then
  11.                 m_vb6FormDefInstance = Me
  12.             Else
  13.                 Try 
  14.                     'For the start-up form, the first instance created is the default instance.
  15.                     If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then
  16.                         m_vb6FormDefInstance = Me
  17.                     End If
  18.                 Catch
  19.                 End Try
  20.             End If
  21.         End If
  22.         'This call is required by the Windows Form Designer.
  23.         InitializeComponent()
  24.     End Sub
  25.     'Form overrides dispose to clean up the component list.
  26.     Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
  27.         If Disposing Then
  28.             If Not components Is Nothing Then
  29.                 components.Dispose()
  30.             End If
  31.         End If
  32.         MyBase.Dispose(Disposing)
  33.     End Sub
  34.     'Required by the Windows Form Designer
  35.     Private components As System.ComponentModel.IContainer
  36.     Public ToolTip1 As System.Windows.Forms.ToolTip
  37.     Public WithEvents chkResetNetwork As System.Windows.Forms.CheckBox
  38.     Public WithEvents cmdTrainNetwork As System.Windows.Forms.Button
  39.     Public WithEvents cmdClose As System.Windows.Forms.Button
  40.     Public WithEvents cmdGetNetworkOutput As System.Windows.Forms.Button
  41.     Public WithEvents txtTrainNetwork As System.Windows.Forms.TextBox
  42.     Public WithEvents Frame1 As System.Windows.Forms.GroupBox
  43.     Public WithEvents txtNetworkOutput As System.Windows.Forms.TextBox
  44.     Public WithEvents Frame2 As System.Windows.Forms.GroupBox
  45.     Public WithEvents Label1 As System.Windows.Forms.Label
  46.     'NOTE: The following procedure is required by the Windows Form Designer
  47.     'It can be modified using the Windows Form Designer.
  48.     'Do not modify it using the code editor.
  49.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  50.         Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(VBShellDlg))
  51.         Me.components = New System.ComponentModel.Container()
  52.         Me.ToolTip1 = New System.Windows.Forms.ToolTip(components)
  53.         Me.ToolTip1.Active = True
  54.         Me.chkResetNetwork = New System.Windows.Forms.CheckBox
  55.         Me.cmdTrainNetwork = New System.Windows.Forms.Button
  56.         Me.cmdClose = New System.Windows.Forms.Button
  57.         Me.cmdGetNetworkOutput = New System.Windows.Forms.Button
  58.         Me.Frame1 = New System.Windows.Forms.GroupBox
  59.         Me.txtTrainNetwork = New System.Windows.Forms.TextBox
  60.         Me.Frame2 = New System.Windows.Forms.GroupBox
  61.         Me.txtNetworkOutput = New System.Windows.Forms.TextBox
  62.         Me.Label1 = New System.Windows.Forms.Label
  63.         Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
  64.         Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
  65.         Me.Text = "Custom Solution Wizard Sample"
  66.         Me.ClientSize = New System.Drawing.Size(332, 325)
  67.         Me.Location = New System.Drawing.Point(184, 250)
  68.         Me.MaximizeBox = False
  69.         Me.MinimizeBox = False
  70.         Me.ShowInTaskbar = False
  71.         Me.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  72.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
  73.         Me.BackColor = System.Drawing.SystemColors.Control
  74.         Me.ControlBox = True
  75.         Me.Enabled = True
  76.         Me.KeyPreview = False
  77.         Me.Cursor = System.Windows.Forms.Cursors.Default
  78.         Me.RightToLeft = System.Windows.Forms.RightToLeft.No
  79.         Me.HelpButton = False
  80.         Me.WindowState = System.Windows.Forms.FormWindowState.Normal
  81.         Me.Name = "VBShellDlg"
  82.         Me.chkResetNetwork.Text = "Reset Network Before Training"
  83.         Me.chkResetNetwork.Size = New System.Drawing.Size(177, 17)
  84.         Me.chkResetNetwork.Location = New System.Drawing.Point(32, 64)
  85.         Me.chkResetNetwork.TabIndex = 4
  86.         Me.chkResetNetwork.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  87.         Me.chkResetNetwork.CheckAlign = System.Drawing.ContentAlignment.MiddleLeft
  88.         Me.chkResetNetwork.BackColor = System.Drawing.SystemColors.Control
  89.         Me.chkResetNetwork.CausesValidation = True
  90.         Me.chkResetNetwork.Enabled = True
  91.         Me.chkResetNetwork.ForeColor = System.Drawing.SystemColors.ControlText
  92.         Me.chkResetNetwork.Cursor = System.Windows.Forms.Cursors.Default
  93.         Me.chkResetNetwork.RightToLeft = System.Windows.Forms.RightToLeft.No
  94.         Me.chkResetNetwork.Appearance = System.Windows.Forms.Appearance.Normal
  95.         Me.chkResetNetwork.TabStop = True
  96.         Me.chkResetNetwork.CheckState = System.Windows.Forms.CheckState.Unchecked
  97.         Me.chkResetNetwork.Visible = True
  98.         Me.chkResetNetwork.Name = "chkResetNetwork"
  99.         Me.cmdTrainNetwork.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
  100.         Me.cmdTrainNetwork.Text = "Train Network"
  101.         Me.cmdTrainNetwork.Size = New System.Drawing.Size(121, 25)
  102.         Me.cmdTrainNetwork.Location = New System.Drawing.Point(16, 32)
  103.         Me.cmdTrainNetwork.TabIndex = 2
  104.         Me.cmdTrainNetwork.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  105.         Me.cmdTrainNetwork.BackColor = System.Drawing.SystemColors.Control
  106.         Me.cmdTrainNetwork.CausesValidation = True
  107.         Me.cmdTrainNetwork.Enabled = True
  108.         Me.cmdTrainNetwork.ForeColor = System.Drawing.SystemColors.ControlText
  109.         Me.cmdTrainNetwork.Cursor = System.Windows.Forms.Cursors.Default
  110.         Me.cmdTrainNetwork.RightToLeft = System.Windows.Forms.RightToLeft.No
  111.         Me.cmdTrainNetwork.TabStop = True
  112.         Me.cmdTrainNetwork.Name = "cmdTrainNetwork"
  113.         Me.cmdClose.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
  114.         Me.cmdClose.Text = "Close"
  115.         Me.cmdClose.Size = New System.Drawing.Size(81, 25)
  116.         Me.cmdClose.Location = New System.Drawing.Point(128, 288)
  117.         Me.cmdClose.TabIndex = 1
  118.         Me.cmdClose.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  119.         Me.cmdClose.BackColor = System.Drawing.SystemColors.Control
  120.         Me.cmdClose.CausesValidation = True
  121.         Me.cmdClose.Enabled = True
  122.         Me.cmdClose.ForeColor = System.Drawing.SystemColors.ControlText
  123.         Me.cmdClose.Cursor = System.Windows.Forms.Cursors.Default
  124.         Me.cmdClose.RightToLeft = System.Windows.Forms.RightToLeft.No
  125.         Me.cmdClose.TabStop = True
  126.         Me.cmdClose.Name = "cmdClose"
  127.         Me.cmdGetNetworkOutput.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
  128.         Me.cmdGetNetworkOutput.Text = "Get Network Output"
  129.         Me.cmdGetNetworkOutput.Size = New System.Drawing.Size(121, 25)
  130.         Me.cmdGetNetworkOutput.Location = New System.Drawing.Point(16, 96)
  131.         Me.cmdGetNetworkOutput.TabIndex = 0
  132.         Me.cmdGetNetworkOutput.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  133.         Me.cmdGetNetworkOutput.BackColor = System.Drawing.SystemColors.Control
  134.         Me.cmdGetNetworkOutput.CausesValidation = True
  135.         Me.cmdGetNetworkOutput.Enabled = True
  136.         Me.cmdGetNetworkOutput.ForeColor = System.Drawing.SystemColors.ControlText
  137.         Me.cmdGetNetworkOutput.Cursor = System.Windows.Forms.Cursors.Default
  138.         Me.cmdGetNetworkOutput.RightToLeft = System.Windows.Forms.RightToLeft.No
  139.         Me.cmdGetNetworkOutput.TabStop = True
  140.         Me.cmdGetNetworkOutput.Name = "cmdGetNetworkOutput"
  141.         Me.Frame1.Text = "Press the buttons to run the sample functions"
  142.         Me.Frame1.Size = New System.Drawing.Size(313, 81)
  143.         Me.Frame1.Location = New System.Drawing.Point(8, 8)
  144.         Me.Frame1.TabIndex = 5
  145.         Me.Frame1.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  146.         Me.Frame1.BackColor = System.Drawing.SystemColors.Control
  147.         Me.Frame1.Enabled = True
  148.         Me.Frame1.ForeColor = System.Drawing.SystemColors.ControlText
  149.         Me.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No
  150.         Me.Frame1.Visible = True
  151.         Me.Frame1.Name = "Frame1"
  152.         Me.txtTrainNetwork.AutoSize = False
  153.         Me.txtTrainNetwork.Size = New System.Drawing.Size(161, 25)
  154.         Me.txtTrainNetwork.Location = New System.Drawing.Point(144, 24)
  155.         Me.txtTrainNetwork.ReadOnly = True
  156.         Me.txtTrainNetwork.TabIndex = 6
  157.         Me.txtTrainNetwork.Text = "Not Tested."
  158.         Me.txtTrainNetwork.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  159.         Me.txtTrainNetwork.AcceptsReturn = True
  160.         Me.txtTrainNetwork.TextAlign = System.Windows.Forms.HorizontalAlignment.Left
  161.         Me.txtTrainNetwork.BackColor = System.Drawing.SystemColors.Window
  162.         Me.txtTrainNetwork.CausesValidation = True
  163.         Me.txtTrainNetwork.Enabled = True
  164.         Me.txtTrainNetwork.ForeColor = System.Drawing.SystemColors.WindowText
  165.         Me.txtTrainNetwork.HideSelection = True
  166.         Me.txtTrainNetwork.Maxlength = 0
  167.         Me.txtTrainNetwork.Cursor = System.Windows.Forms.Cursors.IBeam
  168.         Me.txtTrainNetwork.MultiLine = False
  169.         Me.txtTrainNetwork.RightToLeft = System.Windows.Forms.RightToLeft.No
  170.         Me.txtTrainNetwork.ScrollBars = System.Windows.Forms.ScrollBars.None
  171.         Me.txtTrainNetwork.TabStop = True
  172.         Me.txtTrainNetwork.Visible = True
  173.         Me.txtTrainNetwork.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
  174.         Me.txtTrainNetwork.Name = "txtTrainNetwork"
  175.         Me.Frame2.Size = New System.Drawing.Size(313, 161)
  176.         Me.Frame2.Location = New System.Drawing.Point(8, 80)
  177.         Me.Frame2.TabIndex = 7
  178.         Me.Frame2.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  179.         Me.Frame2.BackColor = System.Drawing.SystemColors.Control
  180.         Me.Frame2.Enabled = True
  181.         Me.Frame2.ForeColor = System.Drawing.SystemColors.ControlText
  182.         Me.Frame2.RightToLeft = System.Windows.Forms.RightToLeft.No
  183.         Me.Frame2.Visible = True
  184.         Me.Frame2.Name = "Frame2"
  185.         Me.txtNetworkOutput.AutoSize = False
  186.         Me.txtNetworkOutput.Font = New System.Drawing.Font("Courier New", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  187.         Me.txtNetworkOutput.Size = New System.Drawing.Size(297, 105)
  188.         Me.txtNetworkOutput.Location = New System.Drawing.Point(8, 48)
  189.         Me.txtNetworkOutput.ReadOnly = True
  190.         Me.txtNetworkOutput.MultiLine = True
  191.         Me.txtNetworkOutput.ScrollBars = System.Windows.Forms.ScrollBars.Both
  192.         Me.txtNetworkOutput.WordWrap = False
  193.         Me.txtNetworkOutput.TabIndex = 8
  194.         Me.txtNetworkOutput.Text = "Not Tested." & Chr(13) & Chr(10)
  195.         Me.txtNetworkOutput.AcceptsReturn = True
  196.         Me.txtNetworkOutput.TextAlign = System.Windows.Forms.HorizontalAlignment.Left
  197.         Me.txtNetworkOutput.BackColor = System.Drawing.SystemColors.Window
  198.         Me.txtNetworkOutput.CausesValidation = True
  199.         Me.txtNetworkOutput.Enabled = True
  200.         Me.txtNetworkOutput.ForeColor = System.Drawing.SystemColors.WindowText
  201.         Me.txtNetworkOutput.HideSelection = True
  202.         Me.txtNetworkOutput.Maxlength = 0
  203.         Me.txtNetworkOutput.Cursor = System.Windows.Forms.Cursors.IBeam
  204.         Me.txtNetworkOutput.RightToLeft = System.Windows.Forms.RightToLeft.No
  205.         Me.txtNetworkOutput.TabStop = True
  206.         Me.txtNetworkOutput.Visible = True
  207.         Me.txtNetworkOutput.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
  208.         Me.txtNetworkOutput.Name = "txtNetworkOutput"
  209.         Me.Label1.TextAlign = System.Drawing.ContentAlignment.TopCenter
  210.         Me.Label1.Text = "The sample functions associated with these buttons have been modified to work with your training data."
  211.         Me.Label1.Size = New System.Drawing.Size(273, 33)
  212.         Me.Label1.Location = New System.Drawing.Point(32, 248)
  213.         Me.Label1.TabIndex = 3
  214.         Me.Label1.Font = New System.Drawing.Font("Arial", 8!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  215.         Me.Label1.BackColor = System.Drawing.SystemColors.Control
  216.         Me.Label1.Enabled = True
  217.         Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText
  218.         Me.Label1.Cursor = System.Windows.Forms.Cursors.Default
  219.         Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
  220.         Me.Label1.UseMnemonic = True
  221.         Me.Label1.Visible = True
  222.         Me.Label1.AutoSize = False
  223.         Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
  224.         Me.Label1.Name = "Label1"
  225.         Me.Controls.Add(chkResetNetwork)
  226.         Me.Controls.Add(cmdTrainNetwork)
  227.         Me.Controls.Add(cmdClose)
  228.         Me.Controls.Add(cmdGetNetworkOutput)
  229.         Me.Controls.Add(Frame1)
  230.         Me.Controls.Add(Frame2)
  231.         Me.Controls.Add(Label1)
  232.         Me.Frame1.Controls.Add(txtTrainNetwork)
  233.         Me.Frame2.Controls.Add(txtNetworkOutput)
  234.     End Sub
  235. #End Region 
  236. #Region "Upgrade Support "
  237.     Private Shared m_vb6FormDefInstance As VBShellDlg
  238.     Private Shared m_InitializingDefInstance As Boolean
  239.     Public Shared Property DefInstance() As VBShellDlg
  240.         Get
  241.             If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
  242.                 m_InitializingDefInstance = True
  243.                 m_vb6FormDefInstance = New VBShellDlg()
  244.                 m_InitializingDefInstance = False
  245.             End If
  246.             DefInstance = m_vb6FormDefInstance
  247.         End Get
  248.         Set
  249.             m_vb6FormDefInstance = Value
  250.         End Set
  251.     End Property
  252. #End Region 
  253.     
  254.     Private Sub cmdClose_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdClose.Click
  255.         Me.Close()
  256.     End Sub
  257.     
  258.     Private Sub VBShellDlg_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
  259.         resetNetwork = True
  260.         chkResetNetwork.CheckState = System.Windows.Forms.CheckState.Checked
  261.         
  262.         If RECALL_ONLY_NETWORK = True Then
  263.             txtTrainNetwork.Text = "Recall Network Only."
  264.             cmdTrainNetwork.Enabled = False
  265.             chkResetNetwork.Enabled = False
  266.         Else
  267.             txtTrainNetwork.Text = "Not tested."
  268.         End If
  269.         
  270.         txtNetworkOutput.Text = "Not tested."
  271.     End Sub
  272.     
  273.     Private Sub cmdGetNetworkOutput_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdGetNetworkOutput.Click
  274.         
  275.         'Get the network response as an array of outputs
  276.         Dim networkResponse As Object
  277.         networkResponse = GetNetworkResponse()
  278.  
  279.         'Clear contents of the list box
  280.         txtNetworkOutput.Text = ""
  281.  
  282.         'Get/Create the column labels for the output data
  283.         Dim outputLabelsArray As Object
  284.         Dim i As Integer
  285.         Dim outputLabels As String
  286.         If CheckIfFileOnFileSystem(DATA_PATH & "\", DESIRED_FILE_NAME) = True Then
  287.             FileOpen(1, DATA_PATH & "\" & DESIRED_FILE_NAME, OpenMode.Input)
  288.             outputLabels = LineInput(1)
  289.             FileClose(1)
  290.             outputLabelsArray = Split(outputLabels, Chr(9))
  291.         Else
  292.             ReDim outputLabelsArray(UBound(networkResponse, 2))
  293.             For i = LBound(outputLabelsArray) To UBound(outputLabelsArray)
  294.                 outputLabelsArray(i) = "Output#" & i + 1
  295.             Next i
  296.         End If
  297.  
  298.         Dim numberOfTrailingSpaces As Short
  299.         Dim outStr As String
  300.         outStr = "Exemplar#"
  301.         For i = LBound(outputLabelsArray) To UBound(outputLabelsArray)
  302.             numberOfTrailingSpaces = 9 - Len(outputLabelsArray(i))
  303.             If (numberOfTrailingSpaces > 0) Then
  304.                 outStr = outStr & Chr(9) & outputLabelsArray(i) & Space(numberOfTrailingSpaces)
  305.             Else
  306.                 outStr = outStr & Chr(9) & VB.Left(outputLabelsArray(i), 9)
  307.             End If
  308.         Next i
  309.         outStr = outStr & vbCrLf
  310.  
  311.         'Prepare output data for display in text box. Limit to 1000 rows.
  312.         Dim j As Integer
  313.         Dim maxRows As Integer
  314.         maxRows = IIf(UBound(networkResponse, 1) > 1000, 1000, UBound(networkResponse, 1))
  315.         For i = LBound(networkResponse, 1) To UBound(networkResponse, 1)
  316.             outStr = outStr & VB6.Format(i + 1, "00000") & "    "
  317.             For j = LBound(networkResponse, 2) To UBound(networkResponse, 2)
  318.                 outStr = outStr & Chr(9) & VB6.Format(networkResponse(i, j), "0.0000000")
  319.             Next j
  320.             outStr = outStr & vbCrLf
  321.         Next i
  322.  
  323.         'Display output data in text box
  324.         txtNetworkOutput.Text = outStr
  325.         
  326.     End Sub
  327.     
  328.     Private Sub chkResetNetwork_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkResetNetwork.CheckStateChanged
  329.         If chkResetNetwork.CheckState = System.Windows.Forms.CheckState.Checked Then
  330.             resetNetwork = True
  331.         Else
  332.             resetNetwork = False
  333.         End If
  334.     End Sub
  335.  
  336.     Private Sub cmdTrainNetwork_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdTrainNetwork.Click
  337.         txtTrainNetwork.Text = "Training..."
  338.         txtTrainNetwork.Refresh()
  339.  
  340.         Dim trainingBestCost As Object
  341.         trainingBestCost = TrainNetwork()
  342.         txtTrainNetwork.Text = "Best Cost = " & trainingBestCost
  343.     End Sub
  344.  
  345.     Function CheckIfFileOnFileSystem(ByRef filePath As String, ByRef fileName As String) As Boolean
  346.         'Determine if a file with the given fileName exists in the given filePath
  347.         On Error GoTo ErrorHandler
  348.         Dim filePathName As String
  349.         filePathName = filePath & fileName
  350.         If StrComp(Dir(filePathName, FileAttribute.Normal), fileName, CompareMethod.Text) <> 0 Then
  351.             CheckIfFileOnFileSystem = False
  352.         Else
  353.             CheckIfFileOnFileSystem = True
  354.         End If
  355.         On Error GoTo 0
  356.         Exit Function
  357. ErrorHandler:
  358.         CheckIfFileOnFileSystem = False
  359.     End Function
  360. End Class