473,598 Members | 3,161 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ARGH! Converting the value of a dtatable from a string to a Double

Hi All :-)

I found the way to get my column sum (Thanks Cor I did it a little different, but the result is what I wanted) I used:

dt_stat_report_ 3b.Columns.Add( New DataColumn("Sum ", GetType(Double) , "sum(Column_10_ ld_act_125_gtr_ fy_fy_hh_avg)") )
where dt_stat_report_ 3b is my datatable, Sum is my column name and sum(Column_10_l d_act_125_gtr_f y_fy_hh_avg) is the sum of the column I needed. This Does return me the correct value in the column I've specified, but now I need that value to be stored in a variable that I can use in another calculation. I've tried:

ld_act_125_gtr_ fy_hh_avg_grnd_ tot = CDbl(dt_stat_re port_3b.Columns .Item(15).ToStr ing)

Where ld_act_125_gtr_ fy_hh_avg_grnd_ tot is the variable and is declared as a Double. This returns an error that the input string was not in the correct format. What I really want to do is get the value from that column and populate the variable with it. I CAN'T get the CDbl() to work! I've tried to do it as CDbl(), I tried System.Convert. ToDouble() but I ALWAYS get an error that the input string was in an incorrect format. I just want the VALUE from the Column that I've summed! Please, can someone explain how to get the string to convert to a double or how to get dt_stat_report_ 3b.Columns.Item (15).Value? Value is not an option and I don't know what else to try!

Any help is GREATLY Appreciated, since I have spent all day on this problem!

Thanks!

Coleen

Nov 21 '05 #1
9 2079
jim
Hi Coleen,

i'm not 100% sure that i understand your problem. are you able to get the
value from the computed field? if so, what datatype is the column in which
the data resides.

if you just need to convert the string to a double then you can use the
parse method.

Double.Parse(dt _stat_report_3b .Columns.Item(1 5).ToString)

overloaded methods allow you to provide a formatprovider and/or a
numberstyle

if the computed column was created with a datatype of Double, then
theoretically

CDbl(myDatatabl e.Rows(myRowInd ex)(myComputedC olumnName))

should pull the data from the field... (theoretically. ..) but, i haven't
worked much with computed columns yet.

hope this helps.

good luck,

jim
"Coleen" <co**********@y aho.com> wrote in message
news:e4******** ******@TK2MSFTN GP12.phx.gbl...
Hi All :-)

I found the way to get my column sum (Thanks Cor I did it a little
different, but the result is what I wanted) I used:

dt_stat_report_ 3b.Columns.Add( New DataColumn("Sum ", GetType(Double) ,
"sum(Column_10_ ld_act_125_gtr_ fy_fy_hh_avg)") )
where dt_stat_report_ 3b is my datatable, Sum is my column name and
sum(Column_10_l d_act_125_gtr_f y_fy_hh_avg) is the sum of the column I
needed. This Does return me the correct value in the column I've specified,
but now I need that value to be stored in a variable that I can use in
another calculation. I've tried:

ld_act_125_gtr_ fy_hh_avg_grnd_ tot =
CDbl(dt_stat_re port_3b.Columns .Item(15).ToStr ing)

Where ld_act_125_gtr_ fy_hh_avg_grnd_ tot is the variable and is declared as a
Double. This returns an error that the input string was not in the correct
format. What I really want to do is get the value from that column and
populate the variable with it. I CAN'T get the CDbl() to work! I've tried
to do it as CDbl(), I tried System.Convert. ToDouble() but I ALWAYS get an
error that the input string was in an incorrect format. I just want the
VALUE from the Column that I've summed! Please, can someone explain how to
get the string to convert to a double or how to get
dt_stat_report_ 3b.Columns.Item (15).Value? Value is not an option and I
don't know what else to try!

Any help is GREATLY Appreciated, since I have spent all day on this problem!

Thanks!

Coleen
Nov 21 '05 #2
Coleen,
ld_act_125_gt r_fy_hh_avg_grn d_tot = CDbl
(dt_stat_repo rt_3b.Columns.I tem(15).ToStrin g)


The datatable is created vertical (columns) and used horizontal (rows).

Is this what you mean?

ld_act_125_gtr_ fy_hh_avg_grnd_ tot = dt_stat_report_ 3b.rows("Sum"). Item(15)

I hope this helps?

Cor
Nov 21 '05 #3
I've tried both suggestions. Here is the code I'm trying:

dt_stat_report_ 3b.Columns.Add( New DataColumn("Sum ", GetType(Double) , "sum(Column_10_ ld_act_125_gtr_ fy_fy_hh_avg)") )
where dt_stat_report_ 3b. is the datatable, Sum is the compute, and Column_10_ld_ac t_125_gtr_fy_fy _hh_avg is the column that I'm getting the grand total for.

I have a For/Next Loop where I have variable ld_pct_125_tot_ gtr_fy_hh that I need to have the following calculation:

ld_pct_125_tot_ gtr_fy_hh = ld_act_125_gtr_ fy_hh_avg/sum for 17 rows in the Loop. Each row has a different average thus the variable ld_act_125_gtr_ fy_hh_avg. the computed column "sum" is the total of all the rows of the variable ld_act_125_gtr_ fy_hh_avg.

I've tried EVERYTHING I can think of to get the value from the computed column "sum" into a variable name. I either get a message that the input string was not in the correct format, or I get a message when I try:

ld_act_125_gtr_ fy_hh_avg_grnd_ tot = CDbl(dt_stat_re port_3b.Rows(0) .Item(0).ToStri ng) that the Row or Item does not exist.

There HAS to be a way to get the value from the computed item into a variable as a double so that I can use that value in my next calculation. I' am at a loss and in desperate need of help! Thanks you so much for trying :-)

Coleen


"Cor Ligthert" <no**********@p lanet.nl> wrote in message news:uA******** ******@TK2MSFTN GP10.phx.gbl...
Coleen,
ld_act_125_gt r_fy_hh_avg_grn d_tot = CDbl
(dt_stat_repo rt_3b.Columns.I tem(15).ToStrin g)


The datatable is created vertical (columns) and used horizontal (rows).

Is this what you mean?

ld_act_125_gtr_ fy_hh_avg_grnd_ tot = dt_stat_report_ 3b.rows("Sum"). Item(15)

I hope this helps?

Cor

Nov 21 '05 #4
For anyone looking at this, here is the solution thanks to my very good VB.Net Teacher whom I called in desperation - Thanks Jerry!!!

Dim the variable as Public. On PreRender use:

PublicVariableN ame = DatatabelName.R ow(0).Cell(15). Value

I could not get the option of value after row or cell in anything I tried within my For/Next Loop. I can now use this Variable value to do my calculations for the percentage rate. Again - THANKS Jerry!
"Coleen" <co**********@y aho.com> wrote in message news:Oa******** *****@tk2msftng p13.phx.gbl...
I've tried both suggestions. Here is the code I'm trying:

dt_stat_report_ 3b.Columns.Add( New DataColumn("Sum ", GetType(Double) , "sum(Column_10_ ld_act_125_gtr_ fy_fy_hh_avg)") )
where dt_stat_report_ 3b. is the datatable, Sum is the compute, and Column_10_ld_ac t_125_gtr_fy_fy _hh_avg is the column that I'm getting the grand total for.

I have a For/Next Loop where I have variable ld_pct_125_tot_ gtr_fy_hh that I need to have the following calculation:

ld_pct_125_tot_ gtr_fy_hh = ld_act_125_gtr_ fy_hh_avg/sum for 17 rows in the Loop. Each row has a different average thus the variable ld_act_125_gtr_ fy_hh_avg. the computed column "sum" is the total of all the rows of the variable ld_act_125_gtr_ fy_hh_avg.

I've tried EVERYTHING I can think of to get the value from the computed column "sum" into a variable name. I either get a message that the input string was not in the correct format, or I get a message when I try:

