textbox evaluation

get each letter one at a time and do something for each

Page 1 of 1

5 Replies - 1187 Views - Last Post: 07 May 2009 - 02:48 PM Rate Topic: -----

#1 BTW  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-April 09

textbox evaluation

Posted 06 May 2009 - 07:33 AM

I have a textbox that I need to evaluate its content one letter at a time.

private void cmdIdentify_Click(object sender, EventArgs e)
		{
		  
			txtboxCallSign.Text.ToUpper();

			for (int i = 0; i < txtboxCallSign.Text.Length; i++)
			{
			  
				GenTone(textBox1.Text[i].ToString());
				//progressbar update with % of chars sent until last char... 
				
			}

		}
		public void GenTone(string sCharIn)
		{
			// Pass the character in as string and use case command to generate dots and dash tones.

			switch (sCharIn)
			{
				case "A":
					 dit();
					 dah();
					 break;
				case "B":
					dah();
					dit();
					dit();
					dit();
					break;

//and so on all the way to Z then 0-9




I'm getting an indexOutofRange Exception when text is in the textbox.
The error is in GenTone(textBox1.Text[i].ToString());

dit() and dah() subs contain tone generation for starting and stopping a sound buffer.


Just as a side note I am not a student and this is in no way homework! I'm just a ham radio op who would like to complete a stations Identification program :)

This post has been edited by BTW: 06 May 2009 - 07:39 AM


Is This A Good Question/Topic? 0
  • +

Replies To: textbox evaluation

#2 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: textbox evaluation

Posted 06 May 2009 - 08:30 AM

View PostBTW, on 6 May, 2009 - 06:33 AM, said:

I have a textbox that I need to evaluate its content one letter at a time.

private void cmdIdentify_Click(object sender, EventArgs e)
		{
		  
			txtboxCallSign.Text.ToUpper();

			for (int i = 0; i < txtboxCallSign.Text.Length; i++)
			{
			  
				GenTone(textBox1.Text[i].ToString());
				//progressbar update with % of chars sent until last char... 
				
			}

		}
		public void GenTone(string sCharIn)
		{
			// Pass the character in as string and use case command to generate dots and dash tones.

			switch (sCharIn)
			{
				case "A":
					 dit();
					 dah();
					 break;
				case "B":
					dah();
					dit();
					dit();
					dit();
					break;

//and so on all the way to Z then 0-9




I'm getting an indexOutofRange Exception when text is in the textbox.
The error is in GenTone(textBox1.Text[i].ToString());

dit() and dah() subs contain tone generation for starting and stopping a sound buffer.


Just as a side note I am not a student and this is in no way homework! I'm just a ham radio op who would like to complete a stations Identification program :)


I think I have a solution to your problem. Instead the for loop use a foreach loop like this:

foreach (char c in txtboxCallSign.Text)
{
    GenTone( c );
}



Then change GenTone to:

public void GenTone(char sCharIn)



Then put the values of "B" to 'B'. I think that will solve your problem.

*edit*
For some reason if you put ( c ) with out spaces in you get ©.

This post has been edited by SixOfEleven: 06 May 2009 - 08:32 AM

Was This Post Helpful? 1
  • +
  • -

#3 BTW  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-April 09

Re: textbox evaluation

Posted 06 May 2009 - 08:59 AM

This looks like exactly what I wanted to do. I don't know why I was trying to make it so complicated!

I posted this less than an hour ago! You Rock! :)

:^:



View PostSixOfEleven, on 6 May, 2009 - 07:30 AM, said:

View PostBTW, on 6 May, 2009 - 06:33 AM, said:

I have a textbox that I need to evaluate its content one letter at a time.

private void cmdIdentify_Click(object sender, EventArgs e)
		{
		  
			txtboxCallSign.Text.ToUpper();

			for (int i = 0; i < txtboxCallSign.Text.Length; i++)
			{
			  
				GenTone(textBox1.Text[i].ToString());
				//progressbar update with % of chars sent until last char... 
				
			}

		}
		public void GenTone(string sCharIn)
		{
			// Pass the character in as string and use case command to generate dots and dash tones.

			switch (sCharIn)
			{
				case "A":
					 dit();
					 dah();
					 break;
				case "B":
					dah();
					dit();
					dit();
					dit();
					break;

//and so on all the way to Z then 0-9




I'm getting an indexOutofRange Exception when text is in the textbox.
The error is in GenTone(textBox1.Text[i].ToString());

dit() and dah() subs contain tone generation for starting and stopping a sound buffer.


Just as a side note I am not a student and this is in no way homework! I'm just a ham radio op who would like to complete a stations Identification program :)


I think I have a solution to your problem. Instead the for loop use a foreach loop like this:

foreach (char c in txtboxCallSign.Text)
{
    GenTone( c );
}



Then change GenTone to:

public void GenTone(char sCharIn)



Then put the values of "B" to 'B'. I think that will solve your problem.

*edit*
For some reason if you put ( c ) with out spaces in you get .

Was This Post Helpful? 0
  • +
  • -

#4 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: textbox evaluation

Posted 06 May 2009 - 09:00 AM

I'm happy to help. Have a great day!
Was This Post Helpful? 0
  • +
  • -

#5 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: textbox evaluation

Posted 06 May 2009 - 09:37 AM

just so you know what your problem actually was...

for (int i = 0; i < [size=4][b]txtboxCallSign[/b][/size].Text.Length; i++)
{
              
       GenTone([size=4][b]textBox1[/b][/size].Text[i].ToString());
         //progressbar update with % of chars sent until last char... 
                
}



notice the issue? You are looping depending on the length of "txtboxCallSign", but you are trying to access the text of "textBox1".
Was This Post Helpful? 0
  • +
  • -

#6 LycHaf17  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 02-May 09

Re: textbox evaluation

Posted 07 May 2009 - 02:48 PM

View Posteclipsed4utoo, on 6 May, 2009 - 08:37 AM, said:

just so you know what your problem actually was...

for (int i = 0; i < [size=4][b]txtboxCallSign[/b][/size].Text.Length; i++)
{
              
       GenTone([size=4][b]textBox1[/b][/size].Text[i].ToString());
         //progressbar update with % of chars sent until last char... 
                
}



notice the issue? You are looping depending on the length of "txtboxCallSign", but you are trying to access the text of "textBox1".



I was just about to write that. I was little confused at first everything looked right, then I saw his for loop was looping for a different value.

Nice catch.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1