Problem with CStr()
Hi,
I'm Experimenting with the Flexpendant.
I'm having some problem converting values between double and string. I have used the following two lines to try and see what happens:
tempDouble = 12.45
TpsLabel4.Text = CStr(tempDouble)
The resulting string is then converted to: "12,45" it should be: "12.45".
Why is this?
/perM
Comments
-
It looks like it is using a localized format to display the value, are you using a non-english version of Vsual Studio, do you have additional languages enabled in your RobotWare system?
Russell Drown0 -
The Windows language is Swedish, the Visual Studio Installation is English, the System in the Virtual Flexpendant is English.
I Managed to make a workaround for now. I made a "ChangeCharacter" function that I use before and after conversion, to make sure i have the correct decimal character.
it seams to work for now.
But it would be nice to now why there is a problem to begin with.
/PerM
0 -
Can you use tempDouble.ToString?Russell Drown0
-
CStr always take your regional settings into consideration. Instead in .NET it is customary to use the ToString method which is overloaded to define whatever formatting that you want.
Here is an example code, create a Windows form and add three buttons
Button1 is using CStr which will use the seperator defined by your culture
Button2 will use *.*
Button3 will use *,*Imports System.Globalization
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myDouble As Double
myDouble = 12.345
Button1.Text = CStr(myDouble)
End SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim myDouble As Double
myDouble = 12.345
Dim x As New NumberFormatInfo
x.NumberDecimalSeparator = "."
Button2.Text = myDouble.ToString(x)
End SubPrivate Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim myDouble As Double
myDouble = 12.345
Dim x As New NumberFormatInfo
x.NumberDecimalSeparator = ","
Button3.Text = myDouble.ToString(x)
End SubEnd Class
John
Developer Center0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 314 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 794 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings