-
I have a program that I want to pull data out of a multi-line text box. Each line of the text box contains some numbers.
I want to be able to read the text in the text box one line at a time, evaluate it and place the results into a second text box.
For example if the text box contains:
' this is the exact format of the text in the textbox.
0100
110
101
10
In my program 0100 will equal blue, 110 will equal orange, 10 will equal red and 101 will equal brown. So when I hit a button I want the second text box to print:
blue
orange
brown
red.
Any suggestions?
twicel
-
Dictionary Object
Normally, you can do this by using an Array and Split function. But I think it will be a bit slow when you perform the comparison. So, I juz come out an idea of using the Dictionary object in Visual Basic like below:
Code:
Option Explicit
Private dict As Dictionary
Private Sub Form_Load()
'Create Dictionary Object for faster searching performance
'For the Dictionary Object, you need to reference to
'Microsoft Scripting Library (scrrun.dll)
Set dict = New Dictionary
With dict
'Set the compare mode
.CompareMode = TextCompare
.Add "100", "blue"
.Add "110", "orange"
.Add "101", "brown"
.Add "10", "red"
End With
Text1 = "100" & vbCrLf & "110" & vbCrLf & "101" & vbCrLf & "10"
End Sub
Private Sub Command1_Click()
Dim bData As Variant
Dim bArray As Variant
bArray = Split(Text1, vbCrLf, -1, vbTextCompare)
For Each bData In bArray
If dict.Exists(bData) Then Text2 = Text2 & dict.Item(bData) & vbCrLf
Next
End Sub