Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Aug 2014
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    [Visual Basic 2013 Express] Trouble Converting string to int

    Hey, this is the first day I have ever done anything with Visual Basic and I have ran into an issue which I cant seem to fix.

    I have declared a couple of variables like so:
    Code:
    Dim intPlayerCount, intTypes As Integer
    I am also setting them to be used like so:
    Code:
    intPlayerCount = txtPlayerCount.Text
    Then I am doing some math with it later on:
    Code:
    intPlayerCount = intPlayerCount * 64 + intTypes * 7
    Then trying to set a label to show the answer, with something like this:
    Code:
    lblTotal.Text = "Your total is: " & intTotalScore
    It would appear that the data coming from the text boxes are strings and when I try to do the math with them (which may be wrong also (in terms of syntax)) the program doesnt like it and crashes out.

    Any advice here guys? do I NEED to convert the inputs?

  • #2
    New Coder
    Join Date
    Aug 2014
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Does anyone have any ideas for me?

  • #3
    New Coder
    Join Date
    Aug 2014
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I have worked this issue out and got my program fully working and published.

  • #4
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,930
    Thanks
    46
    Thanked 203 Times in 202 Posts
    Sorry only saw this today (try to leave code life on check when I can on weekends) You should have been getting an implicit conversion error. Text can't just go to int without converting. Convert is good to look at for this (also you could cast it by doing dim i as integer = (Cint)myString (syntax may be off)

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #5
    New Coder
    Join Date
    Aug 2014
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for replying anyway. I worked out what the issue was and it was because the text boxes were not defaulted to 0, thus when trying to convert (from the many input boxes) the "numbers" it would crash because some of the boxes were empty.

  • #6
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,930
    Thanks
    46
    Thanked 203 Times in 202 Posts
    right, still a conversion error. You can't cast a null value or string.Empty to an int.

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #7
    New Coder 4B/75/73/41/'s Avatar
    Join Date
    Nov 2008
    Posts
    56
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Not trying to be biased here, but I always thought the MS languages where pretty buggy. Glad you got the problem sorted out though.

  • #8
    New Coder
    Join Date
    Aug 2014
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by alykins View Post
    right, still a conversion error. You can't cast a null value or string.Empty to an int.
    Yes, it was an oversight, I got that


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •