Sign in to follow this  
Followers 0
Stel

Parsing Varilables

5 posts in this topic

$BigVar = 1234567890

$var1 = ; I want characters 1-4 from $BigVar

$Var2 = ; I want characters 4-5 from $BigVar

$Var3 = ; I want characters 6-7 from $BigVar

$Var4 = ; I want characters 8-0 from $BigVar

I want to use this when I $objItem.LocalDateTime from a WMI query from Win32_OperatingSystem to construct a date and time.

The VBScript code that I'd use is

----------------------------------------------------------

For Each objItem in colItems

dtmLocalTime = objItem.LocalDateTime

dtmMonth = Mid(dtmLocalTime, 5, 2)

dtmDay = Mid(dtmLocalTime, 7, 2)

dtmYear = Left(dtmLocalTime, 4)

dtmHour = Mid(dtmLocalTime, 9, 2)

dtmMinutes = Mid(dtmLocalTime, 11, 2)

dtmSeconds = Mid(dtmLocalTime, 13, 2)

Next

--------------------------------------------------------

How would I parse a larger variable into a smaller one?

Thanks,

Stel

Share this post


Link to post
Share on other sites



Maybe you can tell us what the out-come you are looking for

Autoit has many, many time Functions that can deliver many out-puts

what is your desired end results?

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Maybe...

Global $BigVar = 1234567890
Global $Var[5]

$Var[1] = StringLeft($BigVar, 4); I want characters 1-4 from $BigVar
$Var[2] = StringLeft(StringTrimLeft($BigVar, 3), 2); I want characters 4-5 from $BigVar
$Var[3] = StringLeft(StringTrimLeft($BigVar, 5), 2); I want characters 6-7 from $BigVar
$Var[4] = StringTrimLeft($BigVar, 7); I want characters 8-0 from $BigVar

For $x = 1 To 4
    MsgBox(64, "Variable " & $x, $Var[$x], 4)
Next

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

This is what I was looking for.

Thanks

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I think what you're really looking for is StringMid().

$BigVar = 1234567890

$var1 = StringMid($BigVar, 1, 4) ; I want characters 1-4 from $BigVar
$Var2 = StringMid($BigVar, 4, 2) ; I want characters 4-5 from $BigVar
$Var3 = StringMid($BigVar, 6, 2) ; I want characters 6-7 from $BigVar
$Var4 = StringMid($BigVar, 8, 3) ; I want characters 8-0 from $BigVar

; just to show results:
For $i = 1 To 4
    MsgBox(0, '', Eval('var' & $i))
Next

edit - removed a stray var :whistle:

Edited by xcal

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