Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

losing variables between subs 1

Status
Not open for further replies.

hererxnl

Technical User
Jul 8, 2003
239
US

Someone help me out here. I'm trying to assign a variable to store the current time which is used repeatedly throughout my form for various calcs. I tried to assign it in the startup module of the prog but after the main form is loaded it's lost. Tried assigning it as a Public Const but the module didn't like me using Now() outside of a function/sub. Then tried declaring the value on For Load and it still is blank when a sub requests it. Help.

Most recent incarnation(not working):

Code:
Sub Form_Load()
    Dim objDateStart As Date
    objDateStart = Now()
End Sub

Private Sub Command1_Click()
    Date = objDateTemp = FileDateTime("C:\Program Files\Whatever")
    Time = objDateTemp = FileDateTime("C:\Program Files\Whatever")
    Call Shell("C:\Program Files\Whatever\run.exe", 1)
End Sub

Private Sub Command2_Click()
    Dim intDaysRun As Long
    Dim intTimeRun As Long
    intDaysRun = DateDiff("d", Now(), objDateTemp)
    intTimeRun = DateDiff("s", Now(), objDateTemp)
    Date = DateAdd("d", intTimeRun, objDateStart)
    Unload Me
End Sub

Thanks in advance.

 

Thanks Frederico.

Didn't realize you could declare inside a form like that.

A star for you.

 
No.. You declare "global" variables OUTSIDE the form, but you assigne outside AND inside.

As you have noticed some "assignments" can not be done outside.

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
objDateStart should be renamed to something like dtmDateStart. It is not an object.
Also, review int prefixes. Also, do you realize you try to assign boolean values to Date and Time?
Instead of multiple calls to Now(), introduce variable, assign just once and use it (unless you want to keep track for time portion of Now() during the program running cycle).

vladk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top