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
Printable View
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
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.
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: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).Code:Label1.Text = Label1.Text + 0.2
Edit: Sometimes other people types quicker than me. ;) Good work Formless!
If it works on my settings (dutch). Are there any complications except for other languages?
How could I resolve it?
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
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:bLbl1.Text += 0.2
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)
Okay, I'll implement this in my code! Thanks so much
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).
I see, do you have any good sites/tutorials for vb?
This is a good one: http://www.homeandlearn.co.uk/NET/vbNet.html
Yeah sure. It's not a tutorial site but it's a great place to learn VB, all the experts hang around there. :)
Thanks a lot guys! Appreciate it! Too bad i'm not an expert ;)
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.
I've put it on now. Seems like I have to correct a whole lot :D