Input text display output text
Page 1 of 110 Replies - 1018 Views - Last Post: 05 May 2011 - 02:57 PM
#1
Input text display output text
Posted 04 May 2011 - 07:04 AM
Basically, I want to have a text box that will display text associated with the text input.
For Example:
input : 512
output : TEXAS
or
input : 659
output : ALABAMA
I have heard that it is possible to do this, and I would like to find out a way to. Even if I need a separate text file with the arrays, I would like to get this to work.
Replies To: Input text display output text
#2
Re: Input text display output text
Posted 04 May 2011 - 08:18 AM
Here you have details and examples for this class.
After you have all the values in the dictionary, treat the TextChanged event on your input textbox and get the string accordingly with the integer value introduced by the user.
#3
Re: Input text display output text
Posted 04 May 2011 - 08:54 AM
Ionut, on 04 May 2011 - 08:18 AM, said:
Here you have details and examples for this class.
After you have all the values in the dictionary, treat the TextChanged event on your input textbox and get the string accordingly with the integer value introduced by the user.
What would the code look like? How would I link to the text file or xls? Im thinking of creating the array in excel for formatting reasons. Like I said before Im completely new to this and basically this is the last step for me. I do however appreciate what has been cone so far.
#4
Re: Input text display output text
Posted 04 May 2011 - 09:20 AM
Dim bar As New Dictionary(Of Int32, String)
bar.Add(1, "b")
bar.Add(2, "zz")
bar.Add(3, "ww")
bar.Add(4, "sadf")
Console.WriteLine(bar(4)) '-- found so it prints out "sadf"
'-- Console.WriteLine(bar(5)) '-- causes exception - it's best to check if that value was in there first.
If bar.ContainsKey(5) Then
Console.WriteLine(bar(5))
End If
As for reading from a file - that uses the stream reader. You can read about it here:
http://msdn.microsof...reamreader.aspx
It is a quick method of read a text file. It's your job to parse the text file correctly else you'll just get lines and lines from in the file and do nothing with them.
For example, say your text file is nothing but lines of a number, a comma, and a string.
Example:
1,b
2,zz
3,ww
4,sadf
...
You would want to read in a line (for example the line of 1,
One might proceed like this:
Dim sr As New StreamReader("<path>") '-- tell it your path.
Dim line As String = String.Empty '-- holds the each line you get in.
Dim arrayOfStrings() As String '-- using the split method of the string on the comma, it returns two strings.. before and after the comma
Dim myDictionary As New Dictionary(Of Int32, String) '-- same as above.
While line IsNot Nothing '-- loop through all the file's rows
line = sr.ReadLine '-- get the next line
arrayOfStrings = line.Split(",") '-- doing the split to get the two strings around the comma
myDictionary.Add(arrayOfStrings(0), arrayOfStrings(1)) '-- adding them to the dictionary.
End While
There you go.. the tools to get what you want done.
I would avoid using an Excel file - that's more complicated.
#5
Re: Input text display output text
Posted 04 May 2011 - 09:40 AM
Thanks!
#6
Re: Input text display output text
Posted 04 May 2011 - 09:45 AM
klturi421, on 04 May 2011 - 11:40 AM, said:
Thanks!
I have no idea what you are asking. It's your job to integrate this with your textboxes.
#7
Re: Input text display output text
Posted 04 May 2011 - 12:12 PM
If textbox1.text = "2354" then textbox1.text = "ALABAMA"
(ON A BUTTON ACTION)
#8
Re: Input text display output text
Posted 05 May 2011 - 10:52 AM
Jordi C, on 04 May 2011 - 01:12 PM, said:
If textbox1.text = "2354" then textbox1.text = "ALABAMA"
(ON A BUTTON ACTION)
It would be more like what modi123_1 posted in #4 with the If statement comparing a textbox value against the data in the Dictionary object instead. Your example hard codes the value into the logic. As modi123_1 also stated, how you wire that up is the programmer's call.
#9
Re: Input text display output text
Posted 05 May 2011 - 11:23 AM
modi123_1, on 04 May 2011 - 09:20 AM, said:
Dim sr As New StreamReader("<path>") '-- tell it your path.
Dim line As String = String.Empty '-- holds the each line you get in.
Dim arrayOfStrings() As String '-- using the split method of the string on the comma, it returns two strings.. before and after the comma
Dim myDictionary As New Dictionary(Of Int32, String) '-- same as above.
While line IsNot Nothing '-- loop through all the file's rows
line = sr.ReadLine '-- get the next line
arrayOfStrings = line.Split(",") '-- doing the split to get the two strings around the comma
myDictionary.Add(arrayOfStrings(0), arrayOfStrings(1)) '-- adding them to the dictionary.
End While
Where would this code go and how do I reference this to a TextBox or am I reading over that in this code?
#10
Re: Input text display output text
Posted 05 May 2011 - 11:27 AM
#11
Re: Input text display output text
Posted 05 May 2011 - 02:57 PM
|
|

New Topic/Question
Reply



MultiQuote






|