|
-
May 17th, 2013, 11:04 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED]implicit conversion from integer to string
Reviewing some code that says
Code:
TextBox14.Text = GetSettingInt("TMaxUPSpeed")
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?
The code is some sample code I am using to be part of a larger app and the code is also from 2009 which shouldnt really make a difference.
Thank you
** Going to Resolve this post, seems to be an open ended debate on the question, I have already sorted the question out, I paid someone to fix the issue instead, I was a tad frustrated by some of the posts, but thanks to all that replied, moving onto other issues.
Last edited by jokerfool; May 24th, 2013 at 12:59 AM.
Reason: Too many people complaining
-
May 17th, 2013, 11:15 PM
#2
Re: implicit conversion from integer to string
 Originally Posted by jokerfool
Reviewing some code that says
Code:
TextBox14.Text = GetSettingInt("TMaxUPSpeed")
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?
The code is some sample code I am using to be part of a larger app and the code is also from 2009 which shouldnt really make a difference.
Thank you
We cant help with the above code as we do not know what GetSettingInt is. None the less its asking for an integer value. Your parsing a string value.
String "The Quick Brown Fox..."
Integer 8 etc..
-
May 17th, 2013, 11:48 PM
#3
Re: implicit conversion from integer to string
An implicit conversion occurs when you assign a value of one data type to a variable of a different, incompatible data type. For instance, this code implicitly converts a String to an Integer:
Code:
Dim int As Integer = "100"
The value "100" is a String and the 'int' variable can only hold and Integer, so the system has to implicitly convert the String to an Integer and then assign the result to the variable. This code performs an explicitly conversion:
Code:
Dim int As Integer = CInt("100")
CInt explicitly converts the String to an Integer and then assign the result to the variable. In that case the code tells the system exactly what to do rather than assuming that the system will work it out for itself.
In your case, presumably the GetSettingInt method returns an Integer while the Text property of a TextBox (in fact, of any control) is type String. You need to explicitly convert the Integer to a String before assigning it to a String property:
Code:
TextBox14.Text = GetSettingInt("TMaxUPSpeed").ToString()
-
May 18th, 2013, 12:05 AM
#4
Thread Starter
Hyperactive Member
Re: implicit conversion from integer to string
Looking for the GetSettingInt here is the function I think for that
Code:
Function GetSettingInt(ByVal name As String) As Integer
Check()
If FileIO.FileSystem.FileExists(subdirName & "s." & name & ".n") = True Then
Return CInt(File.ReadAllText(subdirName & "s." & name & ".n"))
Else
Return Nothing
End If
End Function
-
May 18th, 2013, 06:12 AM
#5
Re: implicit conversion from integer to string
 Originally Posted by jokerfool
Looking for the GetSettingInt here is the function I think for that
Code:
Function GetSettingInt(ByVal name As String) As Integer
Check()
If FileIO.FileSystem.FileExists(subdirName & "s." & name & ".n") = True Then
Return CInt(File.ReadAllText(subdirName & "s." & name & ".n"))
Else
Return Nothing
End If
End Function
ReadAllText returns a string value. Why are you casting this as an integer?
http://msdn.microsoft.com/en-us/library/ms143368.aspx
vb Code:
Public Class Form1 Function GetSettingInt(ByVal name As String) As String Dim path As String = String.Format("{0}s.{1}.n", subdirname, name) If IO.File.Exists(path) Then Return IO.File.ReadAllText(path) Else Return Nothing End If End Function End Class
-
May 18th, 2013, 07:47 AM
#6
Junior Member
Re: implicit conversion from integer to string
Which one is better and more preferred, implicit or explicit conversion.?
-
May 18th, 2013, 09:10 AM
#7
Re: implicit conversion from integer to string
Explicit conversions... that's why the general recomendation is to set Option Explicit On by default.
-tg
-
May 18th, 2013, 09:46 AM
#8
Re: implicit conversion from integer to string
 Originally Posted by techgnome
Explicit conversions... that's why the general recomendation is to set Option Explicit On by default.
-tg
You mean Option Strict. Option Explicit has nothing to do with type conversions. Option Explicit determines whether explicit declaration of variables is required while Option Strict determines whether strict typing is enforced. Strict typing means no late binding and no implicit conversions.
-
May 18th, 2013, 09:48 AM
#9
Re: implicit conversion from integer to string
 Originally Posted by ident
