Solved

Dealing with Issues in VB

Posted on 2003-12-05
13
451 Views
Last Modified: 2010-05-01
Hello All,

I am new to VB so if I don't say the right word(s) or phrases, please forgive my ignorance as I am learning.  I have a small project due in the next week using VB 6.0 , I seem to have an OK grasp on the interface, its more so the code that I ponder.  I have 3 VB books that are for VB Beginners but they deal very little with what I need my app to do.  

I Need to:

Create a report form that will do the following:

1)  Allow me to monitor tasks vis-a-vis time stamping
2)  Allow me to run a difference or comparison statement between two timed intervals
3)  Allow me to write all my results real-time and be able to remove entries that are in cache
4)  Run a splash screen at the beginning of the app.

What I have accomplished:
1)  Created forms
2)  Created Splash Screen
3)  Created Access dBase w/ Relationships (where applicable)

The Sticking points

1) Ok....  I need to compare two timed intervals, since there is no "stopwatch" type of code readily available, I need to DIFF or compare the time when the record was created to the time I stop the stopwatch.  The timer is started when I select a task, I have to manually end the taks for the second and final time stamp.   Then the difference of the two times will be displayed in a text box.  Does this sound like fun yet?

2)  Be able to create a form that shows all assignments not ended.  Meaning, I can add 100 tasks, but until I manually hit the end key the "clock" keeps ticking.

3)  I wrote a module for the Splash Screen form,when I hit run to start the object, it just runs one of the other forms.  I am not sureif the splash should be running.

Anyhelp would be greatly appreciated.  

Fusionite....

0
Comment
Question by:Fusionite
  • 9
  • 4
13 Comments
 
LVL 5

Expert Comment

by:mccainz2
ID: 9885418
for the time difference

    MsgBox Hour(time2 - time1) & ":" & Minute(time2 - time1) & ":" & Second(time2 - time1)

0
 
LVL 5

Expert Comment

by:mccainz2
ID: 9885438
for part 3 in your development envirnoment  go to the project menu item, choose properties .... in the popup should be a dropdown in which you can select the startup object
0
 
LVL 5

Expert Comment

by:mccainz2
ID: 9885837
and for part 2 , this is a demp app , fully functional but no error handling or data validation etc... which allows you to add tasks, stop tasks, and show all completed with the time it took to complete each task...
Use as a framework for your application ...

Uses 5 command buttons , a listbox , and a textbox

Private Type TASK
    tstart As Date
    tend As Date
    completed As Boolean
    title As String
End Type

Dim tasks() As TASK

Dim time1 As Date
Dim time2 As Date

Private Sub CmdAddTask_Click()

    Dim sTask As String
    Dim localTask As TASK
   
    sTask = InputBox("Enter Task Name", "Task Name")
   
    listTasks.AddItem sTask
   
    With localTask
        .completed = False
        .tend = 0
        .title = sTask
        .tstart = Time
    End With
   
    ReDim Preserve tasks(UBound(tasks) + 1)
    tasks(UBound(tasks)) = localTask
   
End Sub
Private Sub cmdStop_Click()
   
    For i = 0 To listTasks.ListCount - 1
        If listTasks.Selected(i) = True Then
            sTask = listTasks.List(i)
        End If
    Next i
   
    For i = 1 To UBound(tasks)
        If tasks(i).title = sTask Then
            With tasks(i)
                .completed = True
                .tend = Time
            End With
        End If
    Next
   
End Sub

Private Function timeDiff(time1 As Date, time2 As Date) As String
    timeDiff = Hour(time2 - time1) & ":" & Minute(time2 - time1) & ":" & Second(time2 - time1)
End Function


Private Sub cmdShowFinished_Click()
    txtCompleted.Text = ""
    For i = 1 To UBound(tasks)
        If tasks(i).completed = True Then
            txtCompleted.Text = txtCompleted.Text & tasks(i).title & " " & timeDiff(tasks(i).tend, tasks(i).tstart) & vbCrLf
        End If
    Next
End Sub

Private Sub Form_Load()
    ReDim tasks(0)
End Sub
0
 

Author Comment

by:Fusionite
ID: 9888500
mccainz2

There is no doubt you've earned the points!  What is a demp app(Forgive me i'm new)?  Do I separate each into the properties of each command button or does it go into one form?    What would be a good VB book or website I should visit to get up to speed.

I have 3 books that give sparse information on how to complete an application from start to finish

More Visual Basic 6.0 in 21 Days
Learn Visual Basic 6.0 Now
Beginning Visual Basic

Your thoughts on these????  Any other you may know that are better???

 I am a webmaster by trade and have dealt very little with VB, could you please review my profile and feel free to email me directly.  Your help so far has been the most insightful and I can't thank you enough for lending a hand!!!  

Fusionite
0
 
LVL 5

Expert Comment

by:mccainz2
ID: 9888663
Sorry , typo , meant demo (demonstration) app

All of this code goes into one form ....

when you see a sub with a declaration like 'Private Sub cmdShowFinished_Click()'
then that tells you that the code in that sub handles the CLICK event for a command button named cmdShow ...

In general the WROX books and Microsoft press books are my favorites on VB.
Of those books youve listed the only one I'm familiar with is the '21' days book (is that SAMMS publishing)?
Probably all fine books for an intorduction , I'd also suggest searching the web for basic tutorials etc...

To play around with the above app

1.Create a new project (with a single form)
2. Add 5 buttons , a listbox (drag its dimensions fairly wide), and a textbox (set its multiline property = true and drag it large also)
3. Modify the names of your controls to reflect the names in the code (add captions to reflect their usage)


