odd problem with Numericupdown / Textbox

tehshort

New member
Joined
Jul 20, 2005
Messages
4
Programming Experience
1-3
Im creating this program and ive run into a very odd error...

Consider this...

this is what i got on my program

2 x NumericUpdown

1 x Textbox

this is the code for numericupdown1

VB.NET:
 Private Sub NUHCK_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NUHCK.ValueChanged 
		Dim newhck As Integer 
		newhck = NUHCK.Value 
 
		Dim show As Short 
		show = POINTSINT.Text 
 
		'check if user clicked the up button then do this. 
		If newhck > HCK Then 
			'substrating from totalpoints 
			If newhck >= 0 And newhck < 50 Then 
				show = show - 1 
				POINTSINT.Text = show 
			ElseIf newhck >= 50 And newhck < 75 Then 
				show = show - 2 
				POINTSINT.Text = show 
			ElseIf newhck >= 75 And newhck < 100 Then 
				show = show - 3 
				POINTSINT.Text = show 
			ElseIf newhck >= 100 Then 
				show = show - 5 
				POINTSINT.Text = show 
				'Når man trykker value ned 
			End If 
		ElseIf newhck < HCK Then 
			If newhck >= 0 And newhck < 50 Then 
				show = show + 1 
				POINTSINT.Text = show 
			ElseIf newhck >= 50 And newhck < 75 Then 
				show = show + 2 
				POINTSINT.Text = show 
			ElseIf newhck >= 75 And newhck < 100 Then 
				show = show + 3 
				POINTSINT.Text = show 
			ElseIf newhck >= 100 Then 
				show = show + 5 
				POINTSINT.Text = show
			End If 
		End If 
		HCK = newhck 
	End Sub

This code works fine and without any problems..

now for the next Numericupdown (2)
i want to make it add +5 to Textbox value each time i press UP and take -5 each time i press DOWN.
This is the code i got in Numericupdown2
VB.NET:
 [size=2]
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] newint [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Integer[/color][/size]
[size=2]newint = NUINT.Value[/size]
[size=2][color=#0000ff]Dim[/color][/size][size=2] show [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Short
[/color][/size][size=2]show = POINTSINT.Text
[/size][size=2][color=#0000ff]if[/color][/size][size=2] newint > INT [/size][size=2][color=#0000ff]Then[/color][/size]
[size=2]show = show + 5
POINTSINT.Text = show
[/size][size=2][color=#0000ff]ElseIf[/color][/size][size=2] newint < INT [/size][size=2][color=#0000ff]Then[/color][/size][size=2][color=#0000ff]
[/color][/size][size=2]show = show - 5
POINTSINT.Text = show
[/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]If
[/color][/size]

INT and HCK is created in the start of my program like this

VB.NET:
 [size=2]
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] INT [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Integer[/color][/size]
[color=#0000ff]D[size=2]im[/size][/color][size=2] HCK [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]Integer
[/color][/size]

and in FORMLOAD i added this

VB.NET:
 [size=2]
INT = NUINT.Value
HCK = NUHCK.Value
[/size]

But each time i try to launch my program it gives me an error in this line ..
VB.NET:
 show = POINTSINT.Text
something about it cannot convert from ""
but the funny thing is, that there is no probs in the other numericupdown control.. and they got the exact same kind of property's

Please help me anyone =)
 
POINTSINT is a textbox so i cannot use the value there...

Well from the start i already added atleast 0 to my textbox.. this shows from the fact that the other numericupdown works on it.. Just not the new one im adding... wich i find kinda odd..
 
Convert to integer

Convert.ToInt16 is the Short Variable type
Convert.ToInt32 is the Integer Variable type
Convert.ToInt64 is the Long Variable type

Dim ShrtMyNumber as Short = Convert.ToInt16(Textbox.Text)

You may want to use
Try

Catch ex As Exception

End Try

or an If statement to see if Textbox.Text is null.
 
So i can change the Textbox property (that it takes strings) to a integer or short ?..
hmm i did not know that... that could possibly solve my problem..
ill test and get back with the results
 
Back
Top