5 Replies - 618 Views - Last Post: 19 October 2008 - 02:22 PM Rate Topic: -----

#1 XiJiangWoo   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 06-April 08

I'm getting 0 as an output everytime

Post icon  Posted 19 October 2008 - 01:10 PM

Hello everyone. I'm trying to do an example for my VB class and I can't figure out why I am getting zero for an output everytime. I've done case selects before but I'm drawinga blank. Any thoughts?

Public Class Form1

	Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click

		'declare variables
		Dim strState As String

		'give variables value
		strState = Me.txtState.Text.ToUpper()


		Select Case strState

			Case "Hawaii"
				Me.lblCharge.Text = "$25.00"


			Case "Oregon"
				Me.lblCharge.Text = "$30.00"


			Case "California"
				Me.lblCharge.Text = "$32.50"

			Case Else
				Me.lblCharge.Text = "0"



		End Select




	End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: I'm getting 0 as an output everytime

#2 BetaWar   User is online

  • #include "soul.h"
  • member icon

Reputation: 1564
  • View blog
  • Posts: 8,354
  • Joined: 07-September 06

Re: I'm getting 0 as an output everytime

Posted 19 October 2008 - 01:23 PM

toUpper() makes the whole string uppercase in move langauges. So, if you had the input of "Texas" it would come out as "TEXAS". Try changing your cases to all caps. Like so:

Public Class Form1

	Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click

		'declare variables
		Dim strState As String

		'give variables value
		strState = Me.txtState.Text.ToUpper()


		Select Case strState

			Case "HAWAII"
				Me.lblCharge.Text = "$25.00"


			Case "OREGON"
				Me.lblCharge.Text = "$30.00"


			Case "CALIFORNIA"
				Me.lblCharge.Text = "$32.50"

			Case Else
				Me.lblCharge.Text = "0"



		End Select




	End Sub


I am not a VB guy so I won't be much help if that isn't the issue.

Hope that helps.
Was This Post Helpful? 0
  • +
  • -

#3 XiJiangWoo   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 06-April 08

Re: I'm getting 0 as an output everytime

Posted 19 October 2008 - 01:28 PM

Public Class Form1

	Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click

		'declare variables
		Dim strState As String

		'give variables value

		strState = Me.txtState.Text.ToUpper()
		strState = Me.txtState.Text

		Select Case strState

			Case "HAWAII"
				Me.lblCharge.Text = "$25.00"


			Case "OREGON"
				Me.lblCharge.Text = "$30.00"


			Case "CALIFORNIA"
				Me.lblCharge.Text = "$32.50"

			Case Else
				Me.lblCharge.Text = "0"



		End Select




	End Sub



Was This Post Helpful? 0
  • +
  • -

#4 Jayman   User is offline

  • Student of Life
  • member icon

Reputation: 423
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: I'm getting 0 as an output everytime

Posted 19 October 2008 - 02:20 PM

Remove the second line of code it is overwriting the conversion to all uppercase.

		strState = Me.txtState.Text.ToUpper()
		'''strState = Me.txtState.Text   <-- remove this line


Was This Post Helpful? 0
  • +
  • -

#5 Damage   User is offline

  • Lord of Schwing
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,989
  • Joined: 05-June 08

Re: I'm getting 0 as an output everytime

Posted 19 October 2008 - 02:21 PM

this is why

Quote

strState = Me.txtState.Text.ToUpper()
strState = Me.txtState.Text <------------------remove this line


you don't need the second line. text.toupper will take whatever is in the text box and assign it to the variable as upper case. it won't convert the actual textbox to uppercase

damn a minute late :P
Was This Post Helpful? 0
  • +
  • -

#6 Jayman   User is offline

  • Student of Life
  • member icon

Reputation: 423
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: I'm getting 0 as an output everytime

Posted 19 October 2008 - 02:22 PM

Topics merged. Please do not create duplicate topics.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1