Application help

cor_dog2

Member
Joined
Feb 15, 2005
Messages
7
Programming Experience
Beginner
I'm try to do a simple program for class and I am having troubles. The program in a pinch is suppose to prompt you for a city, and state. Then when you click display it should display only the city in a message box. For instance if i type "Tampa, Florida" in the text box it should return "Tampa" in a message box. Does anyone know how to do this? I was under the impression I needed to use the trimend method, but do not know if that is the correct way. My current code looks along the lines of the following:

Private Sub btnDisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDisplay.Click

'displays the city name

'declare variables

Dim strAddress As String

Dim strCity As String

'assign input to a variable

strAddress = Me.txtAddress.Text

'display the city name

strCity = Me.txtAddress.Text.TrimEnd()

MessageBox.Show(strCity, "City Name", MessageBoxButtons.OK, _

MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)

End Sub





Any advice/code would be appreciated. Thanks, Correy.
 

Schenz

Well-known member
Joined
Sep 11, 2004
Messages
181
Location
Cincinnati, OH
Programming Experience
5-10
You need to seperate the string in the textbox. I assume that the rule is that it will always be in the format of "city, state" so try the following:
VB.NET:
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click

		'displays the city name

		'declare variables

		Dim strAddress As String
		Dim strCity As String
		Dim commalocation As Integer

		'assign input to a variable
		strAddress = Me.txtAddress.Text

		'display the city name
		commalocation = Me.txtAddress.Text.IndexOf(",")
		strCity = Me.txtAddress.Text.Substring(0, commalocation)

		MessageBox.Show(strCity, "City Name", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
	End Sub
 

cor_dog2

Member
Joined
Feb 15, 2005
Messages
7
Programming Experience
Beginner
Thank You

Wow....seems so easy now. I was messing around with this on and off for 2 or 3 days. Thank you so much. I'm a beginner as you can probably tell. I appreciate the help very much.
 
Top Bottom