473,804 Members | 3,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array Question: Dynamic Monthly Column Headings

28 New Member
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 1948
kadghar
1,295 Recognized Expert Top Contributor
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
nico3334
28 New Member
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 Recognized Expert Top Contributor
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 Recognized Expert Top Contributor
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(txtFromDat e), 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
7253
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 data base into the Page Header? The way I have it setup right now the PageHeader contains the logo, title, address. All of which are fine. Then under that I need to put the ship to and bill to addresses, which are pulled from the data base. Then...
4
21352
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 data look)? How do I add later column headings ? Tom
9
3754
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? Here is an example of just such a usage: <dl class="faq"> <di>
7
20657
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 is the part #, column 2 is title, column 3 is color, column 4 is width and 5 is price.
1
17684
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 Create a Dynamic Crosstab Report PRODUCT :Microsoft Access PROD/VER:1.00 1.10 OPER/SYS:WINDOWS
3
4870
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 there any way of including column headings when copying/pasting from a running datagrid to notepad? At this stage it looks like I have to write my own code but would rather not if someone knows how to do it.
4
2462
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 anyone recommend a book or a website that goes through the basics of how to build dynamic crosstab queries in order to create reports that allows column fields to dynamicaly change according to the source data? Regards David, UK
1
7979
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 compiled and run without any erros but the second program has a run time error when the function return from allocate and the ptr become NULL. How to fixed this? Second Program: /* Best Method to allocate memory for 2D Array because it's ...
5
2511
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 another way? /* * Main.java * * Created on April 29, 2007, 6:57 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */
0
9706
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
9582
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
10580
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...
0
10335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9157
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
6854
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
5652
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
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
2
3821
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.