|
|
Search
|
|||||||
| Home | Register | Downloads | FAQ | Members List | Calendar | Arcade | Mark Forums Read |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Registered User
![]() ![]() 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
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 |
|
|
|
| Advertisement | [Remove Advertisement] | ||
|
|
|
|
#2 (permalink) |
|
Emu author
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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
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
__________________
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.. |
|
|
|
|
|
#3 (permalink) |
|
Registered User
![]() ![]() 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 |
|
|
|
|
|
#4 (permalink) |
|
Emu author
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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 |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|