ld_act_125_gtr_ fy_hh_avg_grnd_ tot = CDbl(dt_stat_re port_3b.Rows(0) .Item(0).ToStri ng) that the Row or Item does not exist.

There HAS to be a way to get the value from the computed item into a variable as a double so that I can use that value in my next calculation. I' am at a loss and in desperate need of help! Thanks you so much for trying :-)

Coleen


"Cor Ligthert" <no**********@p lanet.nl> wrote in message news:uA******** ******@TK2MSFTN GP10.phx.gbl...
Coleen,
ld_act_125_gt r_fy_hh_avg_grn d_tot = CDbl
(dt_stat_repo rt_3b.Columns.I tem(15).ToStrin g)


The datatable is created vertical (columns) and used horizontal (rows).

Is this what you mean?

ld_act_125_gtr_ fy_hh_avg_grnd_ tot = dt_stat_report_ 3b.rows("Sum"). Item(15)

I hope this helps?

Cor

Nov 21 '05 #5
Well, I spoke to soon...this works great if you just want to display the value, but if you want to use the value to perform another calculation, I get "Infinity" in the cell where I'm trying to use the grand total I get from the PreRender.. any other suggestions?

PLEASE? TIA
"Coleen" <co**********@y aho.com> wrote in message news:OV******** *****@TK2MSFTNG P12.phx.gbl...
For anyone looking at this, here is the solution thanks to my very good VB.Net Teacher whom I called in desperation - Thanks Jerry!!!

Dim the variable as Public. On PreRender use:

PublicVariableN ame = DatatabelName.R ow(0).Cell(15). Value

I could not get the option of value after row or cell in anything I tried within my For/Next Loop. I can now use this Variable value to do my calculations for the percentage rate. Again - THANKS Jerry!
"Coleen" <co**********@y aho.com> wrote in message news:Oa******** *****@tk2msftng p13.phx.gbl...
I've tried both suggestions. Here is the code I'm trying:

dt_stat_report_ 3b.Columns.Add( New DataColumn("Sum ", GetType(Double) , "sum(Column_10_ ld_act_125_gtr_ fy_fy_hh_avg)") )
where dt_stat_report_ 3b. is the datatable, Sum is the compute, and Column_10_ld_ac t_125_gtr_fy_fy _hh_avg is the column that I'm getting the grand total for.

I have a For/Next Loop where I have variable ld_pct_125_tot_ gtr_fy_hh that I need to have the following calculation:

ld_pct_125_tot_ gtr_fy_hh = ld_act_125_gtr_ fy_hh_avg/sum for 17 rows in the Loop. Each row has a different average thus the variable ld_act_125_gtr_ fy_hh_avg. the computed column "sum" is the total of all the rows of the variable ld_act_125_gtr_ fy_hh_avg.

I've tried EVERYTHING I can think of to get the value from the computed column "sum" into a variable name. I either get a message that the input string was not in the correct format, or I get a message when I try:

ld_act_125_gtr_ fy_hh_avg_grnd_ tot = CDbl(dt_stat_re port_3b.Rows(0) .Item(0).ToStri ng) that the Row or Item does not exist.

There HAS to be a way to get the value from the computed item into a variable as a double so that I can use that value in my next calculation. I' am at a loss and in desperate need of help! Thanks you so much for trying :-)

Coleen


"Cor Ligthert" <no**********@p lanet.nl> wrote in message news:uA******** ******@TK2MSFTN GP10.phx.gbl...
Coleen,
ld_act_125_gt r_fy_hh_avg_grn d_tot = CDbl
(dt_stat_repo rt_3b.Columns.I tem(15).ToStrin g)


The datatable is created vertical (columns) and used horizontal (rows).

Is this what you mean?

ld_act_125_gtr_ fy_hh_avg_grnd_ tot = dt_stat_report_ 3b.rows("Sum"). Item(15)

I hope this helps?

Cor

Nov 21 '05 #6

Coleen,

