Problem with variables?

Posted on 2003-03-29
Medium Priority
Last Modified: 2010-04-17
I have two control buttons. I have both of them entering the system date into two seperate text boxes when clicked. I need the second control button to enter the system date (which it does) and use the variables left over from the first control button to subtract them from the variables left over from the second button.

This currently is not working. I wanted to test my code so I switched the variables around so the second button was subtracting one variable in the Control code from the other variable in that same Control button code and displaying it in a text box. This worked fine. This leads me to believe that it is a variable problem. Since VB gets rid of the variable contents once used the variable must be getting dumped. I tried using Static and changing it to Public to see if this would work, but still nothing. Here is the code for the two control buttons: - Any ideas?

Public Sub cmdIn_Click()

clkTimein = Format$(Time, "hh:mm")
txtIn.Text = clkTimein
hrIn = Left(clkTimein, 2)
minIn = Right(clkTimein, 2)
hrInone = Val(hrIn)
minInone = Val(minIn)

End Sub

Public Sub cmdOut_Click()

clkTimeout = Format$(Time, "hh:mm")
txtOut.Text = clkTimeout
hrOut = Left(clkTimeout, 2)
minOut = Right(clkTimeout, 2)
hrOutone = Val(hrOut)
minOutone = Val(minOut)
numTothr = hrOutone + minOutone
numTotmin = minOutone + minInone
strTothr = Str(numTothr)
strTotmin = Str(numTotmin)
txtTothr.Text = strTothr
txtTotmin.Text = strTotmin

End Sub
Question by:ammo325
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1

Expert Comment

ID: 8229786
Use text box as variable.

Your code cleeared looks essentially like this:

Public Sub cmdIn_Click()
txtIn = Format$(Time, "hh:mm")
End Sub

Public Sub cmdOut_Click()

txtTothr.Text = Left(Format$(Time, "hh:mm"), 2) + Right(Format$(Time, "hh:mm"), 2)
txtTotmin.Text = Right(Format$(Time, "hh:mm"), 2)  + Right(txtIn, 2)

End Sub

Author Comment

ID: 8229864
Thank you for the response. That didn't really fix it totally, unfortunately the boxes are still showing the incorrect value.

Expert Comment

ID: 8229951
What exactly you want do?
If time in textIn is "12:00"
and time now is "12:12"
what do you want to see in txtOut?
Independent Software Vendors: 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

ID: 8229956
I would like to see 0012

Its a program that has a time in and a time out. So the time out will always need time in subtracted from it to show the duration that has passed.

Accepted Solution

bistrica earned 200 total points
ID: 8231125
Then check DateDiff function.

Expert Comment

ID: 8233287
Bistrica is right; what you want to do is trivial (not to minimise the difficulty you've had with it - I simply mean you should use DateDiff and achieve what you want in simply one line of code!).

Author Comment

ID: 8233360
Thank you. I will try that. I have a nice tutorial book on VB6, doesn't mention DateDiff in it that I know of. Not in the index anyway.

Assisted Solution

davidmwilliams earned 100 total points
ID: 8233529
Here, try this Web page for a tutorial on various time and date-handling functions in VB6 (including DateDiff):


(Careful - it's a long URL and the lines may wrap).

Expert Comment

ID: 9446681
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Simple Linear Regression
Suggested Courses

801 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