home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / PROGRAMS / CH7 / 7-2-5.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-11-02  |  3.9 KB  |  124 lines

  1. VERSION 5.00
  2. Begin VB.Form frmAdding 
  3.    Caption         =   "Adding to an Ordered Array"
  4.    ClientHeight    =   960
  5.    ClientLeft      =   900
  6.    ClientTop       =   1995
  7.    ClientWidth     =   6720
  8.    BeginProperty Font 
  9.       Name            =   "MS Sans Serif"
  10.       Size            =   8.25
  11.       Charset         =   0
  12.       Weight          =   700
  13.       Underline       =   0   'False
  14.       Italic          =   0   'False
  15.       Strikethrough   =   0   'False
  16.    EndProperty
  17.    LinkTopic       =   "Form1"
  18.    PaletteMode     =   1  'UseZOrder
  19.    ScaleHeight     =   960
  20.    ScaleWidth      =   6720
  21.    Begin VB.CommandButton cmdAddSpok 
  22.       Caption         =   "Add to Spoken List"
  23.       Height          =   375
  24.       Left            =   4800
  25.       TabIndex        =   4
  26.       Top             =   120
  27.       Width           =   1815
  28.    End
  29.    Begin VB.PictureBox picAllLang 
  30.       Height          =   255
  31.       Left            =   120
  32.       ScaleHeight     =   195
  33.       ScaleWidth      =   6435
  34.       TabIndex        =   3
  35.       Top             =   600
  36.       Width           =   6495
  37.    End
  38.    Begin VB.CommandButton cmdAddComp 
  39.       Caption         =   "Add to Computer List"
  40.       Height          =   375
  41.       Left            =   2760
  42.       TabIndex        =   2
  43.       Top             =   120
  44.       Width           =   1935
  45.    End
  46.    Begin VB.TextBox txtLang 
  47.       Height          =   285
  48.       Left            =   1440
  49.       TabIndex        =   1
  50.       Top             =   120
  51.       Width           =   1215
  52.    End
  53.    Begin VB.Label lblNew 
  54.       Caption         =   "New language:"
  55.       Height          =   255
  56.       Left            =   120
  57.       TabIndex        =   0
  58.       Top             =   120
  59.       Width           =   1335
  60.    End
  61. Attribute VB_Name = "frmAdding"
  62. Attribute VB_GlobalNameSpace = False
  63. Attribute VB_Creatable = False
  64. Attribute VB_PredeclaredId = True
  65. Attribute VB_Exposed = False
  66. Dim compLang(1 To 20) As String
  67. Dim spokLang(1 To 20) As String
  68. Dim numCompLangs As Integer
  69. Dim numSpokLangs As Integer
  70. Private Sub AddALang(lang() As String, langCount As Integer)
  71.   Dim language As String, n As Integer, i As Integer
  72.   'Insert a language into an ordered array of languages
  73.   language = Trim(txtLang.Text)
  74.   n = 0
  75.     n = n + 1
  76.   Loop Until (UCase(lang(n)) >= UCase(language)) Or (n = langCount)
  77.   If UCase(lang(n)) < UCase(language) Then    'Insert new language at end
  78.       lang(langCount + 1) = language
  79.       langCount = langCount + 1
  80.     ElseIf UCase(lang(n)) > UCase(language) Then    'Insert before item n
  81.       For i = langCount To n Step -1
  82.         lang(i + 1) = lang(i)
  83.       Next i
  84.       lang(n) = language
  85.       langCount = langCount + 1
  86.   End If
  87. End Sub
  88. Private Sub cmdAddComp_Click()
  89.   'Insert language into ordered array of computer languages
  90.   Call AddALang(compLang(), numCompLangs)
  91.   Call DisplayArray(compLang(), numCompLangs)
  92. End Sub
  93. Private Sub cmdAddSpok_Click()
  94.   'Insert language into ordered array of spoken languages
  95.   Call AddALang(spokLang(), numSpokLangs)
  96.   Call DisplayArray(spokLang(), numSpokLangs)
  97. End Sub
  98. Private Sub DisplayArray(lang() As String, howMany As Integer)
  99.   Dim i As Integer
  100.   'Display the languages in the array
  101.   picAllLang.Cls
  102.   For i = 1 To howMany
  103.     picAllLang.Print lang(i) & "  ";
  104.   Next i
  105. End Sub
  106. Private Sub Form_Load()
  107.   'Fill computer language array from COMPLANG.TXT
  108.   numCompLangs = 0
  109.   Open App.Path & "\COMPLANG.TXT" For Input As #1
  110.   Do While (Not EOF(1)) And (numCompLangs < 20)
  111.     numCompLangs = numCompLangs + 1
  112.     Input #1, compLang(numCompLangs)
  113.   Loop
  114.   Close #1
  115.   'Fill spoken language array from SPOKLANG.TXT
  116.   numSpokLangs = 0
  117.   Open App.Path & "\SPOKLANG.TXT" For Input As #1
  118.   Do While (Not EOF(1)) And (numSpokLangs < 20)
  119.     numSpokLangs = numSpokLangs + 1
  120.     Input #1, spokLang(numSpokLangs)
  121.   Loop
  122.   Close #1
  123. End Sub
  124.