home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 July / Disc 1 / PCU0703CD1.iso / software / online / files / imacros.exe / FORM1.VB < prev    next >
Encoding:
Text File  |  2002-12-03  |  6.2 KB  |  167 lines

  1. Public Class Form1
  2.     Inherits System.Windows.Forms.Form
  3.  
  4. #Region " Windows Form Designer generated code "
  5.  
  6.     Public Sub New()
  7.         MyBase.New()
  8.  
  9.         'This call is required by the Windows Form Designer.
  10.         InitializeComponent()
  11.  
  12.         'Add any initialization after the InitializeComponent() call
  13.  
  14.     End Sub
  15.  
  16.     'Form overrides dispose to clean up the component list.
  17.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  18.         If disposing Then
  19.             If Not (components Is Nothing) Then
  20.                 components.Dispose()
  21.             End If
  22.         End If
  23.         MyBase.Dispose(disposing)
  24.     End Sub
  25.  
  26.     'Required by the Windows Form Designer
  27.     Private components As System.ComponentModel.IContainer
  28.  
  29.     'NOTE: The following procedure is required by the Windows Form Designer
  30.     'It can be modified using the Windows Form Designer.  
  31.     'Do not modify it using the code editor.
  32.     Friend WithEvents Button1 As System.Windows.Forms.Button
  33.     Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
  34.     Friend WithEvents Label1 As System.Windows.Forms.Label
  35.     Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
  36.     Friend WithEvents Button2 As System.Windows.Forms.Button
  37.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  38.         Me.Button1 = New System.Windows.Forms.Button()
  39.         Me.TextBox1 = New System.Windows.Forms.TextBox()
  40.         Me.Label1 = New System.Windows.Forms.Label()
  41.         Me.CheckBox1 = New System.Windows.Forms.CheckBox()
  42.         Me.Button2 = New System.Windows.Forms.Button()
  43.         Me.SuspendLayout()
  44.         '
  45.         'Button1
  46.         '
  47.         Me.Button1.Location = New System.Drawing.Point(8, 16)
  48.         Me.Button1.Name = "Button1"
  49.         Me.Button1.Size = New System.Drawing.Size(120, 64)
  50.         Me.Button1.TabIndex = 0
  51.         Me.Button1.Text = "Run wsh-extract.iim macro and return results to VB.NET"
  52.         '
  53.         'TextBox1
  54.         '
  55.         Me.TextBox1.BackColor = System.Drawing.SystemColors.Info
  56.         Me.TextBox1.Location = New System.Drawing.Point(144, 48)
  57.         Me.TextBox1.Multiline = True
  58.         Me.TextBox1.Name = "TextBox1"
  59.         Me.TextBox1.Size = New System.Drawing.Size(112, 32)
  60.         Me.TextBox1.TabIndex = 1
  61.         Me.TextBox1.Text = "TextBox1"
  62.         '
  63.         'Label1
  64.         '
  65.         Me.Label1.Location = New System.Drawing.Point(144, 24)
  66.         Me.Label1.Name = "Label1"
  67.         Me.Label1.Size = New System.Drawing.Size(100, 16)
  68.         Me.Label1.TabIndex = 2
  69.         Me.Label1.Text = "Status:"
  70.         '
  71.         'CheckBox1
  72.         '
  73.         Me.CheckBox1.Location = New System.Drawing.Point(16, 96)
  74.         Me.CheckBox1.Name = "CheckBox1"
  75.         Me.CheckBox1.Size = New System.Drawing.Size(240, 16)
  76.         Me.CheckBox1.TabIndex = 3
  77.         Me.CheckBox1.Text = "Run in System Tray"
  78.         '
  79.         'Button2
  80.         '
  81.         Me.Button2.Location = New System.Drawing.Point(224, 120)
  82.         Me.Button2.Name = "Button2"
  83.         Me.Button2.Size = New System.Drawing.Size(48, 24)
  84.         Me.Button2.TabIndex = 4
  85.         Me.Button2.Text = "Exit"
  86.         '
  87.         'Form1
  88.         '
  89.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
  90.         Me.ClientSize = New System.Drawing.Size(292, 157)
  91.         Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button2, Me.CheckBox1, Me.Label1, Me.TextBox1, Me.Button1})
  92.         Me.Name = "Form1"
  93.         Me.Text = "VB.NET Scripting Interface Demo"
  94.         Me.ResumeLayout(False)
  95.  
  96.     End Sub
  97.  
  98. #End Region
  99.     Dim iim1 As Object
  100.     Dim iret As Integer
  101.     Dim iplay As Integer
  102.     Dim s As String
  103.     Dim sExtractedText As String
  104.     Dim sPart0 As String
  105.     Dim sPart1 As String
  106.     Dim sSplit() As String 'Array to hold the results of the SPLIT command
  107.  
  108.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  109.  
  110.         'Create an object based on the Scripting Interface
  111.         'This way we can copy & paste all the VBS (Windows Scripting) example code
  112.         'directly into a VB.NET project
  113.         TextBox1.Text = "Initializing..."
  114.         iim1 = CreateObject("iimwsh.iim")
  115.  
  116.         If CheckBox1.Checked = True Then
  117.             iret = iim1.iimInit("-tray", True)
  118.         Else
  119.             iret = iim1.iimInit("", True)
  120.         End If
  121.  
  122.         'Tip: With iret = iim1.iimInit(sCmdLine, FALSE) you can ask the Scripting Interface to
  123.         'connect to an already open IIM browser. If there is no IIM browser open, the return value
  124.         'will be negative.
  125.  
  126.         TextBox1.Text = "Set Display..."
  127.         iret = iim1.iimDisplay("Extract Example")
  128.  
  129.         'Normally the Scripting Interface waits about 10 seconds before a Scripting Interface
  130.         'timeout error occurs (for example, if a user closed the IIM browser while it was running,
  131.         'please do not confuse this with the BROWSER timeout errors if a web page loads too slow.)
  132.         'iret = iim1.iimSetInternal("INTERFACETIMEOUT", 1)  'reduce the interface timeout to 1s
  133.  
  134.         TextBox1.Text = "Running Macro..."
  135.         If CheckBox1.Checked = True Then iret = iim1.iimSet("-tray", "") 'apply settings before every PLAY command 
  136.         iplay = iim1.iimPlay("wsh-extract")
  137.         sExtractedText = iim1.iimGetLastMessage()
  138.         iret = iim1.iimExit
  139.  
  140.         If iplay = 2 Then
  141.             TextBox1.Text = "Done!"
  142.             sSplit = Split(sExtractedText, "[EXTRACT]")
  143.             sPart0 = sSplit(0)
  144.             If UBound(sSplit) > 0 Then sPart1 = sSplit(1)
  145.             s = "One US$ costs " + sPart0 + " EURO or " + sPart1 + " British Pounds (GBP)"
  146.             MsgBox(s)
  147.             TextBox1.Text = "Done!"
  148.         End If
  149.  
  150.         If iplay = 1 Then
  151.             TextBox1.Text = "Done, but no data extracted"
  152.         End If
  153.  
  154.         If iplay < 0 Then
  155.             'In this case, sExtractedText contains
  156.             ' the *error* information returned by iimGetLastMessage()
  157.             TextBox1.Text = sExtractedText
  158.         End If
  159.  
  160.     End Sub
  161.  
  162.  
  163.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  164.         End
  165.     End Sub
  166. End Class
  167.