4 Replies - 991 Views - Last Post: 29 November 2009 - 08:23 PM Rate Topic: -----

#1 TimBDesigns  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 25-April 09

Select Case Problem

Post icon  Posted 29 November 2009 - 02:18 PM

I'm unable to get the color to display in the colorLabel. I think the problem is in my selector expression. I tried "B", "##[B]##", "##B##"
Please help.
Option Explicit On
Option Strict On
Option Infer Off

Public Class MainForm

	Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
		Me.Close()
	End Sub

	Private Sub itemTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles itemTextBox.Enter
		itemTextBox.SelectAll()
	End Sub

	Private Sub itemTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles itemTextBox.TextChanged
		colorLabel.Text = String.Empty
	End Sub

	Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

	End Sub

	Private Sub displayButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles displayButton.Click
		Dim characters As String

		Dim isCharactersValid As Boolean



		characters = itemTextBox.Text.ToUpper
	   
		If characters.Length = 5 Then

			If characters Like "##[BGRW]##" Then
				isCharactersValid = True

				If isCharactersValid = True Then


					Select Case characters
						Case "B"
							colorLabel.Text = "Blue"
						Case "G"
							colorLabel.Text = "Green"
						Case "R"
							colorLabel.Text = "Red"
						Case "W"
							colorLabel.Text = "White"
					End Select
				End If
			Else
				MessageBox.Show("Third character must contain a (b,g,r or w).", _
							  "Error", MessageBoxButtons.OK, _
							  MessageBoxIcon.Information)

			End If
		Else
			MessageBox.Show("Please enter the proper 5 character format.", _
							  "Error", MessageBoxButtons.OK, _
							  MessageBoxIcon.Information)

		End If



	   



	End Sub
End Class


Is This A Good Question/Topic? 0
  • +

Replies To: Select Case Problem

#2 Matty919  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 83
  • Joined: 10-May 09

Re: Select Case Problem

Posted 29 November 2009 - 04:37 PM

What exactly do you want the input and output to be? For b input you want the colour label to change to the text blue?
Was This Post Helpful? 0
  • +
  • -

#3 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Select Case Problem

Posted 29 November 2009 - 07:12 PM

The problem is your select statement is trying to find a "B", "G", "R", "W" when you are giving it "23R45" ( or some other numbers) - you need to extract the middle character BEFORE the select statement -
Dim colorChar As String = characters.SubString(2,1)
Select Case colorChar
...


Was This Post Helpful? 1
  • +
  • -

#4 TimBDesigns  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 25-April 09

Re: Select Case Problem

Posted 29 November 2009 - 08:08 PM

View Postmark.bottomley, on 29 Nov, 2009 - 06:12 PM, said:

The problem is your select statement is trying to find a "B", "G", "R", "W" when you are giving it "23R45" ( or some other numbers) - you need to extract the middle character BEFORE the select statement -
Dim colorChar As String = characters.SubString(2,1)
Select Case colorChar
...


Rookie Question.
So if you enter 75B93 the B would be 2 because 7 is 0 and 5 is 1 in the substring index what is the ,1 for?

This post has been edited by TimBDesigns: 29 November 2009 - 08:10 PM

Was This Post Helpful? 0
  • +
  • -

#5 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Select Case Problem

Posted 29 November 2009 - 08:23 PM

reading the help files is useful - the 2 is the zero-based index of the start character and the 1 is the length of the substring to extract.

This post has been edited by mark.bottomley: 29 November 2009 - 08:23 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1