Emuforums.com

Go Back   Emuforums.com > General Discussion > Web development / Programming
Home Register Downloads FAQ Members List Calendar Arcade Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
Old October 14th, 2009   #1 (permalink)
Registered User
 
krissgjeng's Avatar
 
Join Date: Sep 2007
Location: norway
Posts: 226
simple visual basic 2008 programming question

Code:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim d1 As Double
        d1 = CDbl("12.2")
        TextBox1.Text = CStr(d1)
    End Sub
End Class
can anyone tell me why this won't work
i get this error:
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll

if however i write "12,2" (using comma instead, it works)
but withouth conversion it only accepts periods.

is it supposed to work like that?
__________________

pc configuration:
cpu: AMD Athlon 64 X2 6000+ 3.0GHz, GPU: GeForce 8800GTS 640MB, MoBo: Asus M2N32-SLI Deluxe, RAM: Corsair 6GB, case: Cooler Master Centurion 534, HDs: Seagate 500GB + 750GB +external 1TB, Os: Archlinux & Windows 7. my website
krissgjeng is offline   Reply With Quote

Advertisement [Remove Advertisement]
Old October 14th, 2009   #2 (permalink)
Emu author
 
@ruantec's Avatar
 
Join Date: Nov 2002
Location: Austria (originally from Dominican Republic)
Posts: 2,380
mmm thatīs really interesting and it works fine here...anyways iīve seen similar problems while using a German OS and working with Decimal values on SQL databases in a English SQL Server.. atm am using a english one tho.

anyways this code works great for me:
Code:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim d1 As Double
        d1 = CDbl("12,2")
        TextBox1.Text = d1.ToString()
    End Sub
End Class
btw i used the method .ToString() instead of CStr() because i think its better..

anyways you could use a Try-Catch and post the message here so i can see more info about the problem.. something like that:
Code:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim d1 As Double
        Try
            d1 = CDbl("12,2")
            TextBox1.Text = d1.ToString()
        Catch ex As Exception
            Throw New ArgumentException(ex.Message)
        End Try
    End Sub
End Class
other than that i recommend you to set a break point at the start of the page_load event and step through(F10 or F11) and find out where it fails and in that way see the reason why it fail to cast??? at least it seems to be the problem.
__________________

Current development tools:

Visual C++.net, Visual C#.net
Visual VB.net, Visual Webdeveloper.net
Bloodshed Dev C++, Borland C++
Visual Basic 6

Last edited by @ruantec; October 14th, 2009 at 12:47..
@ruantec is offline   Reply With Quote
Old October 14th, 2009   #3 (permalink)
Registered User
 
krissgjeng's Avatar
 
Join Date: Sep 2007
Location: norway
Posts: 226
it seems like if the decimal symbol in the regional settings is set to comma(,) it won't accept periods(.) as a decimal sign when converting from string to double, though in the code it still uses periods.

so when i changed the decimal symbol from , to . in the regional settings it worked just fine.
__________________

pc configuration:
cpu: AMD Athlon 64 X2 6000+ 3.0GHz, GPU: GeForce 8800GTS 640MB, MoBo: Asus M2N32-SLI Deluxe, RAM: Corsair 6GB, case: Cooler Master Centurion 534, HDs: Seagate 500GB + 750GB +external 1TB, Os: Archlinux & Windows 7. my website
krissgjeng is offline   Reply With Quote
Old October 14th, 2009   #4 (permalink)
Emu author
 
@ruantec's Avatar
 
Join Date: Nov 2002
Location: Austria (originally from Dominican Republic)
Posts: 2,380
Yes... as i mentioned in my previous post it seems like a regional setting problem.. like the ones i had in the past with a German OS and a English SQL Server or vice-versa.
__________________

Current development tools:

Visual C++.net, Visual C#.net
Visual VB.net, Visual Webdeveloper.net
Bloodshed Dev C++, Borland C++
Visual Basic 6
@ruantec is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 14:14.

© 2006 - 2008 Emu Forums | About Emu Forums | Legal | A member of the Crowdgather Forum Community


Powered by vBulletin® Version 3.7.6
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5