listbox name = listTasks
textbox name =txtCompleted

Once youve got that working put stops in your IDE on each sub or function declaration , next time you run the app you will be able to stepthrough the code behind each control as you click the buttons etc ....

To put a 'Stop' in your code
In the Pane with your code you wil notice that there is about a 1/4 inch wide grey margin on the left side of the pane . Click on this with your mouse (on the same line as one of the sub declarations) and you should see a red circle appear in the margin and all the code on that line should also be highlighted red....When your program runs and that line of code is reached  , control will return from the program to the IDE and you can use the F8 key to step through your code line by line ... THis is a great way to learn what the code is doing and possibly what bugs may exist....Also, while in this mode , hovering your mouse over a variable will show you its current value...
0
 

Author Comment

by:Fusionite
ID: 9896372
Ok... works good, but, I created 5 commands button and only see 3 "click" commands am I missing something here????   Heres what I see:  

Private Sub CmdAddTask_Click()
Private Sub cmdStop_Click()
Private Sub cmdShowFinished_Click()

1)Creates a task and starts time
2)Stops the task time
3)Shows the task and time in text field
 
Is there a way I can list all tasks even if the time hasn't stopped on the event?  I need to be able to list these commands and stop them at will.  

Thanks,
Fusionite....
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Expert Comment

by:mccainz2
ID: 9896503
(Item 1)

In your development environment at the top of your code pane should be 2 dropdown lists ...

the one on the left holds all the controls on your form , the form itself , and the general area...
Select your command button control from this list and then dropdown the list to the right , it holds all the events for your control .... clicking on one of these will result in the code declaration for that event being added to your form...

(item 2)

to show all tasks only requires a simple modification of the function for showing completed tasks ...

Private Sub cmdShowFinished_Click()
    txtCompleted.Text = ""
    For i = 1 To UBound(tasks)
        If tasks(i).completed = True Then '<------REMOVE this IF statement to show ALL tasks
            txtCompleted.Text = txtCompleted.Text & tasks(i).title & " " & timeDiff(tasks(i).tend, tasks(i).tstart) & vbCrLf
        End If
    Next
End Sub

so...

Private Sub cmdShowFinished_Click()
    txtCompleted.Text = ""
    For i = 1 To UBound(tasks)
                 txtCompleted.Text = txtCompleted.Text & tasks(i).title & " " & timeDiff(tasks(i).tend, tasks(i).tstart) & vbCrLf
    Next
End Sub
0
 
LVL 5

Expert Comment

by:mccainz2
ID: 9896509
BTW: for all tasks no reason to call that time function so...

For i = 1 To UBound(tasks)
                 txtCompleted.Text = txtCompleted.Text & tasks(i).title & vbcrlf
    Next
0
 

Author Comment

by:Fusionite
ID: 9896606
I guess then it safe to assume that the task list gets bigger yet until I hit the stop function and actually select the task itself it stays resident?  Am I correct in this assumption?  If so, I guess the logical progression is writing this information to a spreadsheet or dbase.

I guess I was thinking about this a little differently, I wanted this to be somewhat like quicken so when you added an item to say a check register you could see all the the items line up in order and manually click on each to close them out.  Just a thought..... This is practical enough for what it needs to do.   I didnt realize that all the tasks just listed themselves in the drop down menu.

The only issue is to avoid redundancy, I would need the task list not to be able to add duplicate items if they are already being worked on.  Just a thought.....  I appreciate the insight...

Also need to find some icons for the buttons, the boss likes buttons.

Fusionite....
0
 
LVL 5

Expert Comment

by:mccainz2
ID: 9896671
For your final program I'd use a Msflexgrid control for your task display ...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mshflx98/html/vbctlMSFlexGridControl.asp


Saving data could be done to a flatfile,access database,excel spreadsheet is an excellent idea and using the last two options would introduce you to ADO which is the bread and butter of anyone writing VB apps with data access

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/adostartpage1.asp


I'm sure as a webmaster you are already familiar with plenty of sites offering free button images...

http://www.freebuttons.com/

alternately you could use an image editing program to create your own...
0
 
LVL 5

Accepted Solution

by:
mccainz2 earned 500 total points
ID: 9896683
BTW: utilize MSDN , most questions I see answered on EE have solutions at msdn.microsoft.com if you are willing to hunt a little bit ....


0
 

Author Comment

by:Fusionite
ID: 9896748
Well, I appreciate your help.  I will need to take it from here.... I have a lot to learn in a short-period of time, I will post back the final result.  I think the msflexgrid is the way for me to go in the short term.  I do have the msdn library cds and can get to it on the web.  

Can you give me the names of the books you read on VB?  

Any good websites would be great.

Thanks for all your help, very insightful.  Here begins my journey... Where to next??????

Fusionite.... Changing my name to VBnite....

0
 
LVL 5

Expert Comment

by:mccainz2
ID: 9896810
Let me round up my fav books and I will list em here with the amazon link ...

I'll do the same (minus the amazon link :) ) for the websites

Feel free to post in this thread with anymore questions on this project ... 500 points buys you a lot IMHO on EE and I definitely want you to feel that this site is worth your time and effort...

If you master this project with ADO and flexgrids then you are well on your way !

Gimme a few hours and I'll post the list , gotta earn my daily bread here for a few ( I much prefer solving problems on EE)

BTW: My experience on learning VB is that after you have the basics down come here and try to solve every question you can! At first the time it takes you to research the problem will mean you probly wont post a solution in time to get the points ... however you will learn SO MUCH MORE than books can teach ...
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

757 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now