I am really confused by you, do you want a "compute" the sum of a vertical
column or an expression to get the sum of horizontal items in a rows?

Datatable.Compu te
http://msdn.microsoft.com/library/de...mputetopic.asp

And what you are using in my opinion.
Datacolumn.Expr ession
http://msdn.microsoft.com/library/de...ssiontopic.asp

What is it you want?

Cor

Cor
Nov 21 '05 #7
Thanks Cor :-)

I want to get the grand total (sum) of one column (not row) Then I need to take that grand total and divide each row of the column by the grand total in order to get percentage rate. This is done In MS Excel as:

Column A Column B

row 1 100 =100/600 (Column A Row 1/Column A Total)

row 2 200 =200/600 (Column A Row 1/Column A Total)

row 3 300 =300/600 (Column A Row 1/Column A Total)

Total 600

I need to get the value of "600" into a variable that I can use to divide each row for column A by. Does that Make a little more sense? I ended up creating two datagrids. One that does all the calculations up to the grand total that I need (column A) and I created a variable to store the total for Column A "600" in after I did the databind on the first datagrid. In the second datagrid I took the grand total from Column A "600" and used it in my second datagrid to divide the values from each row in Column A with. Since each row in column A has a variable associated with it (I know there will always be 17 rows of data) I created 17 separate variables for each row in datagrid 1 and use those variables divided by the grand total (Total Column A - "600") from datagrid 1 as available in datagrid 2. Now I hide both datagrids and populate an html table with the values from datagrid1 and datagrid 2 to display to the user. Not simple, not pretty, but it works.

If there is an easier way to get percentage rates from a calculated value for each row, I'd love to know about it...

Thanks - I hope you understand what I was trying to do. This type of calculation is EXTREMELY easy in Excel, but when you have to do all the work that Excel does for you automatically, it is VERY difficult.

Coleen

"Cor Ligthert" <no**********@p lanet.nl> wrote in message news:e1******** *****@TK2MSFTNG P11.phx.gbl...

Coleen,

I am really confused by you, do you want a "compute" the sum of a vertical
column or an expression to get the sum of horizontal items in a rows?

Datatable.Compu te
http://msdn.microsoft.com/library/de...mputetopic.asp

And what you are using in my opinion.
Datacolumn.Expr ession
http://msdn.microsoft.com/library/de...ssiontopic.asp

What is it you want?

Cor



Cor

Nov 21 '05 #8
On 2004-08-14, Coleen <co**********@y aho.com> wrote:
This is a multi-part message in MIME format.

------=_NextPart_000_ 0008_01C48157.E 7166940
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Thanks Cor :-)

I want to get the grand total (sum) of one column (not row) Then I need =
to take that grand total and divide each row of the column by the grand =
total in order to get percentage rate. This is done In MS Excel as:

Column A Column B

row 1 100 =3D100/600 (Column A Row 1/Column A Total)

row 2 200 =3D200/600 (Column A Row 1/Column A Total)

row 3 300 =3D300/600 (Column A Row 1/Column A Total)

Total 600=20

I need to get the value of "600" into a variable that I can use to =
divide each row for column A by. Does that Make a little more sense? I =
ended up creating two datagrids.


DataTable1.Colu mns.Add("Column APercentage", _
GetType(Decimal ), _
"ColumnA/SUM(ColumnA)")

Is that what you're after? This would give you a new column of:

16%
33%
50%

(assuming you format as percentages).

Nov 21 '05 #9
Coleen,

Can you try this extremely easy sample, a new project a datagrid and than
run.

I (think) hope this helps?

Cor

\\\
Private Sub Form1_Load(ByVa l sender As _
Object, ByVal e As System.EventArg s) _
Handles MyBase.Load
Dim dt As New DataTable("Cole en")
dt.Columns.Add( "Fig", GetType(System. Int32))
dt.Columns.Add( "Perc", GetType(System. Int32))
For i As Integer = 0 To 5
Dim dr As DataRow = dt.NewRow
dr(0) = i + 1
dt.Rows.Add(dr)
Next
Dim dr2 As DataRow = dt.NewRow
Dim sum As Integer = _
CInt(dt.Compute ("Sum(Fig)", ""))
dr2(0) = sum
dt.Rows.Add(dr2 )
dt.Columns(1).E xpression = _
"Fig * 100/ " & sum.ToString
DataGrid1.DataS ource = dt
End Sub
///
Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2807
by: The Plankmeister | last post by:
Hi... I'm trying my hardest to understand fully how sessions work and how best to use them. However, all I can find is information that doesn't tell me anything other than that sessions store information between pages, which I knew already. I want to know HOW sessions work! If anybody has any good links to material that explains sessions fully, then please send those links this way! I'm particularly interested in the...
2
12852
by: Wired Earp | last post by:
I don't get it. First of all, it claims to run on a JRE. This is obviously a fraud, it even says so when you attempt to start it: "The JAVA_HOME variable should point to a JDK and not a JRE". I can accept that, being new to it all and not really caring, but things are going downhill rather fast from here. I'm installing a simple webapp in the the the webapps folder, complete with a context.xml in the conf folder. My servlet behaves just as...
3
2024
by: The Plankmeister | last post by:
Hi... I'm attempting to keep everything I write compliant with xhtml 1.0 strict. And It's very bizarre. Why on earth won't this validate: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head>
1
3307
by: Jim Moe | last post by:
Hello, I am (slowly) in the process of changing a table-based layout to CSS/div-based. One area that uses tables a lot is the main nav menu. I have discovered that tables have advantage: all browsers display them the same. I created a CSS to use <ul> as the list container rather than <table>. It works quite well -- in Mozilla. With IE V5 or 6 extra spacing is added between each button image and the large spaces are compressed; it is...
1
829
by: Henry Rollins | last post by:
This is driving me nuts. I have created a Class Assembly in .NET C# which is to be used by traditional ASP pages. I registered it just fine with the regASM command and it work - about 2/3 of the time. The rest of the time I launch the site and the following error is generated: '80070002'
1
1886
by: Cliff Williams | last post by:
How are people managing multiple, interdependent projects in the same solution? If I have to rebuild my solution file one more time, I think my head is going to spin around and pop off. I've seen tools like Nant around, but it seems to have a pretty big learning curve. Is it easier than I think? How does it integrate with debugging? Are there other tools? BTW, I've read dozens of posts describing similar problems along with the...
0
1236
by: Toby Mathews | last post by:
Hi there, I have a problem with a C# AP.NET app. running on my local machine, Sporadically (but more and more frequently) I get the above error message when code running on my laptop trys to connect to our SQL Server, which is located elsewhere. The same code NEVER does this on our development and live machines (both of which are in the same hosting facility as the SQL Server), and other app's that I write/run locally, and that connect...
1
1484
by: RWC | last post by:
Hi Folks, I have a windows 2000 server installation, IIS is running and the ASP.NET 1.1 SDK has been installed. I'm reading a book on ASP.NET and the lessons call for the first line to read <%@ Page Language="VB"%>. When I save the page and run it (from a remote machine) I get the following message; "The scripting language 'VB' is not found on the server." I haven't been able to find ANY other solution. When I type this into
2
3911
by: SorceCode | last post by:
Hey guys, good old > Debug Assertion Failed! > File: dbgdel.cpp > Line: 47 > Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) Rears its ugly head agian! Ok heres what Im up to..
6
5046
by: darrel | last post by:
I'm using some validators for a form. I'm noticing that it writes the text out to the browser as a SPAN with it's visibility set to none. The problem is that it still takes up space, so I have gigantic gaps in my form. It SHOULD be set to display: none instead. Is this a setting in the control somewhere or is this just a huge oversight on MS's part? If the latter, any suggestions for a workaround? Perhaps wrapping the validator in a...
0
7985
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7896
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8389
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8048
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6713
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5438
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3939
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1246
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.