Dictionary Builder Part 1 Getting Started
Step 1 – build the Form Controls: grpInput btnOpenDictionary lstWords btnExtractWords txtNewWord btnAddWord btnOpenDictionary lstWords btnSave btnExit + and assorted labels
Which control will provide the easiest place to start? Step 2 – start easy Which control will provide the easiest place to start?
Which control will provide the easiest place to start? btnAddWord. Step 2 – start easy Which control will provide the easiest place to start? btnAddWord.
Step 2 – btnAddWord What does it do?
Step 2 – btnAddWord What does it do? It moves a word from the textBox to the listBox.
Step 2 – btnAddWord What does it do? How? It moves a word from the textBox to the listBox. How?
Step 2 – btnAddWord What does it do? How? It moves a word from the textBox to the listBox. How? if there's something in the textBox
Step 2 – btnAddWord What does it do? How? It moves a word from the textBox to the listBox. How? if there's something in the textBox copy it to the listBox
Step 2 – btnAddWord What does it do? How? What else should be done? It moves a word from the textBox to the listBox. How? if there's something in the textBox copy it to the listBox What else should be done?
Step 2 – btnAddWord What does it do? How? It moves a word from the textBox to the listBox. How? if there's something in the textBox copy it to the listBox set the focus back in the textBox
Step 2 – btnAddWord What does it do? How? It moves a word from the textBox to the listBox. How? if there's something in the textBox copy it to the listBox set the focus back in the textBox clear the textBox
BUT not everything should go into the listBox
BUT not everything should go into the listBox What conditions should be imposed on the text strings entered by the User?
BUT not everything should go into the listBox We need to deal with “words” that: have UPPER case characters
BUT not everything should go into the listBox We need to deal with “words” that: have UPPER case characters are too long
BUT not everything should go into the listBox We need to deal with “words” that: have UPPER case characters are too long have non-alpha characters
BUT not everything should go into the listBox We need to deal with “words” that: have UPPER case characters are too long have non-alpha characters duplicate a word in the list
BUT not everything should go into the listBox We need to deal with “words” that: have UPPER case characters are too long have non-alpha characters duplicate a word in the list These tasks will be facilitated by using an identifier instead of object.property notation, and sub-programs.
Step 2 – btnAddWord Revisiting our pseudo code… if there's something in the textBox copy it to the listBox set the focus back in the textBox clear the textBox
Step 2 – btnAddWord If txtWord.Text <> vbNullString Then End If
Step 2 – btnAddWord If txtWord.Text <> vbNullString Then Dim newWord = LCase(txtWord.Text) lstWords.Items.Add(newWord) End If
Step 2 – btnAddWord If txtWord.Text <> vbNullString Then Dim newWord = LCase(txtWord.Text) lstWords.Items.Add(newWord) txtWord.Focus() End If
Step 2 – btnAddWord If txtWord.Text <> vbNullString Then Dim newWord = LCase(txtWord.Text) lstWords.Items.Add(newWord) txtWord.Focus() txtWord.Clear() End If
Step 2 – btnAddWord If txtWord.Text <> vbNullString Then Dim newWord = LCase(txtWord.Text) If Len(newWord) <= 11 Then lstWords.Items.Add(newWord) txtWord.Focus() txtWord.Clear() End If
Step 2 – btnAddWord If txtWord.Text <> vbNullString Then Dim newWord = LCase(txtWord.Text) If Len(newWord) <= 11 Then lstWords.Items.Add(newWord) txtWord.Focus() txtWord.Clear() Else txtWord.SelectAll() End If
Step 2 – btnAddWord If txtWord.Text <> vbNullString Then Dim newWord = LCase(txtWord.Text) If Len(newWord) <= 11 And isWord(newWord) Then lstWords.Items.Add(newWord) txtWord.Focus() txtWord.Clear() Else txtWord.SelectAll() End If
Step 2.1 – isWord() Private Function isWord() End Function
Step 2.1 – isWord() Private Function isWord(ByVal t As String) As Boolean End Function
Step 2.1 – isWord() Private Function isWord(ByVal t As String) As Boolean Return ??? End Function
Step 2.1 – isWord() Private Function isWord(ByVal t As String) As Boolean Return flag End Function
Step 2.1 – isWord() Private Function isWord(ByVal t As String As Boolean Dim flag = True Return flag End Function
Step 2.1 – isWord() Private Function isWord(ByVal t As String) As Boolean Dim flag = True Dim c As Integer For c = 1 To Len(t) ˈ under some condition flag = False Next Return flag End Function
Step 2.1 – isWord() Private Function isWord(ByVal t As String) As Boolean Dim flag = True Dim c As Integer For c = 1 To Len(t) Dim thisC = Mid(t, c, 1) If thisC < "a" Or thisC > "z" Then flag = False End If Next Return flag End Function
Step 2.1 – isWord() Private Function isWord(ByVal t As String) As Boolean Dim flag = True Dim c As Integer For c = 1 To Len(t) Dim thisC = Mid(t, c, 1) If thisC < "a" Or thisC > "z" Then flag = False Exit For End If Next Return flag End Function
Step 2.2 - isUnique() End Function Private Function isUnique(ByVal t As String) As Boolean End Function
Step 2.2 - isUnique() Dim flag = True Return flag End Function Private Function isUnique(ByVal t As String) As Boolean Dim flag = True Return flag End Function
Step 2.2 - isUnique() Dim flag = True Dim i As Integer Private Function isUnique(ByVal t As String) As Boolean Dim flag = True Dim i As Integer For i = 0 To lstWords.Items.Count - 1 ˈ under some condition flag = False Next Return flag End Function
Step 2.2 - isUnique() Dim flag = True Dim i As Integer Private Function isUnique(ByVal t As String) As Boolean Dim flag = True Dim i As Integer For i = 0 To lstWords.Items.Count - 1 If t = lstWords.Items.Item(i) Then flag = False Exit For End If Next Return flag End Function