473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Loading data in tables - Again :-(

EEEK! I have eight columns and 18 rows in a table. I need to populate the table and run calculations on four of the columns andfor totals in a footer. Here is some of the code I am using to populate my table
Dim ls_county, ls_gas, ls_gasohol, ls_tot_gal, ls_cty_rate, ls_st_rate As Strin
Dim ls_sum_gas, ls_sum_gasohol, ls_sum_tot_gas, ls_sum_cty_tax, ls_sum_st_tax As Strin

Function calc_gallons(
I have to do this set of code for 17 rows! Any suggestion on how to do it easier? Can I do a for/Next loop? I need to make sure that the variables go into the correct column/row(cell) so I don't know that there is any way around doing code of this sort for all 8 columns and all 17 rows..
ls_gas = CInt(tbl_worksheet1.Rows(1).Cells(1).Text
ls_gasohol = CInt(tbl_worksheet1.Rows(1).Cells(2).Text
ls_tot_gal = CInt(ls_gas) + CInt(ls_gasohol
tbl_worksheet1.Rows(1).Cells(3).Text = ls_tot_ga

This set of code is only set to return the total for the first row into row 18 - I need to SUM all 17 rows for each column in the last row as overall totals... I'm terrible at For/Next - any suggestions
ls_sum_gas = CInt(ls_gas
tbl_worksheet1.Rows(18).Cells(1).Text() = ls_sum_ga

End Functio

Thanks - I need all the help I can get :-

Coleen

---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
Nov 20 '05 #1
5 994
Hi Coleen,

Change the function; pass in the column name or ordinal number and then make
the function more generic, doing the calc for each of the passed in cols.

Summing the rows should be trivial - pass that back also. BTW, if you pass
variables into the function byref, they will return the changed value.

HTH,

Bernie Yaeger

<coleenholley> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
EEEK! I have eight columns and 18 rows in a table. I need to populate the table and run calculations on four of the columns andfor totals in a
footer. Here is some of the code I am using to populate my table: Dim ls_county, ls_gas, ls_gasohol, ls_tot_gal, ls_cty_rate, ls_st_rate As String Dim ls_sum_gas, ls_sum_gasohol, ls_sum_tot_gas, ls_sum_cty_tax, ls_sum_st_tax As String
Function calc_gallons()
I have to do this set of code for 17 rows! Any suggestion on how to do it easier? Can I do a for/Next loop? I need to make sure that the variables
go into the correct column/row(cell) so I don't know that there is any way
around doing code of this sort for all 8 columns and all 17 rows... ls_gas = CInt(tbl_worksheet1.Rows(1).Cells(1).Text)
ls_gasohol = CInt(tbl_worksheet1.Rows(1).Cells(2).Text)
ls_tot_gal = CInt(ls_gas) + CInt(ls_gasohol)
tbl_worksheet1.Rows(1).Cells(3).Text = ls_tot_gal

This set of code is only set to return the total for the first row into row 18 - I need to SUM all 17 rows for each column in the last row as
overall totals... I'm terrible at For/Next - any suggestions? ls_sum_gas = CInt(ls_gas)
tbl_worksheet1.Rows(18).Cells(1).Text() = ls_sum_gas

End Function

Thanks - I need all the help I can get :-)

Coleen

---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest

Community Website: http://www.dotnetjunkies.com/newsgroups/
Nov 20 '05 #2
Cor
Hi Coleen,

You mean something as?
\\\
dim i as integer
dim y as integer
For i = 0 to 17
for y = 0 to 7
tbl_worksheet.rows(17)(y)=tbl_worksheet.rows(i)(y)
next
next
///
the rowindex starts at 0 so row 18 is 17
It has all to be numeric of course otherwise you have to test that

I hope this helps,

Cor
EEEK! I have eight columns and 18 rows in a table. I need to populate the table and run calculations on four of the columns andfor totals in a
footer. Here is some of the code I am using to populate my table: Dim ls_county, ls_gas, ls_gasohol, ls_tot_gal, ls_cty_rate, ls_st_rate As String Dim ls_sum_gas, ls_sum_gasohol, ls_sum_tot_gas, ls_sum_cty_tax, ls_sum_st_tax As String
Function calc_gallons()
I have to do this set of code for 17 rows! Any suggestion on how to do it easier? Can I do a for/Next loop? I need to make sure that the variables
go into the correct column/row(cell) so I don't know that there is any way
around doing code of this sort for all 8 columns and all 17 rows... ls_gas = CInt(tbl_worksheet1.Rows(1).Cells(1).Text)
ls_gasohol = CInt(tbl_worksheet1.Rows(1).Cells(2).Text)
ls_tot_gal = CInt(ls_gas) + CInt(ls_gasohol)
tbl_worksheet1.Rows(1).Cells(3).Text = ls_tot_gal

This set of code is only set to return the total for the first row into row 18 - I need to SUM all 17 rows for each column in the last row as
overall totals... I'm terrible at For/Next - any suggestions? ls_sum_gas = CInt(ls_gas)
tbl_worksheet1.Rows(18).Cells(1).Text() = ls_sum_gas

Nov 20 '05 #3
Thanks - actually, I got that far:

For i = 1 To 17
ls_tot_gal = CInt(ls_gas) + CInt(ls_gasohol)
ls_sum_tot_gas = ls_sum_tot_gas + CInt(ls_tot_gal)

tbl_worksheet1.Rows(i).Cells(3).Text() = ls_tot_gal
Next i
tbl_worksheet1.Rows(i).Cells(3).Text() = ls_sum_tot_gas

The problem I am having is that I need my calculations to go both across and down. The calculations do run for both, but the calculations across which is

ls_sum_tot_gas = ls_sum_tot_gas + CInt(ls_tot_gal)

don't add up each individual line...it adds the amount from tbl_worksheet1.Rows(1).Cells(1) +
tbl_worksheet1.Rows(1).Cells(2) and puts that value in EVERY row total. Each row has a different value and needs to be calculated. The sum total at the bottom is working great- it takes ALL the values (which in this case is 14500) and adds them up to grand total of 246500. Any suggestions on how to get the totals for each row to calculate properly? TIA - Coleen
---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
Nov 20 '05 #4
You mean something like this?

ls_gas = CInt(tbl_worksheet1.Rows(1).Cells(1).Text)
ls_gasohol = CInt(tbl_worksheet1.Rows(1).Cells(2).Text)

For i = 1 To 17
ls_tot_gal = CInt(ls_gas) + CInt(ls_gasohol)
ls_sum_tot_gas = ls_sum_tot_gas + CInt(ls_tot_gal)

tbl_worksheet1.Rows(i).Cells(3).Text() = ls_tot_gal
Next j
tbl_worksheet1.Rows(i).Cells(3).Text() = ls_sum_tot_gas

only using cell names instead of integers? I guess I'm not quite sure what you mean - could you please give me an example? Thanks very much :-) Coleen

---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
Nov 20 '05 #5
Cor
Hi Colleen,

Although there was a time that I was also working in oil, I dont have to do
with that, so I keep it with indexes.

I take my original sample and add one row.

\\\
dim i as integer
dim y as integer
For i = 0 to 17
for y = 1 to 6
tbl_worksheet.rows(17)(y)=tbl_worksheet.rows(i)(y)
tb_workstheer.rows(i)(0)=tbl_worksheet.rows(i)(y)
next
next
///
This adds all items horizontaly into the first column
This adds all items inclusieve the first verticaly into the last row

(I did not check it)

I think you should give it a try.

Cor

Nov 20 '05 #6

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

Similar topics

32
by: Neil Ginsberg | last post by:
We're using SQL Server 7 with an Access 2000 MDB as a front end with ODBC linked tables. I recently created a new set of tables for the app, and users are complaining that unsaved data is being...
3
by: Steven | last post by:
I am new to DB2 databases in general and I can't be the only one with this problem and was looking for a best practice. I need to make nightly data feeds from another system. I was using an...
5
by: Olaf Gschweng | last post by:
We're new into DB2 and have some problem with DB2 8.1 (?) on a Linux system. We load some big tables of a DB2 database from files every day. We do a "DELETE FROM table" for each table and then we...
4
by: Bill Stock | last post by:
The few times in the past that I've loaded unbound data, I've tended to cheat and use temp tables (not really unbound) or use code for small datasets. I'm currently involved in a project that...
5
by: John Richardson | last post by:
I've been bothered for some time about my DataGrid not populating my rows very quickly. I have about 10K rows loading into the grid. I create a datatable dt with 2 columns, an ID and a display. ...
4
by: John | last post by:
Hi all, I'm having a little problem understanding the concepts of dynamically loading/unloading user conrols: 1. If I have a couple of usercontrols embedded within a few tables cells on my...
2
by: Eddy | last post by:
Hello, I've an XML file loaded into a dataset. It works fine, but some values i can't load. For example, <incidentid> is working fine, but <subjectid> is an issue, because it has a name and dsc...
4
by: Khurram | last post by:
Hi, I understand in order to extract data from the tables in a Dataset and setting it to control, the following csharp syntax applies. textBox1.Text = northwindDataSet.Customers.ContactName; ...
7
by: koonda | last post by:
Hi guys, I am trying to create a web interface in C# using ASP.NET. The database being used is SQL Server. I have some problems loading the tables in the datalist controls. When I run the program...
1
by: hvellani | last post by:
Okay here is my problem... I have multiple csv files with data in each file. They are connected via foreign keys (with each table having its on primary key). I want to load these tables into an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.