VB -> If label.text=multiple #'s..then

  • Thread starter Thread starter Hareth
  • Start date Start date
H

Hareth

I Tried:
If label1.Text < 80 Then

lblOutput.Text = "Word I wanna say"



It didnt work...

Do I have to import something? declare something? missing something?

It didnt generate any errors, just doesnt do anything.

label1.text always is a number.....



VS2003 VB.net
 
Hi
If label1.Text < 80 Then

lblOutput.Text = "Word I wanna say"

This would output your text into lblOutput

Dim lblValue as Integer = label1.Text
If lblValue < 80 then
lblOutput.Text = "Word I wanna say"
End If

or did you mean the length of label1.text?

If lable1.Text.Length < 80 then
lblOutput.Text = "Word I wanna say"
End If
 
The text property is a string type, even when it looks like a number. You
need to convert it into an actual number, then compare.

Dim n as int32 = clng(label1.text)
if n < 80 then
....
OR
Dim n as double = cdbl(label1.text)
....
 
Hareth,

Although your code is not nice it should work.

Nicer can be
Label1.Text = "1"
If CInt(label1.Text) < 80 Then
lblOutput.Text = "Word I wanna say"
End if

I hope this helps?

Cor
 
Hareth said:
I Tried:
If label1.Text < 80 Then

lblOutput.Text = "Word I wanna say"

I suggest to set 'Option Strict On' (add this line on top of your source
file).

Then use something like this:

\\\
If CInt(Label1.Text) < 80 Then
...
End If
///

If you want to check the length of the text entered into the textbox:

\\\
If Label1.Text.Length < 80 Then
...
End If
///
 
Thanx for everyones help......

I know that everyones method is correct..

It turns out that I put it ..in the wrong area...sigh*


My mistake....



Cor Ligthert.....You said my way isnt nice. Why?

It does seem amatuer how i wrote the code, but it works.

are you suggesting that b/c more errors are likely to happen? or something
else??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top