|
-
Apr 25th, 2013, 12:23 PM
#1
Thread Starter
New Member
Period vs Comma problem
Hey!
So I enter a standard value of my labels. Which is 1,20.
When I add 0.2 to it on my pc. It becomes 1,40.
On my brother's pc, it's 1.20,20?
Can someone explain, please?
Greetz
Flexam
-
Apr 25th, 2013, 12:38 PM
#2
Re: Period vs Comma problem
There are a few reasons why, the most obvious one is region/culture settings which dictate what the actual "period" character is. However, why are you adding 0.2 (supposedly a number) to a Label with a text value of 1,20. That doesn't make much sense. Why don't you show us the code you're using so we can further see what's going on.
You also might want to set Option Strict and Option Explicit to On.
Last edited by formlesstree4; Apr 25th, 2013 at 12:39 PM.
Reason: Clarification
-
Apr 25th, 2013, 12:41 PM
#3
Re: Period vs Comma problem
There's two problems here, the first problem is that you and your brother have different culture settings, one of you have a setting where comma is treated as the decimal point while the other doesn't. The second (and this is the main problem) is that you're trying to add a number to a string. If you would convert both values to a number (a floating point value such as a Single or a Double) the problem would go away.
If you post the code you have I'll show you how to do it, but basically you probably do something like this:
Code:
Label1.Text = Label1.Text + 0.2
If you would turn Option Strict to On VB wouldn't even allow that code, which would have helped you in debugging it. (My point being, always use Option Strict On).
Edit: Sometimes other people types quicker than me. Good work Formless!
Last edited by Joacim Andersson; Apr 25th, 2013 at 12:44 PM.
-
Apr 25th, 2013, 01:41 PM
#4
Thread Starter
New Member
Re: Period vs Comma problem
If it works on my settings (dutch). Are there any complications except for other languages?
How could I resolve it?
-
Apr 25th, 2013, 01:50 PM
#5
Re: Period vs Comma problem
 Originally Posted by flexam
If it works on my settings (dutch). Are there any complications except for other languages?
How could I resolve it?
By not mixing strings with numbers... Post your code and we'll show you how to correct it. (You don't have to change your regional settings).
-
Apr 25th, 2013, 01:53 PM
#6
Thread Starter
New Member
Re: Period vs Comma problem
Code:
dim aJupiler as integer
dim Lichtbier as list(of integer)
Select Case aJupiler 'Bereken de plaats in arraylist
Case Is = Lichtbier(4)
Select Case bLbl1.Text
Case Is = 3
bPictureBox1.Image = My.Resources.greyarrow
bLbl1.Text = 3
Case Is > 3
bPictureBox1.Image = My.Resources.greenarrow
bLbl1.Text = 3
Case Is < 2.81
bPictureBox1.Image = My.Resources.greenarrow
bLbl1.Text += 0.2
Case Is = 2.9
bPictureBox1.Image = My.Resources.greenarrow
bLbl1.Text += 0.1
End Select
End Select
-
Apr 25th, 2013, 02:04 PM
#7
Re: Period vs Comma problem
See, here's your problem:Actually you have several of those but with other numbers besides 0.2, you also have 0.1 and so on. Even your Select Case assumes there are numbers in your bLbl1.Text (which I assume is a Label). You need to understand that the Text property is a string (of text) not numeric, even if it contains a number. Text is Text and nothing else. What you need to do is to first convert that to the correct type, for example a Double. Since this is not user input (meaning the Text property will never be something like "Hello World" or something like that) you can get away by doing a direct conversion.
Code:
Dim value As Double = CDbl(bLbl1.Text)
'...
Select Case value ' <- Not the Text property but the numeric value you just converted the Text property into
'...
Case Is 2.9
bPictureBox1.Image = ...
value += 0.1
End Select
'Now convert the number back into a string
bLbl1.Text = CStr(value)
-
Apr 25th, 2013, 02:10 PM
#8
Thread Starter
New Member
Re: Period vs Comma problem
Okay, I'll implement this in my code! Thanks so much
-
Apr 25th, 2013, 02:11 PM
#9
Re: Period vs Comma problem
Just to make sure you understand the difference:
1 + 2 = 3
"a" + "b" = "ab"
"1" + "2" = "12"
If you would turn Option Strict On VB would tell you that you where mixing text with numbers and asked you to correct it (well, it would have given you a compile time error).
-
Apr 25th, 2013, 02:14 PM
#10
Thread Starter
New Member
Re: Period vs Comma problem
I see, do you have any good sites/tutorials for vb?
-
Apr 25th, 2013, 02:16 PM
#11
Addicted Member
Re: Period vs Comma problem
-
Apr 25th, 2013, 02:18 PM
#12
Re: Period vs Comma problem
Yeah sure. It's not a tutorial site but it's a great place to learn VB, all the experts hang around there.
-
Apr 25th, 2013, 02:21 PM
#13
Thread Starter
New Member
Re: Period vs Comma problem
Thanks a lot guys! Appreciate it! Too bad i'm not an expert
-
Apr 25th, 2013, 02:28 PM
#14
Re: Period vs Comma problem
If you turn Option Strict On you will become an expert much faster than if you keep it off. The thing is that when it's turned Off (which unfortunately is the default) VB will allow you to mix things that are not the same and try to guess what you really want. To go back to my earlier explanation:
1 + 2 = 3
"a" + "b" = "ab"
"1" + "2" = "12"
"1" + 2 = ????? Either 3 or 12, what do you want? I don't know so let me just put one of them in and assume that that is what you want...
The last comment is true when you have Option Strict turned Off. If you turn it On then VB will stop guessing and ask you to be specific instead.
-
Apr 25th, 2013, 02:37 PM
#15
Thread Starter
New Member
Re: Period vs Comma problem
I've put it on now. Seems like I have to correct a whole lot
-
Apr 25th, 2013, 02:40 PM
#16
Re: Period vs Comma problem
 Originally Posted by flexam
I've put it on now. Seems like I have to correct a whole lot 
But correcting those mistakes will get you one big step closer to becoming an expert.
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
|