Jump to content

Convert VB to AutoIt


Recommended Posts

Hello,

I have found a little VB program for converting Unix time stamps, I would like to convert to AutoIt

Would this be possible? I have very basic experience with VB

There are few lines I would like to convert, Could I use dll calls?

Dim span As New TimeSpan
        span = dateTime2.Value.ToUniversalTime() - dateTime

        Dim returnerItem As New Long
        returnerItem = span.TotalSeconds

;ToUniversalTime

Converts the value of the current DateTime object to Coordinated Universal Time (UTC).

Namespace: System

Assembly: mscorlib (in mscorlib.dll)

;span.TotalSeconds

Represents a time interval.

Namespace: System

Assembly: mscorlib (in mscorlib.dll)

Thanks,

Keith

Edited by Kogmedia
[font="Verdana"]Keith (Kogmedia)[/font]My ScriptQuick Search - Internet / Hard Drive Search
Link to comment
Share on other sites

Link to comment
Share on other sites

Hello,

I have tryed the code you have posted but I get the error message;

C:\Documents and Settings\Kog Media\Desktop\unixtime.au3 (12) : ==> Variable must be of type "Object".:

$span = $UnixTime.Value.ToUniversalTime() - $dateTime

$span = $UnixTime^ ERROR

;Original Program
;http://www.brianprice.ca/2007/06/02/a-lil-program-i-created/

#include <Date.au3>

; Calculated the number of seconds since EPOCH (1970/01/01 00:00:00) 
$dateTime = _DateDiff( 's',"1970/01/01 00:00:00",_NowCalc())

$UnixTime = '1180292400000'

Dim $span
$span = $UnixTime.Value.ToUniversalTime() - $dateTime

Dim $returnerItem
$returnerItem = $span.TotalSeconds

Thanks

Edited by Kogmedia
[font="Verdana"]Keith (Kogmedia)[/font]My ScriptQuick Search - Internet / Hard Drive Search
Link to comment
Share on other sites

Link to comment
Share on other sites

@ptrex

I can't see "createobject" in the original code.

Sorry I have never used ObjCreate before

Here is the full source code

