|
-
May 30th, 2007, 11:58 AM
#1
Thread Starter
Fanatic Member
Just some clarification...
When using the SaveSetting command the parameters are as follows:
Code:
SaveSetting (AppName[String], Section[String], Key[String], Setting[String])
Since they are all strings (same as GetSetting parameters are), then how come something like this will work:
Code:
SaveSetting "Some Program", "Section 1", "5", "1"
or
Code:
Check1.Value = GetSetting("Some Program", "Section 1", "5", "1")
Without a type mismatch error happening.
But if i have a Function with the following in it...
Code:
Public Function SomethingToDo (FirstParameter As String, SecondParameter As String) As String
and pass integers into it, it will error with type mismatch.
How does visual basic get around this? I don't want to use Variants because problems will come when i'm converting back to integers or what ever. So what would i put inside the function parameters to make it "fuzzy"?
-
May 30th, 2007, 12:17 PM
#2
Re: Just some clarification...
Because "5" is a string and 5 is an integer.
-
May 30th, 2007, 12:19 PM
#3
Thread Starter
Fanatic Member
Re: Just some clarification...
Check1.Value = GetSetting("Some Program", "Section 1", "5", "1")
What about this?, GetSetting returns a string, but Check1.Value is an integer.
As long as it returns a number it won't error even though the types don't match up =S and how can i make this behavour happen in functions and subs that i create?
Last edited by Slyke; May 30th, 2007 at 12:27 PM.
-
May 30th, 2007, 01:10 PM
#4
Re: Just some clarification...
Check1.Value = CInt(GetSetting("Some Program", "Section 1", "5", "1"))
Now it returns an Integer.
-
May 30th, 2007, 02:02 PM
#5
Re: Just some clarification...
 Originally Posted by Slyke
how can i make this behavour happen in functions and subs that i create?
If the values you pass can be coerced into the types required, VB does that silently. IOW, if your sub is
Code:
Private Sub Test(iTest As Integer)
And you call it with It will work, since "5" will be coerced into 5. Or you could write your sub to expect a variant if that's what you really want to do - then test for what you need - If IsNumeric(vMyVariant), IsArray(aMyVariant), etc.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
May 30th, 2007, 10:57 PM
#6
Thread Starter
Fanatic Member
Re: Just some clarification...
Oh, ok, but sometimes it comes up with a type mismatch and when i check what is inside the string, it is only a number. This happens alot when i load a string from a file and try to put it into an integer even though it's only a number.
-
May 30th, 2007, 11:11 PM
#7
Re: Just some clarification...
Don't rely on implicit conversion.
If a type mismatch occurs then explicit conversion is necessary, such as with CInt(). But as I mentioned earlier don't rely on implicit conversion... you should have converted the string to begin with since you already knew it was a string and that you were gonna assign it to a variable of another data type... you then wouldn't be having this error.
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
|