Re: Regional settings cause runtime crash

Tech-Archive recommends: Fix windows errors by optimizing your registry



"Colmag" <Colmag@xxxxxxxxxxxxxxxxxxxxxxxxx> schrieb
Marina,

Thanks for the suggestion.  It seems I'm doing something dodgy in
converting variable types.

Because there are so many places where people have restricted access
rights, I've avoided writing anything to the registry.  To store
application settings such as window positions, I write a text file
containing these settings when the app closes, and read the config
file when the app starts.

I'm declaring a variable as a string which equals a line from the
text file and then applying that to my application.  e.g:

Dim MainTop As String = streamtoread.ReadLine
Me.top = MainTop

The main problem seems to be that you don't use Option Strict. If you used it you would be aware of all conversions taking place.


With appropriate regional settings (decimal separator = .) .net
converts the string to an integer no problem, but as soon as I
change the regional setting to something like a comma, the
conversion no longer works.

Are you sure at this line? I haven't seen an integer using a decimal separator, ever. ;-) How do you /write/ the line into the file?



Whenever you use the text representation of a value you must be aware of the format being used. Internally, one should store all values in it's native format, i.e. date values in DateTime variables etc. If you convert a value from it's native format to string or vice versa, the string format must be taken into account. To store and read application settings, you should use a fixed format. You can use the InvariantCulture to do this. Your application will run independent from the regional settings of the machine where it is running on. To present data to the user, use the regional settings that are usually used automatically used if you use ToString or Parse without additional formatting information.





Armin


.



Relevant Pages

  • Re: Format an Excel Column in the windows short date format.
    ... Dim Buffer As String, Ret As Long ... Dim GetInfo As String ... It works for most regional settings but not Norwegian. ... If anyone can point me in the right direction on how to format a column ...
    (microsoft.public.excel.programming)
  • Re: Date Formatting in VB6
    ... That would mean your nicely formatted yyyy-mm-dd text is being converted ... Dim sDate As String, dDate As Date ... I thought about converting the string back to date for ... to put it in the proper format but I still get mm/dd/yyyy. ...
    (microsoft.public.vb.syntax)
  • Re: Date String Format issues converting from VB6 to VB 2005.NET
    ... There is a breaking change from VB6 to VB.Net relating to date formatting characters. ... You haven't mentioned what the data type of TradeDate is but because you are attempting to assign a formatted value I will assume it is a string. ... Assuming that it contains a string in yyyy/MM/dd format, then to convert it to MMddyy format you need to convert it to a date and then reconvert it to a string. ... with string formatting converting an application from VB6. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Format an Excel Column in the windows short date format.
    ... I display the same string. ... Dim GetInfo As String ... It works for most regional settings but not Norwegian. ... using the NumberFormatLocal format produced the same result. ...
    (microsoft.public.excel.programming)
  • Re: Encoding of primitives for binary serialization
    ... Once you get around endian issues, there's no real problems to a binary format. ... the value to string and then write the string in binary ... Converting decimals to and from string representations is liable to munge the lowest bits, assuming you even get a precise representation. ...
    (comp.lang.java.programmer)