Imports System.DateTime

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dateTime2.Hide()
    End Sub

    Private Sub optionselect1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optionselect1.CheckedChanged
        Me.dateTime1.Show()
        Me.dateTime2.Hide()
    End Sub

    Private Sub optionselect2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optionselect2.CheckedChanged
        Me.dateTime2.Show()
        Me.dateTime1.Hide()
    End Sub

    Private Sub cnvrtButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cnvrtButton.Click
        If Me.optionselect1.Checked = True Then
            If Me.dateTime1.Text = Nothing Then
                MessageBox.Show("Please Enter A Unix Time Stamp", "Missing Parameter", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Return
            End If

            calcWindowsTime()
        ElseIf Me.optionselect2.Checked = True Then
            If Me.dateTime2.Text = Nothing Then
                MessageBox.Show("Please Enter A Unix Time Stamp", "Missing Parameter", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Return
            End If

            calcUnixTime()
        End If
    End Sub

    Private Sub calcWindowsTime()
        ' This function will take the unix time, which is seconds from 01/01/1970 at 00:00:00 GMT, and convert to a String time

        Dim dateTime As New System.DateTime(1970, 1, 1, 0, 0, 0, 0)
        dateTime = dateTime.AddSeconds(Me.dateTime1.Text).ToLocalTime()

        Me.results.Text = dateTime.ToShortDateString & " " & dateTime.ToShortTimeString
    End Sub

    Private Sub calcUnixTime()
        Dim dateTime As New DateTime(1970, 1, 1, 0, 0, 0, 0)
        Dim stringDate = Me.dateTime2.Text

        Dim span As New TimeSpan
        span = dateTime2.Value.ToUniversalTime() - dateTime

        Dim returnerItem As New Long
        returnerItem = span.TotalSeconds

        Me.results.Text = returnerItem
    End Sub

End Class
[font="Verdana"]Keith (Kogmedia)[/font]My ScriptQuick Search - Internet / Hard Drive Search
Link to comment
Share on other sites

@Kogmedia

These functions illustrated in the code are not exactly compatible with AU3

You will have to write your own function for this

This might get you going

$timer = TimerInit()

While 1
   $iTimerDiff = TimerDiff($timer)
   ToolTip(_TimeToString($iTimerDiff),0,0)
   sleep(250)
WEnd

Func _TimeToString($timestamp)
  Local $_time, $_h, $_m, $_s, $_message
  $_time = Round($timestamp / 1000, 0)
  $_h = Int($_time / 3600)
  $_m = Int(($_time - $_h * 3600) / 60)
  $_s = $_time - $_h * 3600 - $_m * 60
  If ($_h > 0) Then
    $_message = StringFormat("%02d:%02d:%02d", $_h, $_m, $_s)
  ElseIf ($_m > 0) Then
    $_message = StringFormat("%02d:%02d", $_m, $_s)
  ElseIf ($_s > 0) Then
    $_message = StringFormat("%02d", $_s)
  Else
    $_message = ""
  EndIf
  Return $_message
EndFuncoÝ÷ Ù©Ýjëh×6Local $Time1 = '00:622:09', $Time2 = '02:1788:05'

MsgBox(0, 'Subtract / Add', 'Subtracted: ' & _StrAddSub($Time1, $Time2, 0) & @CR & _
     'Added: ' & _StrAddSub($Time1, $Time2))

Func _StrAddSub($sTime1, $sTime2, $iAdd = 1, $sDelim = ':'); $iAdd = 1 Add, $iAdd = 0 Subtract
    Local $aSplit1 = StringSplit($sTime1, $sDelim), $iSubTotal = 0
    Local $aSplit2 = StringSplit($sTime2, $sDelim)
    If $aSplit1[0] <> 3 Or $aSplit2[0] <> 3 Then Return SetError(0, 0, 0)
    Local $iTotal1 = ((Int($aSplit1[1]) * 3600) + (Int($aSplit1[2]) * 60) + (Int($aSplit1[3])))
    Local $iTotal2 = ((Int($aSplit2[1]) * 3600) + (Int($aSplit2[2]) * 60) + (Int($aSplit2[3])))
    If $iAdd Then
        $iSubTotal = $iTotal1 + $iTotal2
    ElseIf $iTotal1 >= $iTotal2 Then
        $iSubTotal = $iTotal1 - $iTotal2
    Else
        $iSubTotal = $iTotal2 - $iTotal1
    EndIf
    Local $iHour = Int(($iSubTotal / 3600))
    Local $iMin = Int(($iSubTotal - ($iHour * 3600)) / 60)
    Local $iSec = Int(($iSubTotal - $iHour * 3600) - ($iMin * 60))
    Return StringFormat('%02d', $iHour) & $sDelim & StringFormat('%02d', $iMin) & $sDelim & StringFormat('%02d', $iSec)
EndFunc

Hope this helps

regards

ptrex

Link to comment
Share on other sites

Hi,

Not sure if it is your issue, but @arcker did some conversions with Unix time stamp, and we made a vbs script to run in AutoIt;

VBconvert + dateIf you give me an example of the input data you have , I could have a look. And I think, even better, @arcker understands it!

Best, randall

Link to comment
Share on other sites

Hi,

Not sure if it is your issue, but @arcker did some conversions with Unix time stamp, and we made a vbs script to run in AutoIt;

VBconvert + dateIf you give me an example of the input data you have , I could have a look. And I think, even better, @arcker understands it!

Best, randall

Here is an example date

Unix: 1180292400000

Real Date: 27/05/2007 20:00

Thanks It would be great to get unix time in autoit :rolleyes:

[font="Verdana"]Keith (Kogmedia)[/font]My ScriptQuick Search - Internet / Hard Drive Search
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...