10 Replies - 3166 Views - Last Post: 22 November 2010 - 07:24 PM Rate Topic: -----

#1 Viper2KX  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 195
  • Joined: 25-January 09

TextBox2.Text Error with If/ElseIf/Else statements

Posted 19 August 2009 - 11:32 AM

Many of you are aware I am making a AiO Character Creator for all tabletop RPG games.

My code is:
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
		Dim totalXP As Double

		totalXP = TextBox2.Text

		If (totalXP >= 0) And (totalXP <= 999) Then
			TextBox1.Text = 1
		ElseIf (totalXP >= 1000) And (totalXP <= 2249) Then
			TextBox1.Text = 2
		ElseIf (totalXP >= 2250) And (totalXP <= 3749) Then
			TextBox1.Text = 3
		ElseIf (totalXP >= 3750) And (totalXP <= 5499) Then
			TextBox1.Text = 4
		ElseIf (totalXP >= 5500) And (totalXP <= 7499) Then
			TextBox1.Text = 5
		ElseIf (totalXP >= 7500) And (totalXP <= 9999) Then
			TextBox1.Text = 6
		ElseIf (totalXP >= 10000) And (totalXP <= 12999) Then
			TextBox1.Text = 7
		ElseIf (totalXP >= 13000) And (totalXP <= 16499) Then
			TextBox1.Text = 8
		ElseIf (totalXP >= 16500) And (totalXP <= 20499) Then
			TextBox1.Text = 9
		ElseIf (totalXP >= 20500) And (totalXP <= 25999) Then
			TextBox1.Text = 10
		ElseIf (totalXP >= 26000) And (totalXP <= 31999) Then
			TextBox1.Text = 11
		ElseIf (totalXP >= 32000) And (totalXP <= 38999) Then
			TextBox1.Text = 12
		ElseIf (totalXP >= 39000) And (totalXP <= 46999) Then
			TextBox1.Text = 13
		ElseIf (totalXP >= 47000) And (totalXP <= 56999) Then
			TextBox1.Text = 14
		ElseIf (totalXP >= 57000) And (totalXP <= 68999) Then
			TextBox1.Text = 15
		ElseIf (totalXP >= 69000) And (totalXP <= 82999) Then
			TextBox1.Text = 16
		ElseIf (totalXP >= 83000) And (totalXP <= 98999) Then
			TextBox1.Text = 17
		ElseIf (totalXP >= 99000) And (totalXP <= 118999) Then
			TextBox1.Text = 18
		ElseIf (totalXP >= 119000) And (totalXP <= 142999) Then
			TextBox1.Text = 19
		ElseIf (totalXP >= 143000) And (totalXP <= 174999) Then
			TextBox1.Text = 20
		ElseIf (totalXP >= 175000) And (totalXP <= 209999) Then
			TextBox1.Text = 21
		ElseIf (totalXP >= 210000) And (totalXP <= 254999) Then
			TextBox1.Text = 22
		ElseIf (totalXP >= 255000) And (totalXP <= 309999) Then
			TextBox1.Text = 23
		ElseIf (totalXP >= 310000) And (totalXP <= 374999) Then
			TextBox1.Text = 24
		ElseIf (totalXP >= 375000) And (totalXP <= 449999) Then
			TextBox1.Text = 25
		ElseIf (totalXP >= 450000) And (totalXP <= 549999) Then
			TextBox1.Text = 26
		ElseIf (totalXP >= 550000) And (totalXP <= 674999) Then
			TextBox1.Text = 27
		ElseIf (totalXP >= 675000) And (totalXP <= 824999) Then
			TextBox1.Text = 28
		ElseIf (totalXP >= 825000) And (totalXP <= 999999) Then
			TextBox1.Text = 29
		ElseIf (totalXP = 1000000) Then
			TextBox1.Text = 30
		Else
			TextBox1.Hide()
			Label8.Text = "No such level."
		End If
	End Sub



This is currently on Dungeons and Dragons 4th edition because they're 30 levels and not the usual 20.

My error is: Conversion from string "" to type 'Double' is not valid.

With:
Dim totalXP As Integer


Error: Conversion from string "" to type 'Integer' is not valid.

Because I am running Windows 7 Ultimate RC 64-bit, would I have to put Int64?

Is This A Good Question/Topic? 0
  • +

