Server Uptime Timer

From VbGORE Visual Basic Online RPG Engine

Hey guys. Thought I'd share this code with you guys since I originally made it for my Elysium game. Which I decided to drop since I found vbGORE. Anyhow, I'm not sure if Spodi plans on adding this feature to the server itself. But heres the mini tutorial explaining how to do it.

The Code

<vb> 'Uptime Script/Form 'By: David "Amiga-Pirate" Cluett 'Revised: April 30th 2007 'Please Keep Copyright in-tact.

Dim UTDays As Integer Dim UTHrs As Integer Dim UTMins As Integer Dim UTSecs As Integer

Private Sub Form_Load() UTDays = 0 UTHrs = 0 UTMins = 0 UTSecs = 0 lblUT.Caption = UTDays & " Days, " & UTHrs & " Hours, " & UTMins & " Mins, " & UTSecs & " Seconds" End Sub

Sub AddSecond() UTSecs = UTSecs + 1

   If UTSecs = 60 Then
       AddMin
       UTSecs = 0
   End If

End Sub

Sub AddMin() UTMins = UTMins + 1

   If UTMins = 60 Then
       AddHour
       UTMins = 0
   End If

End Sub

Sub AddHour() UTHrs = UTHrs + 1

   If UTHrs = 24 Then
       AddDay
       UTHrs = 0
   End If

End Sub

Sub AddDay() UTDays = UTDays + 1 End Sub

Private Sub UT_Timer() AddSecond lblUT.Caption = UTDays & " Days, " & UTHrs & " Hours, " & UTMins & " Mins, " & UTSecs & " Seconds" End Sub

</vb>

Instructions

Now, you ask what am I doing with this code? Well go ahead and add a new form to the server project. Name it something logical like frmUptime or something. Next you want to access your frmMain and add to the menu, by right clicking the form and clicking "Menu Editor...". Add a fancy button that says Server Uptime etc. And click OK/Apply. Now what your going to want to do is double click on the black area provided in the Form Design template in VB6. It should take you to the Form_Load() function.

Find/Locate

<vb> Private Sub Form_Load() Dim TempSplit() As String </vb>

Add Underneath

<vb> frmUptime.Show </vb>

Keep in mind that frmUptime is what I called my second form showing the uptime. Replace it with whatever it is you named your form. The ".show" argument will start the dialog at the launch of the application. How ever, it will automatically hide after the server is up. And it won't start counting until it's Hidden. Now the next step is to go into the menu in the frmMain form and click the server uptime button you created. And now it should take you to your Click function for the menu. Like so.

<vb> Private Sub mnuUT_Click() frmUptime.Show End Sub </vb>

Again use the show argument as it will now display the time and status of the server being up. Make sure you have the code in code section of this tutorial is written into this form. Also on this form, The server uptime that is. Make sure you have a Label, a Timer and of course a Close button (Not talking about a red X here. I mean a command button.). Name them accordingly, then you should be set. And actually I made a mistake earlier. It shows from the Launch of the program. But that's besides the point right?

Similar.jpg

You're form should look similar to this. Also make sure your timer is set to an Interval of 1000 ms.

Next you're going to want to add this to your timer function.

<vb> AddSecond lblUT.Caption = UTDays & " Days, " & UTHrs & " Hours, " & UTMins & " Mins, " & UTSecs & " Seconds" </vb>

So now, it calls the AddSecond Function and it updates our label we set. I think I've covered everything. If I didn't feel free to Contact me on the forums via pm and I'll be happy to help. As well if you have improvements feel free to add. And if it comes down to it, I'll post the form file or project on the forums. ALSO PLEASE MAKE SURE YOU MAKE THE LABELS ACCORDINGLY TO AVOID CONFUSION!

Personal tools