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!
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 - dim namArray() as string
-
n = 12 * (year(date2) - year(date1)) + month(date2) - month(date1) +1
-
redim namarray(1 to n)
-
n=1
-
dateTmp = date1
-
do
-
namarray(n) = month(datetmp) & "-" & year(datetmp)
-
datetmp = dateadd("m",1,datetmp)
-
n=n+1
-
if datetmp > date2 then exit do
-
loop
hope that helps
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.
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 -
dim namArray() as string 'Define an array of strings
-
n = 12 * (year(date2) - year(date1)) + month(date2) - month(date1) +1
-
redim namarray(1 to n) 'here I put the dimension of the array
-
'Year(date) gives you back an integer with the year of the date
-
'month(date) gives you back an integer betwen 1 and 12
-
n=1 'start a counter called n
-
dim dateTmp as date
-
dateTmp = date1 'create a dummy, i should have defined it first (done!)
-
'and now that dummy is the starting date
-
do 'start a loop
-
namarray(n) = month(datetmp) & "-" & year(datetmp) 'add the n'th element to the array with the month and year of the dummy date
-
datetmp = dateadd("m",1,datetmp) 'add one month to the dummy date
-
n=n+1'increase the counter
-
if datetmp > date2 then exit do 'if the dummy date is greater than the finishing date then i exit the loop
-
loop 'close the loop
QVeen72 1,445
Recognized Expert Top Contributor
Hi,
Check This : -
Dim TDate As Date
-
TDate =CDate(txtFromDate.Text)
-
List1.Clear
-
Do
-
List1.AddItem Format(TDate ,"YYYYMM"
-
TDate = DateAdd("m", 1 , TDate)
-
Loop Until TDate>=CDate(txtToDate.Text)
-
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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
|
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>
|
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.
|
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
| |
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.
|
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
|
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
...
|
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.
*/
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |