1/17/06
In class talking about search program
JavaScript and VbScript
JavaScript is on pg 696 on your text book
4 things needed to search
interaction - request
data has to be stored somewhere either in file or in an array
file-you can store a lot of data
Array - you can not have too much data. Faster than file also it is part of program, any change you make you have to change in compile
respond- if match is succeeded it will respond if not it will fail
loop it (one or more)
Vb uses parentheses for array in contrast to bracket[ ] in other languages
" if " statement is same
loop is almost same, you don't have all the variables together
dim english=("water"," house"," book", "university", "car", "computer")
dim spanish = ("aqua", "casa", "libro", "universidad", "caro", "computador")
dim result = 0
dim searchword as string
searchword = inputbox("ENTER ENGLISH WORD TO TRANSLATE")
for i=0 to 5
if searchword = english(i) then
msgbox("Spanish word is "&spanish(i))
else
msgbox("SORRY, No match for : "&searchword)
end if
next i
Array and loop comes together
An array is a contiguous and homogeneous memory location identified by a name. The access to each location is done through an index or subscript. Contiguous means the locations (memories) that are continuously next to each other. Homogeneous meaning the cells can only hold data of the same kind. All the data is of the same type: integer, single, double, etc. The index is a number that represents each room, beginning with 0 and ending with a defined maximum value. The index uniquely identifies each cell allowing access to a corresponding location.
Public
Class Form1 Inherits System.Windows.Forms.Form#
Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer.InitializeComponent()
'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Thencomponents.Dispose()
End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor.<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent() ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 266) Me.Name = "Form1" Me.Text = "Form1" End Sub#
End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim result As Integer = 0 Dim i As Integer Dim searchword As String Dim english() = {"water", "house", "book", "university", "car", "computer"} Dim spanish() = {"aqua", "casa", "libro", "universidad", "caro", "computador"} While 1searchword = InputBox("ENTER ENGLISH WORD TO TRANSLATE")
If searchword = "" Then End End If For i = 0 To 5 If searchword = english(i) ThenMsgBox("Spanish word is " & spanish(i))
result = 1
End If Next i If (result = 0) ThenMsgBox("SORRY, No match for : " & searchword)
End If End While End SubEnd
Class
Program in pg 139 & pg 140 is identical. Program in pg 139 doesn't use array. pg 140 uses array. pg 159 use array but take advantage of it.
As promised students working on midterms.