?
Solved

Need help with the MSFlexgrid question

Posted on 2005-04-11
10
Medium Priority
?
153 Views
Last Modified: 2010-05-02
I have a MSFlexgrid, which is bringing in data in this fashion:
Field1               Field2             Field3
______________________________________________
9:30am            Truck 1            Hay
10:00am          Truck 2            Wire
11:30am          Truck 3            Fibre
2:30pm            Truck 4            Hay
4:00pm            Truck 5            Wire
etc....(other various entries till 11:00pm)
----------------------------------------------------------------
data will always have a "time" field (in character) in the format you see
and times will always be in :30 minute incraments.
After the data comes into the grid, I need to add the times that are ABSENT to the grid.
The times in total must be from 7:00am to 11:00 pm in :30 min incraments.
So the grid must look like this:
Field1               Field2             Field3
______________________________________________
7:00am
7:30am
8:00am
8:30am
9:00am
9:30am            Truck 1            Hay
10:00am          Truck 2            Wire
10:30am
11:00am
11:30am          Truck 3            Fibre
12:00pm
12:30pm
1:00pm
1:30pm
2:00p.
2:30pm            Truck 4            Hay
3:00pm
3:30pm
4:00pm            Truck 5            Wire
4:30pm
etc....all the way to 11:00pm
----------------------------------------------------------------
after the grid is first populated with the data shown at the top,
what code will fill in the blank entries into my grid.?
0
Comment
Question by:yyuubum2
  • 3
  • 3
  • 2
8 Comments
 
LVL 6

Expert Comment

by:PePi
ID: 13754841
try this:

since your time is constant (from 7:00am to 11:00pm in 30 minutes increments) you will have a total of 33 rows always (excluding the heading on the grid ig you have any). So i guess you already have your grid setup to have 33 rows (flexgrid.Rows = 33 or flexgrid.Rows = 34 if you have a header row)

dim hr as integer, min as integer, i as integer
dim s as string

hr = 7: min = 0: s = "am"
with flexgrid
    for i = 0 to 32              
        'assuming time is at column 0  
        .textmatrix(i, 0) = format(hr, "##") & ":" & format(min, "00") & s

        'reset the hour if it's after 12
        if hr = 12 and min = 30 then hr = 1

        'increment the hr
        if min = 30 and hr <> 1 then hr = hr + 1
        if hr = 12 then s = "pm"

        'toggle min
        if min = 0 then min = 30 else: min = 0
    next i
end with



HTH!


0
 
LVL 15

Expert Comment

by:unknown_routine
ID: 13754885
lets call. date variable is called Sdate

so the code for increment is like this:

Dim sdate As String

sdate = "4:00PM"
Do While CDate(sdate) < CDate("11:00pm")

sdate = CDate(sdate) + CDate("0:30")
MsgBox sdate 'take out this msgbox later
'....code to update flexgrid


Loop


End Sub
0
 
LVL 6

Expert Comment

by:PePi
ID: 13754998
oooops... change this:


        'reset the hour if it's after 12
        if hr = 12 and min = 30 then hr = 1

        'increment the hr
        if min = 30 and hr <> 1 then hr = hr + 1
        if hr = 12 then s = "pm"

       'toggle min
        if min = 0 then min = 30 else: min = 0

with this:

        'reset the hour if it's after 12
        If hr = 12 And min = 30 Then hr = 1: GoTo skip

        'increment the hr
        If min = 30 Then hr = hr + 1
        If hr = 12 Then s = "pm"

skip:
        'toggle min
        If min = 0 Then min = 30 Else: min = 0



0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:yyuubum2
ID: 13755135
both missed the mark perhaps because of my presentation,
in any case look at my example at the top.
I don't want to change the times of the original appointments.
I need to fill in the times that DON'T exist AROUND the ones that DO.

I start at 8:00am  in any case.
If I have 9:30am, 10:00am and 1:00pm for example
 then your routine has to insert:
 8:00am, 8:30am, 9:00am, 10:30am, 11:00am, 11:30am, 12:00pm, 12:30pm, 1:30pm  etc..
leaveing the original records intact.
??
0
 

Author Comment

by:yyuubum2
ID: 13755143
The records that your routine adds WILL BE BLANK records with
only the time in the first column.
0
 
LVL 15

Expert Comment

by:unknown_routine
ID: 13755682

this:


This can be done byu checking if a specefic cell is empty or not:


 Assuming times are in the 1st column as your example above:

Dim irow ,icol
Dim sdate As String
icol=0
irow=0


if trim(flexgrid.textmatrix(Irow+1))="" then

sdate =flexgrid.textmatrix(irow,0)
sdate = CDate(sdate) + CDate("0:30")
flexgrid.textmatrix(irow,icol+1)=sdate
end if
irow=irow+1
0
 

Author Comment

by:yyuubum2
ID: 13762575
Unkonwn Routine:
The grid has EVERY ROW POPULATED with it comes in.
There are no blanks in the first column, ever.
I guess I'm not being clear on what I need.
I don't know how else to state it.

0
 
LVL 6

Accepted Solution

by:
PePi earned 400 total points
ID: 13766807
Why not create your grid based on the time intervals first AND THEN populate your appointments. Humour me for a moment...

Here's what I suggest you should do...

Since you said in your first post that your day starts from 7:00am and ends at 11:00pm. Imagine that you had a full day and that you have appointments from 7:00am to 11:00pm. Following the scenario, you'll have a total of 33 rows representing 7:00am to 11:00pm at 30 minutes interval each with a corresponding appointment entry.

Now, you create a flexgrid with 33 rows and 3 columns, each row representing a 30 minute time block. You then populate the first column with your time intervals (i.e. 7:00am, 7:30am, 8:00am, etc...). Keep in mind that you have not put in any appointments yet. You just created the flexgrid with the time intervals first.

Next step, you get the data (whereever it is you are getting it from) and I am assuming that your data has the corresponding time of the appointment. Reading the first appointment record, you loop through the flexgrid and comparing the record's appointment time with the value of the first column of the flexgrid. Example, your first record contains 9:30am, Truck1, Hay. You then do a for next loop and comparing the value of the 1st column with 9:30am until you find the match. once you find the match, you put field number 2 to column 2 and field 3 to column 3 and then read the next record. hence, your grid will look like this:

Col1         Col2         Col3

7:00am
7:30am
8:00am
8:30am
9:00am
9:30am   Truck1     Hay
10:00am
10:30am
....


You do this until all records have been read.




0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month17 days, left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question