473,397 Members | 1,974 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,397 software developers and data experts.

Array Question: Dynamic Monthly Column Headings

I'm not that familiar with arrays so I'll try to explain my problem as clear as possible. I have 2 text boxes in VB where users are basically allowed to choose a date range up to 12 months. The format of the text boxes are "mm/dd/yyyy". So a user could choose to display data from 01/01/2007 to 12/01/2007. Or 07/01/2007 to 10/01/2007. Then I want the data to display under monthly column headings. My problem is due to the fact that the number of columns could change each time, so it will never be fixed . Thus, I'm having a problem creating an array with a loop to determine the first and last month choice, and fill in the months between.

The VB form is linked to a SQL database, so it is pulling the monthly data from this table. Just to give you an example, here is what column headings I would like to display if a user selects a date range of 01/01/2007 to 04/01/2007:

200701 —- 200702 —- 200703 —- 200704

I really don't need any SQL coding to accomplish this, I'm just not sure how to use the array and loop to populate these column headings. Thanks!
Aug 31 '07 #1
4 1933
kadghar
1,295 Expert 1GB
check out the month and year functions, to create an array with the titles you want, if the initial date is in Date1 and the ending date is in Date2 just do something like this

Expand|Select|Wrap|Line Numbers
  1. dim namArray() as string
  2. n = 12 * (year(date2) - year(date1)) + month(date2) - month(date1) +1
  3. redim namarray(1 to n)
  4. n=1
  5. dateTmp = date1
  6. do
  7.     namarray(n) = month(datetmp) & "-" & year(datetmp)
  8.     datetmp = dateadd("m",1,datetmp)
  9.     n=n+1
  10.     if datetmp > date2 then exit do
  11. loop
hope that helps
Aug 31 '07 #2
Thanks for your reply. I'm sorry, I've been trying to understand each line of your code but I seem to having some problems. Could you possibly add some comments so I can decode what some of the lines mean? Thank you so much.
Aug 31 '07 #3
kadghar
1,295 Expert 1GB
Thanks for your reply. I'm sorry, I've been trying to understand each line of your code but I seem to having some problems. Could you possibly add some comments so I can decode what some of the lines mean? Thank you so much.
sure
Expand|Select|Wrap|Line Numbers
  1. dim namArray() as string 'Define an array of strings
  2. n = 12 * (year(date2) - year(date1)) + month(date2) - month(date1) +1
  3. redim namarray(1 to n) 'here I put the dimension of the array
  4. 'Year(date) gives you back an integer with the year of the date
  5. 'month(date) gives you back an integer betwen 1 and 12 
  6. n=1 'start a counter called n
  7. dim dateTmp as date
  8. dateTmp = date1  'create a dummy, i should have defined it first (done!)
  9. 'and now that dummy is the starting date
  10. do  'start a loop
  11.     namarray(n) = month(datetmp) & "-" & year(datetmp)  'add the n'th element to the array with the month and year of the dummy date
  12.     datetmp = dateadd("m",1,datetmp) 'add one month to the dummy date
  13.     n=n+1'increase the counter
  14.     if datetmp > date2 then exit do 'if the dummy date is greater than the finishing date then i exit the loop
  15. loop 'close the loop
Aug 31 '07 #4
QVeen72
1,445 Expert 1GB
Hi,

Check This :

Expand|Select|Wrap|Line Numbers
  1. Dim TDate As Date
  2. TDate =CDate(txtFromDate.Text)
  3. List1.Clear
  4. Do
  5.  List1.AddItem Format(TDate ,"YYYYMM"
  6.  TDate = DateAdd("m", 1 , TDate)
  7. Loop Until TDate>=CDate(txtToDate.Text)
  8.  
Start with the First Date(txtFromDate), Add One Month and keep on Repeating till u reach the Last Date. Change the "List1.AddItem", to populate ur Grid Column/ Array..

REgards
Veena
Sep 2 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Me | last post by:
Hi all, I have an app in which I need to create a packing slip. I have designed in report designer. The data is pulled from a SQL database. My question is how can I put information from the...
4
by: Thomas Jerkins | last post by:
When I write a create table SQL statement I want to add some information about the column heading of each column. How does the exact syntax for the create table look like (which includes this column...
9
by: Dave H | last post by:
Hello, I have a query regarding definition lists. Is it good practice semantically to use the dt and dd elements to mark up questions and answers in a frequently asked questions list, or FAQ? ...
7
by: Tom | last post by:
PHP Gurus... Can anyone give me a helping hand with this. I'm more ASP, but trying to move to PHP and sturggling a bit. I have a few products stored in a csv file created in Excel. Column 1...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
3
by: PeterZ | last post by:
Hi, In a running C# app with a datagrid control I select all rows in the dataGrid using CTRL-A, I then paste into some other app like notepad or Word but the column headings get left off. Is...
4
by: deejayquai | last post by:
I've worked through the MS KB example and it doesn't really help me as I missing the basics of what the code is doing. I've posted a couple of times here in thsi group but with no success. Could...
1
by: Peterwkc | last post by:
Hello all expert, i have two program which make me desperate bu after i have noticed the forum, my future is become brightness back. By the way, my problem is like this i the first program was...
5
by: Stephen3776 | last post by:
I am doing an inventory control progam and trying to output a multiple array, I am getting an illegal conversion error java.lang.double !d. Can somebody tell me what I am doing wrong or if there is...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
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
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...
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.