RobotStudio event

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 Drown
  • 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

     

  • Can you use tempDouble.ToString?
    Russell Drown
  • 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 Sub

        Private 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 Sub

        Private 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 Sub

    End Class