Replies To: TextBox2.Text Error with If/ElseIf/Else statements

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: TextBox2.Text Error with If/ElseIf/Else statements

Posted 19 August 2009 - 11:43 AM

You need to convert the text (string) into a number first before you can use it a number.
Is suggest you add this to the start of the subroutine.
   Dim totalXP As Double
If Double.TryParse( TextBox2.Text,totalXP)=False Then
 Message.Show("You've entered something I don't recognize as a number")
 Exit Sub
End If


Was This Post Helpful? 0
  • +
  • -

#3 Viper2KX  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 195
  • Joined: 25-January 09

Re: TextBox2.Text Error with If/ElseIf/Else statements

Posted 19 August 2009 - 11:50 AM

View PostAdamSpeight2008, on 19 Aug, 2009 - 10:43 AM, said:

You need to convert the text (string) into a number first before you can use it a number.
Is suggest you add this to the start of the subroutine.
   Dim totalXP As Double
If Double.TryParse( TextBox2.Text,totalXP)=False Then
 Message.Show("You've entered something I don't recognize as a number")
 Exit Sub
End If



I have copied and pasted your if statement, but you had an error that I easily fixed 'Message.Show'. I changed it to 'MsgBox' and it works. Thank you Adam, this is now solved.

This post has been edited by Viper2KX: 19 August 2009 - 11:51 AM

Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: TextBox2.Text Error with If/ElseIf/Else statements

Posted 19 August 2009 - 11:52 AM

MessageBox.Show is the method to use.
Was This Post Helpful? 0
  • +
  • -

#5 Viper2KX  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 195
  • Joined: 25-January 09

Re: TextBox2.Text Error with If/ElseIf/Else statements

Posted 19 August 2009 - 11:54 AM

Sweet, this section works to perfection now. Thank you so much.
Was This Post Helpful? 0
  • +
  • -

#6 Viper2KX  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 195
  • Joined: 25-January 09

Re: TextBox2.Text Error with If/ElseIf/Else statements

Posted 24 August 2009 - 07:49 AM

I have found a flaw with this. If a user inputs a number higher then 1,000,000 (without commas), I have the label that says "Current level:" switch to "No such level exist", then TextBox1 hides. But I am trying to make it so the user can delete until the number is less than or equal to 1,000,000.

And I have tried the For loop ad the Do While loop, any pointers? I am thinking of putting this in the Else statement if possible.

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
		Dim totalXP As Double

		If Double.TryParse(TextBox2.Text, totalXP) = False Then
			MessageBox.Show("You've entered something I don't recognize as a number")
			Exit Sub
		End If

		totalXP = TextBox2.Text

		If (totalXP >= 0) And (totalXP <= 999) Then
			TextBox1.Text = 1
		ElseIf (totalXP >= 1000) And (totalXP <= 2249) Then
			TextBox1.Text = 2
		ElseIf (totalXP >= 2250) And (totalXP <= 3749) Then
			TextBox1.Text = 3
		ElseIf (totalXP >= 3750) And (totalXP <= 5499) Then
			TextBox1.Text = 4
		ElseIf (totalXP >= 5500) And (totalXP <= 7499) Then
			TextBox1.Text = 5
		ElseIf (totalXP >= 7500) And (totalXP <= 9999) Then
			TextBox1.Text = 6
		ElseIf (totalXP >= 10000) And (totalXP <= 12999) Then
			TextBox1.Text = 7
		ElseIf (totalXP >= 13000) And (totalXP <= 16499) Then
			TextBox1.Text = 8
		ElseIf (totalXP >= 16500) And (totalXP <= 20499) Then
			TextBox1.Text = 9
		ElseIf (totalXP >= 20500) And (totalXP <= 25999) Then
			TextBox1.Text = 10
		ElseIf (totalXP >= 26000) And (totalXP <= 31999) Then
			TextBox1.Text = 11
		ElseIf (totalXP >= 32000) And (totalXP <= 38999) Then
			TextBox1.Text = 12
		ElseIf (totalXP >= 39000) And (totalXP <= 46999) Then
			TextBox1.Text = 13
		ElseIf (totalXP >= 47000) And (totalXP <= 56999) Then
			TextBox1.Text = 14
		ElseIf (totalXP >= 57000) And (totalXP <= 68999) Then
			TextBox1.Text = 15
		ElseIf (totalXP >= 69000) And (totalXP <= 82999) Then
			TextBox1.Text = 16
		ElseIf (totalXP >= 83000) And (totalXP <= 98999) Then
			TextBox1.Text = 17
		ElseIf (totalXP >= 99000) And (totalXP <= 118999) Then
			TextBox1.Text = 18
		ElseIf (totalXP >= 119000) And (totalXP <= 142999) Then
			TextBox1.Text = 19
		ElseIf (totalXP >= 143000) And (totalXP <= 174999) Then
			TextBox1.Text = 20
		ElseIf (totalXP >= 175000) And (totalXP <= 209999) Then
			TextBox1.Text = 21
		ElseIf (totalXP >= 210000) And (totalXP <= 254999) Then
			TextBox1.Text = 22
		ElseIf (totalXP >= 255000) And (totalXP <= 309999) Then
			TextBox1.Text = 23
		ElseIf (totalXP >= 310000) And (totalXP <= 374999) Then
			TextBox1.Text = 24
		ElseIf (totalXP >= 375000) And (totalXP <= 449999) Then
			TextBox1.Text = 25
		ElseIf (totalXP >= 450000) And (totalXP <= 549999) Then
			TextBox1.Text = 26
		ElseIf (totalXP >= 550000) And (totalXP <= 674999) Then
			TextBox1.Text = 27
		ElseIf (totalXP >= 675000) And (totalXP <= 824999) Then
			TextBox1.Text = 28
		ElseIf (totalXP >= 825000) And (totalXP <= 999999) Then
			TextBox1.Text = 29
		ElseIf (totalXP = 1000000) Then
			TextBox1.Text = 30
		ElseIf (totalXP >= 1000001) Then
			TextBox1.Hide()
			Label8.Text = "No such level exists."
		Else
			'
		End If
	End Sub


