Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
As part of my on-going testing of Excel Automation using vb 2008 and Office 2007, I decided to create a virtual Machine in my Local computer.

I'm still trying to find solution bout the InterOp assembly which I posted in another thread.

In my Query Form, I declared the Textbox value as string, then converted to double and is use in my Select Statement,

Dim Rate1 as String = Me.Textbox6.Text
Dim nRate as Double = CDbl(Rate1)

Tested this in my local and is working Okay. Created a SetUp and copied the Setup to my Virtual Machine and Install It, the program is working okay and i can produce views(DGV) and outputs(textfile). Some reports uses the TextBox6 and its value, but this is where I recieve this Error "Convert String to double is Invalid?",

in Prerequisite Components, i checked this;

Windows Installer 3.1<br />
.Net Framework 3.5 SP1<br />
Microsoft Office 2007 Primary InterOp Assemblies


I have also installed windows xp and office 2007 in my virtual machine.
Posted
Updated 31-Jan-12 20:50pm
v4
Comments
Rajesh Anuhya 1-Feb-12 2:51am    
Edited.
--RA
Alan Tuscano 1-Feb-12 2:54am    
Hi Rajesh, why can't i do that stuff.. i tried making it into vb code, tried making it into bold but nothing has change. And U simply updated it by making some lines into red and highlighting some... cool.. :)

Well, not all Strings are compatible Doubles. How would, for example, "Hi" or an empty String be converted to a numeric value?
Of course I can't see your dataset, but it seems there are some non-numeric values in there.
What would be a lot safer is to call Double.TryParse[^].
Usage as follows:
VB
Dim d As Double ' If only this were C#, we would've had Double d :)
If Double.TryParse(Me.TextBox6.Text, d) Then
   ' The string was successfully converted.
   ' Your variable d now has the converted value.
Else
   ' The string was not a numeric value.
   ' Nothing happened to d.
End If
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 1-Feb-12 2:57am    
Of course. My 5.
Not clear what all the OP's text to do with this question. It isn't a question though; I would not answer.
--SA
Sander Rossel 1-Feb-12 6:57am    
Thanks SA. The OP clearly had a converting problem. There was only one line of code where the conversion could fail, so I merely suggested this approach :)
Though I agree the problem wasn't very clear to begin with.
Alan Tuscano 1-Feb-12 2:57am    
Hi Naerling,
forgot to detail textbox6.. :)
It will only be used when User selects the report that will create Excel spreedsheet, and the value from the textbox is the Exchange rate.

I'll try your code and get back to you soon.
Simon_Whale 1-Feb-12 4:16am    
+5 good answer and also like your commented reference too
Sander Rossel 1-Feb-12 6:57am    
Thanks :)
use
VB
Dim nRate as Double=Double.Parse(Rate1 );
 
Share this answer
 
You have to do some validation of the textbox text before you convert it.

If TextBox6 is blank, CDbl will throw the error you're seeing.

If would be better to use Double.Parse() or .TryParse() instead, but you still have to make sure the textbox has a value before you try and parse it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900