Sign in to follow this  
Followers 0
NeptuneIT

Passing Variables in AutoIt

8 posts in this topic

I'm attempting to use AutoIt to build a GUI for a vbscript that my company uses. I've tried converting the vbscript to AutoIt but there is a function that cannot convert.

My next plan was to build the GUI in AutoIt and then have it fire off the vbscript located on a network share. Is there a way to pass variables from the AutoIt script to the VBScript?

Is this the best way to do what i'm trying to do or is there a way to embed a vbscript inside an AutoIt script without having to convert?

This is my first attempt at making a productive AutoIt script (I've made a few bots) so I appreciate any help someone can lend me! Thanks!

Share this post


Link to post
Share on other sites



I know nothing about VBS but you could have AutoIt write the variable to an ini file for your VBS script to read.



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

1. What function?

2. Commandline is easiest, then...

3. ScriptControl object, but not 100% perfect (and point 1 is concern with SC)

4. We try to help

Share this post


Link to post
Share on other sites

1. What function?

CDate - searched the forums about this one and it seem someone else is using the same function to convert dates from active directory but no one ever responded to him. Here's the full function of which CDate is a part:

Function Integer8Date(objDate, lngBias)
' Function to convert Integer8 (64-bit) value to a date, adjusted for
' local time zone bias.
  Dim lngAdjust, lngDate, lngHigh, lngLow
  lngAdjust = lngBias
  lngHigh = objDate.HighPart
  lngLow = objdate.LowPart
' Account for error in IADslargeInteger property methods.
  If lngLow < 0 Then
    lngHigh = lngHigh + 1
  End If
  If (lngHigh = 0) And (lngLow = 0) Then
    lngAdjust = 0
  End If
  lngDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _
    + lngLow) / 600000000 - lngAdjust) / 1440
' Trap error if lngDate is ridiculously huge.
  On Error Resume Next
  Integer8Date = CDate(lngDate)
  If Err.Number <> 0 Then
    On Error GoTo 0
    Integer8Date = #1/1/1601#
  End If
  On Error GoTo 0
End Function

4. We try to help

Thanks!

Share this post


Link to post
Share on other sites

I know nothing about VBS but you could have AutoIt write the variable to an ini file for your VBS script to read.

I'm pretty sure I can get the vbscript to read the ini file - Can you point me where to look to get AutoIt to write to an ini?

Thanks!

Share this post


Link to post
Share on other sites

Look in the AutoIt help file under IniWrite


Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites

Look in the AutoIt help file under IniWrite

Perfect! Thanks a ton

Share this post


Link to post
Share on other sites

CDate - searched the forums about this one and it seem someone else is using the same function to convert dates from active directory but no one ever responded to him. Here's the full function of which CDate is a part:

CDate, ohh, tough one as AutoIt has no date function except for the macros.

Here is a quick untested hack. ScriptControl sometimes dislikes comments, and certain VBS functions and syntax. "On Error Goto..." would seem useless under a virtual script execution. ScriptControl can use code from a FileRead() but as stated, not 100% perfect at doing it by far (i.e. may not work).

Not sure how to call and test this function but what I have come along with which may give you some direction.

Integer8Date(9223372036854775807, 0); hmm.. :(

Func Integer8Date($objDate, $lngBias)
    Local $code, $oSC
    $code = _
    "Function Integer8Date(objDate, lngBias)" & @CRLF & _
    "' Function to convert Integer8 (64-bit) value to a date, adjusted for" & @CRLF & _
    "' local time zone bias." & @CRLF & _
    "  Dim lngAdjust, lngDate, lngHigh, lngLow" & @CRLF & _
    "  lngAdjust = lngBias" & @CRLF & _
    "  lngHigh = objDate.HighPart" & @CRLF & _
    "  lngLow = objdate.LowPart" & @CRLF & _
    "' Account for error in IADslargeInteger property methods." & @CRLF & _
    "  If lngLow < 0 Then" & @CRLF & _
    "    lngHigh = lngHigh + 1" & @CRLF & _
    "  End If" & @CRLF & _
    "  If (lngHigh = 0) And (lngLow = 0) Then" & @CRLF & _
    "    lngAdjust = 0" & @CRLF & _
    "  End If" & @CRLF & _
    "  lngDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _" & @CRLF & _
    "    + lngLow) / 600000000 - lngAdjust) / 1440" & @CRLF & _
    "' Trap error if lngDate is ridiculously huge." & @CRLF & _
    "  On Error Resume Next" & @CRLF & _
    "  Integer8Date = CDate(lngDate)" & @CRLF & _
    "  If Err.Number <> 0 Then" & @CRLF & _
    "    On Error GoTo 0" & @CRLF & _
    "    Integer8Date = #1/1/1601#" & @CRLF & _
    "  End If" & @CRLF & _
    "  On Error GoTo 0" & @CRLF & _
    "End Function"
    $oSC = ObjCreate('ScriptControl')
    If Not @error Then
        $oSC.language = 'VBScript'
        $oSC.addcode ($code)
        Return $oSC.run ('Integer8Date', $objDate, $lngBias)
    Else
        Return SetError(1, 0, '')
    EndIf
EndFunc

Share this post


Link to post
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
Sign in to follow this  
Followers 0