Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

hi guys..

i wanna do a coding whereby whenever a number is removed from label1(label1 has codings to generate numbers),label4 will indicate a +1 point(for ex. if 5 numbers is removed from label1,label4 will show 5)

 

(i already did a coding to remove the numbers..)

 

 

and also this error message on sr = CStr(Label1.Text) is shown

 

An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll

 

Additional information: Cast from string "" to type 'Integer' is not valid.

Edited by kogan31
Posted

err..

sorry i'm a newbie and i dun quite understand u

CStr is a code use to convert string... am i wrong?

if so wats the code i should write?

could u show them to me?

 

thanks alot

Posted
CStr converts it to a string, yes, but you want to convert it to an integer. So you should be using CInt (because sr is an integer)
Gamer extraordinaire. Programmer wannabe.
Posted (edited)

errmm..

ok..

but there is still an error

 

An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll

 

Additional information: Cast from string "" to type 'Integer' is not valid.

 

i think there is something wrong somewhere in my coding

Dim sa As String = Label1.Text
       Dim sr As Integer
       sr = CInt(Label1.Text)
       If sa.Length = sr - 1 Then
           Label4.Text = sr + 1
       End If

any idea wats wrong?

please advice

 

thank you so much

Edited by PlausiblyDamp
Posted
Well, you seem a little new to try and explain what Try/Catch error handling is (at least for me to explain it, as I suck at explaining things). But the error is because you don't have an integer value in your Label. Make sure it's an integer value, and you won't get that error. Or you can look up how to use Try/Catch (are you learning from a book or just winging it?)
Gamer extraordinaire. Programmer wannabe.
Posted

yeah

i'm new to vb..

yeah there is an integer value in the label but its only when i activate the generating of the numbers den the numbers(integers) starts..

so is the error from there?

Posted

hmm...

 

still cant work for me..

ok..

can anyone do me a favor?

could u write a rough coding so that if i remove a number from label1 a point will be added in label4..

 

thanks alot

Posted

nope label1 is not displaying anything at all until i start the timer and numbers will be generating out randomly..

as a newbie..

i do not know how to use the try/catch..

hehe

hope u guys can help me out?

gonna hand in this project in like 3 hours time..

lol

  • Leaders
Posted
Try
   If Not Label1.Text = Nothing Then '/// incase it's empty
       Dim sr As Integer = Integer.Parse(Label1.Text)
       '/// do your code stuff here.
   End If
Catch Ex As Exception
   MessageBox.Show(Ex.Message)
End Try

Posted
I tried your code in a simple program and it worked ok, the only way I got an error was when lable1.text was not a whole number (Input string was not in correct format) What does label1.text show when you get the error
  • Leaders
Posted

have you tried asigning a value to _LastValue to start with? ie:

Private _LastValue As Int32 = 0

also instead of having "10" and "0" in the load event, have you tried removing the ""? , ie:

Label1.Text = 10
Label4.Text = 0

Posted

Where have you got the code to start the random generation of numbers?

 

If i call a sub that changes label1.text in sub main I get an error, only get the error you have if i have a very large number in label1.text

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...