Was This Post Helpful? 0
  • +
  • -

#7 motcom  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: TextBox2.Text Error with If/ElseIf/Else statements

Posted 24 August 2009 - 08:12 AM

Would it not then mean that the user can't get any more points?

Diablo 3 or Titan Quest stay at the max level once reached.

This is just a suggestion..... :P

ElseIf (totalXP = 1000000) Then
			TextBox1.Text = 30
		Else
			TextBox1.Hide()
			Label8.Text = "No such level."
		End If




becomes

ElseIf (totalXP >= 1000000) Then
			TextBox1.Text = 30
		endif


Was This Post Helpful? 1
  • +
  • -

#8 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

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

Re: TextBox2.Text Error with If/ElseIf/Else statements

Posted 24 August 2009 - 09:33 AM

This can be coded much more simply and flexibly as:
Dim Levels() As Integer = {
0, 1000, 2250, 3750, 5500, 7500,
10000, 13000, 16500, 20500, 26000,
32000, 39000, 47000, 57000, 69000,
83000, 99000, 119000, 143000, 175000,
210000, 255000, 310000, 375000, 450000,
550000, 675000, 825000, 1000000}
	   Dim x As Integer = 0
	   If totalXP >= Levels.(Levels.Length - 1) then
		   x = Levels.Length
	   Else
		   While totalXP < Levels(x) Do
			   x = x + 1
		   End While
	   End If
	   TextBox1.Text = x


This code will clip anybody entering more than 1000000 to level 30 - This is simpler than forcing them back - or you can just re-write their input to 1000000 if you find they input a bigger number.
Was This Post Helpful? 0
  • +
  • -

#9 Viper2KX  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 195
  • Joined: 25-January 09

Re: TextBox2.Text Error with If/ElseIf/Else statements

Posted 24 August 2009 - 09:53 AM

Yeah. I just want to re-write their input to 1,000,000 if they try and type a larger number.

This post has been edited by Viper2KX: 24 August 2009 - 09:59 AM

Was This Post Helpful? 0
  • +
  • -

#10 Viper2KX  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 195
  • Joined: 25-January 09

Re: TextBox2.Text Error with If/ElseIf/Else statements

Posted 24 August 2009 - 10:15 AM

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

#11 ahabich  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 18
  • Joined: 14-November 10

Re: TextBox2.Text Error with If/ElseIf/Else statements

Posted 22 November 2010 - 07:24 PM

@mark.bottomley

Your while loop does not execute.

The left side of the condition changes the right side stays fixed.
Do While Levels(x) <= totalXP

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1