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 1933
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.
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
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(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
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...
|
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...
|
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?
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |