10 Replies - 1819 Views - Last Post: 05 May 2011 - 02:57 PM Rate Topic: -----

#1 klturi421  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-May 11

Input text display output text

Posted 04 May 2011 - 07:04 AM

First off I am no programmer, I am doing this as a personal project to help me at my current job. I have the basic coding down and now for the final step I want to figure out how to do the following problem. Any assistance would go a long way!

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.

Is This A Good Question/Topic? 0
  • +

Replies To: Input text display output text

#2 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: Input text display output text

Posted 04 May 2011 - 08:18 AM

Put all the data in a file(text file, xml, xls, your choice) and read the values in a Dictionary<int, string>
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.
Was This Post Helpful? 0
  • +
  • -

#3 klturi421  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-May 11

Re: Input text display output text

Posted 04 May 2011 - 08:54 AM

View PostIonut, on 04 May 2011 - 08:18 AM, said:

Put all the data in a file(text file, xml, xls, your choice) and read the values in a Dictionary<int, string>
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.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9487
  • View blog
  • Posts: 35,774
  • Joined: 12-June 08

Re: Input text display output text

Posted 04 May 2011 - 09:20 AM

The MSDN example is pretty through. A dictionary is a key and value holder, right? Say your key is an integer... and your value is a string. You would declare it like this, add pairs to it, and return the value if you have the key.
        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,B), break it into two strings (because you are using your comma to separate the entries), and add them a dicionary object, and use that object later.

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.
Was This Post Helpful? 0
  • +
  • -

#5 klturi421  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-May 11

Re: Input text display output text

Posted 04 May 2011 - 09:40 AM

With those examples does it pull from a specific text box ie textbox1 or does it need to be declared? What you have provided looks exactly like what I need, I just want to make sure it pulls from the appropriate text box as my form has multiple text boxes.

Thanks!
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9487
  • View blog
  • Posts: 35,774
  • Joined: 12-June 08

Re: Input text display output text

Posted 04 May 2011 - 09:45 AM

View Postklturi421, on 04 May 2011 - 11:40 AM, said:

With those examples does it pull from a specific text box ie textbox1 or does it need to be declared? What you have provided looks exactly like what I need, I just want to make sure it pulls from the appropriate text box as my form has multiple text boxes.

Thanks!


I have no idea what you are asking. It's your job to integrate this with your textboxes.
Was This Post Helpful? 0
  • +
  • -

#7 Jordi C  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 11-January 11

Re: Input text display output text

Posted 04 May 2011 - 12:12 PM

Won't this be like:
If textbox1.text = "2354" then
textbox1.text = "ALABAMA"


(ON A BUTTON ACTION)
Was This Post Helpful? 0
  • +
  • -

#8 souptoy  Icon User is offline

  • D.I.C Head


Reputation: 54
  • View blog
  • Posts: 244
  • Joined: 17-January 08

Re: Input text display output text

Posted 05 May 2011 - 10:52 AM

View PostJordi C, on 04 May 2011 - 01:12 PM, said:

Won't this be like:
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.
Was This Post Helpful? 0
  • +
  • -

#9 klturi421  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-May 11

Re: Input text display output text

Posted 05 May 2011 - 11:23 AM

View Postmodi123_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?
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9487
  • View blog
  • Posts: 35,774
  • Joined: 12-June 08

Re: Input text display output text

Posted 05 May 2011 - 11:27 AM

No, I haven't seen your code to know how to integrate it, but beyond that it is your job to integrate the concepts you, hopefully, learned into your project! That's your end of the bargain!
Was This Post Helpful? 0
  • +
  • -

#11 Jordi C  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 11-January 11

Re: Input text display output text

Posted 05 May 2011 - 02:57 PM

haha, me and my stupid hardcoding all the time
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1