|
-
May 19th, 2013, 12:31 AM
#1
Re: implicit conversion from integer to string
 Originally Posted by GBeats
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.
<<<------------
.NET Programming (2012 - 2018)
®Crestron - DMC-T Certified Programmer | Software Developer <<<------------
-
May 19th, 2013, 12:44 AM
#2
Thread Starter
Hyperactive Member
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?
-
May 19th, 2013, 12:45 AM
#3
Thread Starter
Hyperactive Member
Re: implicit conversion from integer to string
AceInfinity I was referring too
String "The Quick Brown Fox..."
Integer 8 etc..
-
May 19th, 2013, 12:48 AM
#4
Thread Starter
Hyperactive Member
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?
-
May 19th, 2013, 12:51 AM
#5
Re: implicit conversion from integer to string
 Originally Posted by jokerfool
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:
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()
<<<------------
.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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|