ReadAllText returns a string value. Why are you casting this as an integer?
Presumably because the file is a text file but it contains a setting value that represents a number. When you add an Integer to My.Settings it gets stored in the config file. The config file is XML, which is structured text. As such, the value has to be read as text and converted to an Integer at some point. This is no different.
-
May 18th, 2013, 03:29 PM
#10
Thread Starter
Hyperactive Member
Re: implicit conversion from integer to string
The code I am using is from 2008 to 2009 so the code back then may of served its purpose. The code shown is part of the settings, the main app itself works fine and I have no issues with loading etc, I just got a warning on the code for implicit conversion from integer to string. Here is the settings functions, this is where I am getting the warning.
Code:
Imports System.IO
''' <summary>
''' Because My.Setting namespace loose it's data after renaming the assembly file, or moving it, i made this.
''' </summary>
''' <remarks></remarks>
'''
Public Module SettingsManager
' Dim subdirName As String = "opt\"
Dim subdirName As String = MYDIR & "\opt\"
'Sub Check()
' If FileIO.FileSystem.DirectoryExists("opt") = False Then
' FileIO.FileSystem.CreateDirectory("opt")
' End If
'End Sub
Sub Check()
If FileIO.FileSystem.DirectoryExists(subdirName) = False Then
FileIO.FileSystem.CreateDirectory(subdirName)
End If
End Sub
Function GetSettingInt(ByVal name As String) As Integer
Check()
If FileIO.FileSystem.FileExists(subdirName & "s." & name & ".n") = True Then
Return CInt(File.ReadAllText(subdirName & "s." & name & ".n"))
Else
Return Nothing
End If
End Function
Function GetSettingStr(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
''' <summary>
''' Return an empty list if invalid name supplied.
''' </summary>
''' <param name="name"></param>
''' <returns></returns>
''' <remarks></remarks>
Function GetSettingStrList(ByVal name As String) As List(Of String)
Check()
If FileIO.FileSystem.FileExists(subdirName & "s." & name & ".n") = True Then
Return File.ReadAllLines(subdirName & "s." & name & ".n").ToList()
Else
Return New List(Of String)(0)
End If
End Function
Function GetSettingBool(ByVal name As String) As Boolean
Check()
If FileIO.FileSystem.FileExists(subdirName & "s." & name & ".n") = True Then
If File.ReadAllText(subdirName & "s." & name & ".n") = "True" Then
Return True
Else
Return False
End If
Else
Return Nothing
End If
End Function
Sub SetSettingInt(ByVal name As String, ByVal data As Integer)
Check()
File.WriteAllText(subdirName & "s." & name & ".n", data)
End Sub
Sub SetSettingStr(ByVal name As String, ByVal str As String)
Check()
File.WriteAllText(subdirName & "s." & name & ".n", str)
End Sub
Sub SetSettingStrList(ByVal name As String, ByVal list As List(Of String))
Check()
File.WriteAllLines(subdirName & "s." & name & ".n", list.ToArray)
End Sub
Sub SetSettingBool(ByVal name As String, ByVal bool As Boolean)
Check()
File.WriteAllText(subdirName & "s." & name & ".n", bool.ToString)
End Sub
Sub SetSettingFont(ByVal name As String, ByVal font As Font)
Check()
'Dim d As New Font("font family", Size, FontStyle.Regular, GraphicsUnit.Pixel, font.GdiCharSet)
Try
Dim fontfamilyStr As String = font.FontFamily.Name
Dim sizeStr As String = font.Size
Dim styleStr As String = font.Style.ToString
Dim gdiChatSet As String = CInt(font.GdiCharSet)
Dim text As String = fontfamilyStr & "|" & sizeStr & "|" & styleStr & "|" & gdiChatSet
File.WriteAllText(subdirName & "s." & name & ".n", text)
Catch ex As Exception
End Try
End Sub
Function getSettingFont(ByVal name As String) As Font
Check()
If FileIO.FileSystem.FileExists(subdirName & "s." & name & ".n") = True Then
Dim t As String() = File.ReadAllText(subdirName & "s." & name & ".n").Split(CChar("|"))
Dim fontfamilyStr As String = t.ElementAt(0)
Dim sizeStr As Single = CSng(t.ElementAt(1))
Dim styleStr As FontStyle = getFontStyle(t.ElementAt(2))
Dim gdiChatSet As Byte = CByte(t.ElementAt(3))
Return New Font(fontfamilyStr, sizeStr, styleStr, GraphicsUnit.Point, gdiChatSet)
Else
Return Nothing
End If
End Function
Private Function getFontStyle(ByVal s As String) As FontStyle
Select Case s
Case "Bold"
Return FontStyle.Bold
Case "Italic"
Return FontStyle.Italic
Case "Regular"
Return FontStyle.Regular
Case "Strikeout"
Return FontStyle.Strikeout
Case "Underline"
Return FontStyle.Underline
Case Else
Return FontStyle.Regular
End Select
End Function
End Module
-
May 18th, 2013, 04:10 PM
#11
Re: implicit conversion from integer to string
You're getting the warning since GetSettingInt returns an integer and you're assigning that to the Text property of a TextBox which is a String property. If you want to get rid of the warning use either of these two code lines:
Code:
TextBox14.Text = GetSettingInt("TMaxUPSpeed").ToString()
'or
TextBox14.Text = CStr(GetSettingInt("TMaxUPSpeed"))
It's always better to explicitly convert data types because you are in that case in control and the compiler doesn't have to make assumptions of what you're really trying to do. I would recommend to turn Option Strict on.
Last edited by Joacim Andersson; May 18th, 2013 at 04:13 PM.
-
May 18th, 2013, 06:53 PM
#12
Re: implicit conversion from integer to string
File.ReadAllText() returns a string though, so I'm assuming that the text you want to read is supposed to be cast to an integer. I might suggest Integer.TryParse() in that case, and return either a null string, or string.Empty on false. (Check that accordingly, and do whatever you need to do based on the returned value.) Or make this function take on the paradigm of the TryParse() method using a ByRef param, and returning a boolean based on TryParse() success or failure...
Since the value is being used for text though, why cast to an integer in the first place only to convert back to a string? Seems inefficient, and especially if you aren't going to be using this Integer value for anything else. If you want validation Integer.TryParse() is the way to go...
As mentioned above, unless you've changed your settings, Option Explicit is already on by default anyways, but Option Strict is the one that you want to have turned on. Implicit conversions are bad, and they also don't teach you to recognize what types you are dealing with if you always rely in implicit conversions being done for you. I once read an article that had this as a defense somehow for why VB.net is better than C#... Not sure how that works, but that's another story. 
Cheers
Last edited by AceInfinity; May 18th, 2013 at 06:57 PM.
<<<------------
.NET Programming (2012 - 2018)
®Crestron - DMC-T Certified Programmer | Software Developer <<<------------
-
May 18th, 2013, 08:10 PM
#13
Re: implicit conversion from integer to string
 Originally Posted by Joacim Andersson
You're getting the warning since GetSettingInt returns an integer and you're assigning that to the Text property of a TextBox which is a String property. If you want to get rid of the warning use either of these two code lines:
Code:
TextBox14.Text = GetSettingInt("TMaxUPSpeed").ToString()
'or
TextBox14.Text = CStr(GetSettingInt("TMaxUPSpeed"))
It's always better to explicitly convert data types because you are in that case in control and the compiler doesn't have to make assumptions of what you're really trying to do. I would recommend to turn Option Strict on.
Which is exactly what I said in post #3, so one wonders why the OP is still asking the same question and hasn't acted on the advice provided there.
-
May 18th, 2013, 08:16 PM
#14
Re: implicit conversion from integer to string
 Originally Posted by AceInfinity
Since the value is being used for text though, why cast to an integer in the first place only to convert back to a string? Seems inefficient, and especially if you aren't going to be using this Integer value for anything else.
You seem to be missing the point that I made in post #9. It's clear from the method name that this data represents part of the application's preferences/options/settings. The data obviously represents a number so it is completely appropriate that it be returned as a number. When the data gets used it will be used as a number. This is presumably not the only place that this setting value will be used. This particular instance is for display purposes so, as with all data, it must be in String form for that purpose. Elsewhere though, it is likely that the data will be used in a comparison with another number, so it is essential that it be a number. Would you say that My.Settings should return everything as Strings? If not then why should these home-grown settings be returned as Strings?
The possibility that the file doesn't contain a valid number has to be taken into account somewhere. If your suggestion to use TryParse is not taken up then any code that calls this method really should have it within an exception handler.
-
May 18th, 2013, 08:38 PM
#15
Re: implicit conversion from integer to string
 Originally Posted by jmcilhinney
You seem to be missing the point that I made in post #9. It's clear from the method name that this data represents part of the application's preferences/options/settings. The data obviously represents a number so it is completely appropriate that it be returned as a number. When the data gets used it will be used as a number. This is presumably not the only place that this setting value will be used. This particular instance is for display purposes so, as with all data, it must be in String form for that purpose. Elsewhere though, it is likely that the data will be used in a comparison with another number, so it is essential that it be a number. Would you say that My.Settings should return everything as Strings? If not then why should these home-grown settings be returned as Strings?
The possibility that the file doesn't contain a valid number has to be taken into account somewhere. If your suggestion to use TryParse is not taken up then any code that calls this method really should have it within an exception handler.
 Originally Posted by jmcilhinney
Presumably because the file is a text file but it contains a setting value that represents a number. When you add an Integer to My.Settings it gets stored in the config file. The config file is XML, which is structured text. As such, the value has to be read as text and converted to an Integer at some point. This is no different.
You are probably right. And if he uses this value lots of times as an Integer, I suppose a simple redundant cast back to a string wouldn't matter too much. He wouldn't have to cast the value to an Integer a whole bunch of times though when he wants to use it if the return value stays as is. I didn't consider the bigger picture and was only looking at the smaller inefficiency here, because I have a habit of only reading the thread and judging based on the given information.
Regards,
Ace
Last edited by AceInfinity; May 18th, 2013 at 09:03 PM.
<<<------------
.NET Programming (2012 - 2018)
®Crestron - DMC-T Certified Programmer | Software Developer <<<------------
-
May 18th, 2013, 10:38 PM
#16
Fanatic Member
Re: implicit conversion from integer to string
why is everyone talking about conversions, the question was what does the line of code do
TextBox14.Text = GetSettingInt("TMaxUPSpeed")
and
Function GetSettingInt(ByVal name As String) As Integer
Check()
If FileIO.FileSystem.FileExists(subdirName & "s." & name & ".n") = True Then
Return CInt(File.ReadAllText(subdirName & "s." & name & ".n"))
Else
Return Nothing
End If
End Function
simply checks if a file named "TMaxUpSpeed" exists
if it does it puts the contents of the file ( an intergeter probably) in a textbox, its wrongly coded and conversions dont need to be applied
if it does not then the textbox is left empty
it seems a little pointless(with the way its done) but thats what its doing
its that simple.
why are all u guys confusing jokerfool by following up with the conversions stuff?
Last edited by GBeats; May 18th, 2013 at 10:42 PM.
Yes!!!
Working from home is so much better than working in an office...
Nothing can beat the combined stress of getting your work done on time whilst
1. one toddler keeps pressing your AVR's power button
2. one baby keeps crying for milk
3. one child keeps running in and out of the house screaming and shouting
4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
5. working at 1 O'clock in the morning because nobody is awake at that time
6. being grossly underpaid for all your hard work

-
May 18th, 2013, 10:45 PM
#17
Fanatic Member
Re: implicit conversion from integer to string
Function GetSettingInt(ByVal name As String) As Integer
Check()
If FileIO.FileSystem.FileExists(subdirName & "s." & name & ".n") = True Then
Return CInt(File.ReadAllText(subdirName & "s." & name & ".n"))
Else
Return Nothing
End If
End Function
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
Yes!!!
Working from home is so much better than working in an office...
Nothing can beat the combined stress of getting your work done on time whilst
1. one toddler keeps pressing your AVR's power button
2. one baby keeps crying for milk
3. one child keeps running in and out of the house screaming and shouting
4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
5. working at 1 O'clock in the morning because nobody is awake at that time
6. being grossly underpaid for all your hard work

-
May 18th, 2013, 11:30 PM
#18
Re: implicit conversion from integer to string
Why? If the text in the file is an integer why shouldn't the function return an integer? It would be safer to use Integer.TryParse than CInt but the function is still returning an integer, and (unless the function causes an exception) the textbox will never be empty since the function is always returning an integer. Nothing for an integer is equal to 0.
The warning is because the integer that is returned is added to a textbox and should first be converted as posted earlier.
-
May 19th, 2013, 12:21 AM
#19
Thread Starter
Hyperactive Member
Re: implicit conversion from integer to string
So I just want to clarify that the code I am using is from 2008, please understand this, I didn't write the code, I am just asking for assistance. So thank you to the posts, I will take everything on board and make the changes. Thank you.
-
May 19th, 2013, 12:31 AM
#20
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:36 AM
#21
Thread Starter
Hyperactive Member
Re: implicit conversion from integer to string
OMG Integer or String, its all too much for me now, im so confused and it doesnt matter who explains it except for post #2, I think I understand.
This post was never intended to be a debate, I had the warning when I go to build, it didnt stop the function of the app, I just wanted to know how to remove the warning, it seems I will have to edit the code in the settings file as explained above and in doing so it has removed the error from certain lines and now refers to other lines in the settings file e.g. SetSettingInt, but there are hundreds of lines related to that error, would this mean going in and changing all those lines from int to str? I am sorry if I am not the expert here I am only the beginner and trying to learn as much as I can before the end of the line arrives for me, but thank you too all.
-
May 19th, 2013, 12:41 AM
#22
Re: implicit conversion from integer to string
Why is it too much? What are you confused about? Let us know and we can help. 
Post #3, is where the implicit conversion phenomena is best explained in my opinion: http://www.vbforums.com/showthread.p...=1#post4417245
The return value from the function is an Integer, the Text property when set, expects a type of string, so when you assign that Integer to the placeholder of the Text property, a magical conversion is done for you (an implicit conversion from the original Integer, to the String value). To avoid the "magician" doing this magic for you so to speak, you need to cast that Integer value to a string first before you assign it to the Text property. That's how you would fix it.
So as mentioned above, either CStr(), or the ToString() extension method.
it seems I will have to edit the code in the settings file as explained above
No, that function is fine... The only modification you might consider making to it, is adding Integer.TryParse() in there instead of CInt(). Everything else is fine, you shouldn't need to do anything with the function...
<<<------------
.NET Programming (2012 - 2018)
®Crestron - DMC-T Certified Programmer | Software Developer <<<------------
-
May 19th, 2013, 12:44 AM
#23
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
#24
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
#25
Re: implicit conversion from integer to string
So it wants to change from a number to a letter is that what this error is referring too?
By "letter", the proper term is String, but yes. 
The Text property is a type of String. Thus it doesn't accept an Integer. Some kind of conversion needs to happen to get the value to a type of String, before the Text property can hold that value. So if you don't have Option Strict On, and you don't do this conversion yourself (explicitly), an implicit conversion happens and this conversion is dealt with for you automatically (when a conversion can be made). This is bad practice though and should be avoided, so that's why you are getting the notification about it.
<<<------------
.NET Programming (2012 - 2018)
®Crestron - DMC-T Certified Programmer | Software Developer <<<------------
-
May 19th, 2013, 12:48 AM
#26
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
#27
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 <<<------------
-
May 19th, 2013, 01:12 AM
#28
Thread Starter
Hyperactive Member
Re: implicit conversion from integer to string
I did add the .tostring but I got that error above. Instead I added this code as mentioned and the error went away
Code:
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
-
May 19th, 2013, 01:27 AM
#29
Fanatic Member
Re: implicit conversion from integer to string
Hi,
ok yes i read it again, i missed your post.
and since it looks like its getting some sort of setting that's numerical then it makes sense to have the function like that.
i wasnt thinking but practically its a good way to get "0" in the string if there is nothing there, since naturally integers start of as 0.
point taken sry
the function still is has potential problems with the way it is, and is relying of outside information being correct to prevent a crash.
Yes!!!
Working from home is so much better than working in an office...
Nothing can beat the combined stress of getting your work done on time whilst
1. one toddler keeps pressing your AVR's power button
2. one baby keeps crying for milk
3. one child keeps running in and out of the house screaming and shouting
4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
5. working at 1 O'clock in the morning because nobody is awake at that time
6. being grossly underpaid for all your hard work

-
May 19th, 2013, 01:31 AM
#30
Fanatic Member
Re: implicit conversion from integer to string
jokerfool please NOTE
if the function is used somewhere else while code like my suggestion, you will need to do more conversions, but if its not then you will be fine.
the error you have might also be caused by the file itself, you should check the data inside the file.
obviously you cant use Cint("with this") because there are no numbers there, i dont know what it would return but it wouldnt be what you wanted that is sure.
Yes!!!
Working from home is so much better than working in an office...
Nothing can beat the combined stress of getting your work done on time whilst
1. one toddler keeps pressing your AVR's power button
2. one baby keeps crying for milk
3. one child keeps running in and out of the house screaming and shouting
4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
5. working at 1 O'clock in the morning because nobody is awake at that time
6. being grossly underpaid for all your hard work

-
May 19th, 2013, 01:32 AM
#31
Re: implicit conversion from integer to string
 Originally Posted by jokerfool
I did add the .tostring but I got that error above. Instead I added this code as mentioned and the error went away
Code:
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
No... Please read through the posts again, it was suggested not to do this as a final consensus.
Does this make sense?
1. GetSettingInt
2. Return value: String
What was the error you were getting with ToString()?
<<<------------
.NET Programming (2012 - 2018)
®Crestron - DMC-T Certified Programmer | Software Developer <<<------------
-
May 19th, 2013, 01:42 AM
#32
Thread Starter
Hyperactive Member
Re: implicit conversion from integer to string
When I change to .ToString() it says:
Expression does not produce a value
-
May 19th, 2013, 01:43 AM
#33
Re: implicit conversion from integer to string
I have a hard time believing that you're using the function correctly.. Can you show us your exact code when it gives you that error and are you sure it is with that line?
<<<------------
.NET Programming (2012 - 2018)
®Crestron - DMC-T Certified Programmer | Software Developer <<<------------
-
May 19th, 2013, 01:45 AM
#34
Thread Starter
Hyperactive Member
Re: implicit conversion from integer to string
Already did that, its posted above.
-
May 19th, 2013, 01:46 AM
#35
Re: implicit conversion from integer to string
 Originally Posted by jokerfool
When I change to .ToString() it says:
Expression does not produce a value
Then you did it wrong. How about you show us what you did and then we can tell you what's wrong with it?
-
May 19th, 2013, 01:59 AM
#36
Thread Starter
Hyperactive Member
Re: implicit conversion from integer to string
Okay I guess I must of made a mistake somewhere, so is this correct? Cos the line is no longer highlighted saying that message, but will adding that .ToString() to the end of the line chance the functionality of the application?
TextBox14.Text = GetSettingInt("TMaxUPSpeed").ToString()
-
May 19th, 2013, 02:00 AM
#37
Fanatic Member
Re: implicit conversion from integer to string
you should double check the file that you getting the info for, your applying a text extraction, maybe the file contains an object, or nothing at all.
you said you already changed the function to return string, what did the textbox show when you did that?
Yes!!!
Working from home is so much better than working in an office...
Nothing can beat the combined stress of getting your work done on time whilst
1. one toddler keeps pressing your AVR's power button
2. one baby keeps crying for milk
3. one child keeps running in and out of the house screaming and shouting
4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
5. working at 1 O'clock in the morning because nobody is awake at that time
6. being grossly underpaid for all your hard work

-
May 19th, 2013, 02:08 AM
#38
Thread Starter
Hyperactive Member
Re: implicit conversion from integer to string
When I made that change you mentioned the error for that section disappeared, the error moved onto another section within the settings that I mentioned above
-
May 19th, 2013, 02:15 AM
#39
Re: implicit conversion from integer to string
 Originally Posted by jokerfool
Okay I guess I must of made a mistake somewhere, so is this correct? Cos the line is no longer highlighted saying that message, but will adding that .ToString() to the end of the line chance the functionality of the application?
TextBox14.Text = GetSettingInt("TMaxUPSpeed").ToString()
No it won't. Either way, the number is being retrieved from the file and displayed in the TextBox. The difference is that the ToString means that the Integer is converted to a String explicitly while previously it was being converted implicitly. It's being converted either way though. Do you actually know what implicit and explicit mean? That would probably be a good place to start.
-
May 19th, 2013, 02:24 AM
#40
Thread Starter
Hyperactive Member
Re: implicit conversion from integer to string
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
|