Results 1 to 40 of 45

Thread: [RESOLVED]implicit conversion from integer to string

Hybrid View

  1. #1
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: implicit conversion from integer to string

    Quote Originally Posted by GBeats View Post
    should be

    Function GetSettingInt(ByVal name As String) As string
    Check()
    If FileIO.FileSystem.FileExists(subdirName & "s." & name & ".n") = True Then
    Return File.ReadAllText(subdirName & "s." & name & ".n")
    Else
    Return Nothing
    End If
    End Function
    If the return value was a string, then GetSettingInt wouldn't make sense would it? And this was part of the discussion if you look through the thread.

    The setting is intended to be an Integer from the very beginning, so why should it be a string? You're going to be using it perhaps more as an Integer than a String, so for this one place where you would use it as a string, why would you make the function fit this type? Then all the other places where you use it as an Integer, you have to manually cast it each time, instead of returning that value directly from the function.

    And no... He was asking what the implicit conversion bit meant on that line, not what the code itself does.

    Being new to programming, can someone explain to me in the most basic format what exactly this means, what does implicit conversion mean and implicit conversion from integer to string mean, what is it trying to tell me here?
    When he said "can someone explain to me in the most basic format what exactly this means," he was referencing the implicit conversion notice.

    My suggestion was Integer.TryParse(), so if you didn't have the return value as an Integer, then imagine implementing TryParse() everywhere you use this string, just to have a usable integer representation of the text in the file? Rethinking this over, it makes much more sense to stay an Integer.

    ~Ace
    Last edited by AceInfinity; May 19th, 2013 at 12:36 AM.
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - 2018)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

  2. #2

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    Re: implicit conversion from integer to string

    Ahhhh lightbulb to head

    The textbox with the error is a text box that requires the user to enter a number

    Which I believe is the Integer.

    What is the meaning of implicit conversion, I dont get.

    So it wants to change from a number to a letter is that what this error is referring too?

  3. #3

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    Re: implicit conversion from integer to string

    AceInfinity I was referring too

    String "The Quick Brown Fox..."
    Integer 8 etc..

  4. #4

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    Re: implicit conversion from integer to string

    When I change to .ToString() it says:

    Expression does not produce a value

    Hence why I didnt change anything further

    Should I turn on Option Strict On and if so how?

  5. #5
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: implicit conversion from integer to string

    Quote Originally Posted by jokerfool View Post
    When I change to .ToString() it says:

    Expression does not produce a value

    Hence why I didnt change anything further
    Did you do:
    Code:
    TextBox14.Text = GetSettingInt("TMaxUPSpeed").ToString()
    ???

    And to imagine this implicit conversion stuff. Lets say that the GetSettingInt() function returns a value of 9 in this case.

    If you write this in your code:
    Code:
    TextBox14.Text = 9
    You will get the same warning. But the implicit conversion takes that 9 and makes it "9" (a string). This would fix that warning:
    Code:
    TextBox14.Text = "9"
    Or in this case 9 is a placeholder for our function (we can't just put quotes around the function, otherwise it makes the function name our string, and not its return value), so the ToString() function is used:
    Code:
    TextBox14.Text = (9).ToString()
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - 2018)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

Posting Permissions

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



Click Here to Expand Forum to Full Width