Jump to content

Recommended Posts

Posted (edited)

Hello!  Happy Advent!

I shock myself sometimes <g>, I just started editing a file that had 2 inputboxes that I'd made up using the CodeWizard tool some years back (though I don't remember much from that far back <g>!).  But I went and added another inputbox and darned if it doesn't work and work without hiccuping!!!  <lol>  MIracle I managed to do it <g>.

Anyway, it's for creating folders.  But I don't know how to apply the StringFormat to the leading number that will be inserted at the beginning of the created folder name.

The user input for the folder number is in inputbox 1.

Here is my code:

;
; AutoIt 3x
;
#Include <Date.au3>
#include<_My_DATE.au3>     ; my date, time conventions, etc.
#NoTrayIcon     ; AutoIt's icon doesn't show in systray
TraySetIcon("Shell32.dll", 147)     ; changes the icon displayed in the systray
AutoItSetOption("WinTitleMatchMode", 2)     ; this allows partial window titles to be valid!
;-------------------------------------------------------------------------------------------------------------------------


#Region --- CodeWizard generated code Start ---
;InputBox features: Title=Yes, Prompt=Yes, Default Text=Yes, Width=250, Height=125
If Not IsDeclared("sInputBoxAnswer1") Then Local $sInputBoxAnswer1
;=====================================================================================================
$BoxTitle1  = "Create folder:"
$LineTitle1 = "1. Number for next folder -- (i.e., ''2'', ''14'', or ''99'', etc. ...):"
$BoxWidth1  = "525"
$BoxHeight1 = "125"
;=====================================================================================================
$sInputBoxAnswer1 = InputBox($BoxTitle1, $LineTitle1 & @CRLF & @CRLF, ""," ", $BoxWidth1, $BoxHeight1, Default, Default)    ; width, heigh, left ("Default" centers box), top ("Default" centers box).
Select
    Case @Error = 0 ;OK - The string returned is valid
            ClipPut($sInputBoxAnswer1)
    Case @Error = 1 ;The Cancel button was pushed
        Exit     ; finished
    Case @Error = 3 ;The InputBox failed to open
        Exit     ; finished
EndSelect
#EndRegion --- CodeWizard generated code End ---


If Not IsDeclared("sInputBoxAnswer2") Then Local $sInputBoxAnswer2
;=====================================================================================================
$BoxTitle2  = "Create folder:"
$LineTitle2 = "2. yymmdd.ddd" & @CRLF & "(Today's date by default; but change, as needed in yymmdd.ddd format.):"
$BoxWidth2  = "525"
$BoxHeight2 = "145"
;=====================================================================================================
$sInputBoxAnswer2 = InputBox($BoxTitle2, $LineTitle2 & @CRLF & @CRLF, $YrDate_Short," ", $BoxWidth2, $BoxHeight2, Default, Default)    ; width, heigh, left ("Default" centers box), top ("Default" centers box).
Select
    Case @Error = 0 ;OK - The string returned is valid
            ClipPut($sInputBoxAnswer2)
    Case @Error = 1 ;The Cancel button was pushed
        Exit     ; finished
    Case @Error = 3 ;The InputBox failed to open
        Exit     ; finished
EndSelect
#EndRegion --- CodeWizard generated code End ---


If Not IsDeclared("sInputBoxAnswer3") Then Local $sInputBoxAnswer3
;=====================================================================================================
$BoxTitle3  = "Create folder:"
$LineTitle3 = "3. Name for folder -- (i.e., Pliers, etc.):"
$BoxWidth3  = "525"
$BoxHeight3 = "125"
;=====================================================================================================
#Region --- CodeWizard generated code Start ---
;InputBox features: Title=Yes, Prompt=Yes, Default Text=Yes, Width=250, Height=125
If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer3
$sInputBoxAnswer3 = InputBox($BoxTitle3, $LineTitle3 & @CRLF & @CRLF, ""," ", $BoxWidth3, $BoxHeight3, Default, Default)    ; width, heigh, left ("Default" centers box), top ("Default" centers box).
Select
    Case @Error = 0 ;OK - The string returned is valid
        ;==============================================================================
        $PathAndFldrName = @ScriptDir & "\" & $sInputBoxAnswer1 & "." & $sInputBoxAnswer2 & "- " & $sInputBoxAnswer3 & " [rd"
        ;==============================================================================
        $Title1    = ClipGet() & ", _ _._ _- " & $sInputBoxAnswer3 & "- PRODUCT DETAILS.txt"
        $LineText1 = "Seller:" & @TAB & @TAB & @TAB & "." & @CRLF & _
                     "* FULFILLED By:" & @TAB & "." & @CRLF & _
                     "Product:" & @TAB & @TAB & @TAB & "." & @CRLF & _
                     "Price:" & @TAB & @TAB & @TAB & "$ #.#" & @CRLF & @CRLF & @CRLF & _
                     "Price:" & @TAB & @TAB & @TAB & "$ #.#" & @CRLF & @CRLF & @CRLF & _
                                "--------------------------------" & @CRLF & _
                     "Source URL:" & @TAB & "." & @CRLF & _
                                "--------------------------------" & @CRLF & @CRLF & @CRLF & _
                     "Details:" & @TAB & @CRLF & "*******" & @CRLF & @CRLF & "."
        ;------------------------------------------------------------------------------
        $Title2    = ClipGet() & ", _ _._ _- " & $sInputBoxAnswer3 & "- [SOURCE URL FOR PRODUCT(S) (drag pg here4 2create)].url"
        $LineText2 = ""
        ;------------------------------------------------------------------------------
        $Title3    = ClipGet() & ", _ _._ _- " & $sInputBoxAnswer3 & "- screencapture of order page.jpg"
        $LineText3 = ""
        ;==============================================================================
        DirCreate($PathAndFldrName)
        Sleep(50)
        FileWrite($PathAndFldrName & "\" & $Title1, $LineText1)
        Sleep(50)
        FileWrite($PathAndFldrName & "\" & $Title2, $LineText2)
        Sleep(50)
        FileWrite($PathAndFldrName & "\" & $Title3, $LineText3)
    Case @Error = 1 ;The Cancel button was pushed
        Exit     ; finished
    Case @Error = 3 ;The InputBox failed to open
        Exit     ; finished
EndSelect
#EndRegion --- CodeWizard generated code End ---

 

[Now before anyone says, I'm sure it's ugly to you guys and it could probably be done waaayyyy better than this.  But this is at my level and I can understand it <g>.]

 

In other scripts that I have, I can ensure they keep the same naming convention in terms of number length by using StringFormat.

An example I have of a line of working code can be seen here below.  But I'm lost as how to apply it to the script above in the section dealing with $sInputBoxAnswer1 re the folder name.

 I think for 3 places with leading 0 -- to ensure the output is like this - 009, 054, 099, 125, etc. -- the code below with "StringFormat("%02i"," might need %03i, instead of %02i, no?

ClipPut($YrDate_Short & "." & StringFormat("%02i", $number) & "- ")

Thank you for any help in advance!

:)

Edited by Diana (Cda)
Posted
7 hours ago, argumentum said:

Yes

Great!  So that part of the question is okay, then.

I just don't know how to add that StringFormat (with %03i) shown in the example (found in the 2nd code block) into my script that I posted in the 1st code block above.

 

Thank you!

Posted
4 hours ago, Diana (Cda) said:

I just don't know how to...

"D:\New AutoIt v3 Script.au3"(5,9) : error: can't open include file <_My_DATE.au3>.
#include<_My_DATE.au3>
~~~~~~~~^
"D:\New AutoIt v3 Script.au3"(40,84) : warning: $YrDate_Short: possibly used before declaration.
$sInputBoxAnswer2 = InputBox($BoxTitle2, $LineTitle2 & @CRLF & @CRLF, $YrDate_Short,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"D:\New AutoIt v3 Script.au3"(40,84) : error: $YrDate_Short: undeclared global variable.
$sInputBoxAnswer2 = InputBox($BoxTitle2, $LineTitle2 & @CRLF & @CRLF, $YrDate_Short,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
D:\New AutoIt v3 Script.au3 - 2 error(s), 1 warning(s)
!>10:10:33 AU3Check ended. Press F4 to jump to next error. rc:2

 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted (edited)

 

;
; AutoIt 3x
;
#Include <Date.au3>
;~ #include<_My_DATE.au3>     ; my date, time conventions, etc.
#NoTrayIcon     ; AutoIt's icon doesn't show in systray
TraySetIcon("Shell32.dll", 147)     ; changes the icon displayed in the systray
AutoItSetOption("WinTitleMatchMode", 2)     ; this allows partial window titles to be valid!
;-------------------------------------------------------------------------------------------------------------------------

#Region --- CodeWizard generated code Start ---
;InputBox features: Title=Yes, Prompt=Yes, Default Text=Yes, Width=250, Height=125
If Not IsDeclared("sInputBoxAnswer1") Then Local $sInputBoxAnswer1
;=====================================================================================================
$BoxTitle1  = "Create folder:"
$LineTitle1 = "1. Number for next folder -- (i.e., ''2'', ''14'', or ''99'', etc. ...):"
$BoxWidth1  = "525"
$BoxHeight1 = "125"
;=====================================================================================================
$sInputBoxAnswer1 = InputBox($BoxTitle1, $LineTitle1 & @CRLF & @CRLF, ""," ", $BoxWidth1, $BoxHeight1, Default, Default)    ; width, heigh, left ("Default" centers box), top ("Default" centers box).
Select
    Case @Error = 0 ;OK - The string returned is valid
;~      ClipPut($sInputBoxAnswer1)  ; No needed , use the $sInputBoxAnswer1 ⚠️
        $sInputBoxAnswer1 = StringFormat("%03i", $sInputBoxAnswer1) ; Here you are formatting. ⚠️
    Case @Error = 1 ;The Cancel button was pushed
        Exit     ; finished
    Case @Error = 3 ;The InputBox failed to open
        Exit     ; finished
EndSelect
#EndRegion --- CodeWizard generated code End ---


If Not IsDeclared("sInputBoxAnswer2") Then Local $sInputBoxAnswer2
;=====================================================================================================
$BoxTitle2  = "Create folder:"
$LineTitle2 = "2. yymmdd.ddd" & @CRLF & "(Today's date by default; but change, as needed in yymmdd.ddd format.):"
$BoxWidth2  = "525"
$BoxHeight2 = "145"
;=====================================================================================================
;~ $sInputBoxAnswer2 = InputBox($BoxTitle2, $LineTitle2 & @CRLF & @CRLF, $YrDate_Short," ", $BoxWidth2, $BoxHeight2, Default, Default)    ; width, heigh, left ("Default" centers box), top ("Default" centers box).
$sInputBoxAnswer2 = InputBox($BoxTitle2, $LineTitle2 & @CRLF & @CRLF, _DTFormat(_NowCalc(), "yyMMdd.ddd"), " ", $BoxWidth2, $BoxHeight2, Default, Default)    ; width, heigh, left ("Default" centers box), top ("Default" centers box).
Select
    Case @Error = 0 ;OK - The string returned is valid
;~      ClipPut($sInputBoxAnswer2) ; No needed , use the $sInputBoxAnswer2 ⚠️
    Case @Error = 1 ;The Cancel button was pushed
        Exit     ; finished
    Case @Error = 3 ;The InputBox failed to open
        Exit     ; finished
EndSelect
#EndRegion --- CodeWizard generated code End ---


If Not IsDeclared("sInputBoxAnswer3") Then Local $sInputBoxAnswer3
;=====================================================================================================
$BoxTitle3  = "Create folder:"
$LineTitle3 = "3. Name for folder -- (i.e., Pliers, etc.):"
$BoxWidth3  = "525"
$BoxHeight3 = "125"
;=====================================================================================================
#Region --- CodeWizard generated code Start ---
;InputBox features: Title=Yes, Prompt=Yes, Default Text=Yes, Width=250, Height=125
If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer3
$sInputBoxAnswer3 = InputBox($BoxTitle3, $LineTitle3 & @CRLF & @CRLF, ""," ", $BoxWidth3, $BoxHeight3, Default, Default)    ; width, heigh, left ("Default" centers box), top ("Default" centers box).
Select
    Case @Error = 0 ;OK - The string returned is valid
        ;==============================================================================
        $PathAndFldrName = @ScriptDir & "\" & $sInputBoxAnswer1 & "." & $sInputBoxAnswer2 & "- " & $sInputBoxAnswer3 & " [rd"
        ;==============================================================================
;~      $Title1    = ClipGet() & ", _ _._ _- " & $sInputBoxAnswer3 & "- PRODUCT DETAILS.txt"
        $Title1    = $sInputBoxAnswer2 & ", _ _._ _- " & $sInputBoxAnswer3 & "- PRODUCT DETAILS.txt"
        $LineText1 = "Seller:" & @TAB & @TAB & @TAB & "." & @CRLF & _
                     "* FULFILLED By:" & @TAB & "." & @CRLF & _
                     "Product:" & @TAB & @TAB & @TAB & "." & @CRLF & _
                     "Price:" & @TAB & @TAB & @TAB & "$ #.#" & @CRLF & @CRLF & @CRLF & _
                     "Price:" & @TAB & @TAB & @TAB & "$ #.#" & @CRLF & @CRLF & @CRLF & _
                                "--------------------------------" & @CRLF & _
                     "Source URL:" & @TAB & "." & @CRLF & _
                                "--------------------------------" & @CRLF & @CRLF & @CRLF & _
                     "Details:" & @TAB & @CRLF & "*******" & @CRLF & @CRLF & "."
        ;------------------------------------------------------------------------------
;~      $Title2    = ClipGet() & ", _ _._ _- " & $sInputBoxAnswer3 & "- [SOURCE URL FOR PRODUCT(S) (drag pg here4 2create)].url"
        $Title2    = $sInputBoxAnswer2 & ", _ _._ _- " & $sInputBoxAnswer3 & "- [SOURCE URL FOR PRODUCT(S) (drag pg here4 2create)].url"

        $LineText2 = ""
        ;------------------------------------------------------------------------------
;~      $Title3    = ClipGet() & ", _ _._ _- " & $sInputBoxAnswer3 & "- screencapture of order page.jpg"
        $Title3    = $sInputBoxAnswer2 & ", _ _._ _- " & $sInputBoxAnswer3 & "- screencapture of order page.jpg"
        $LineText3 = ""
        ;==============================================================================
        DirCreate($PathAndFldrName)
        Sleep(50)
        FileWrite($PathAndFldrName & "\" & $Title1, $LineText1)
        Sleep(50)
        FileWrite($PathAndFldrName & "\" & $Title2, $LineText2)
        Sleep(50)
        FileWrite($PathAndFldrName & "\" & $Title3, $LineText3)
    Case @Error = 1 ;The Cancel button was pushed
        Exit     ; finished
    Case @Error = 3 ;The InputBox failed to open
        Exit     ; finished
EndSelect
#EndRegion --- CodeWizard generated code End ---

; #FUNCTION# ====================================================================================================================
; Name...........: _DTFormat
; Description....: Formats a given date/time string according to the specified format.
; Syntax.........: _DTFormat($sDate, $sFormat [, $iLcid = $LOCALE_USER_DEFAULT])
; Parameters.....: $sDate     - The date string to be formatted "[YYYY/MM/DD][ HH:MM:SS [ tt]]".
;                  $sFormat   - A string containing the desired format for the date and time.
;                               Supported tokens are: Date and/or Time
;                               Date:
;                                   d, dd = day; ddd, dddd = day of week; M= month; y = year
;                               Time:
;                                   h= hour m= minute
;                                   s = second (long time only)
;                                   tt= AM. or P.M.
;                                   h/H = 12/24 hour
;                                   hh, mm, ss = display leading zero
;                                   h, m, s = do not display leading zero
;                               Tokens can be separated by '|' to specify different formats for date and time.
;                  $iLcid     - [optional] The locale identifier. Defaults to the user's default locale (default is $LOCALE_USER_DEFAULT).
;                                   e.g. German = 1031, English = 1033
; Return values .: Success: Returns the formatted date string.
;                  Failure: Returns an empty string and set the @error flag to non-zero.
;                               @error:
;                                   1 - Error date is not valid.
;                                   2 - Error in splitting the date string
;                                   3 - Error in encoding SystemTime
;                                   4 - Error in time formatting
;                                   5 - Error in date formatting
; Author ........: ioa747
; Modified ......:
; Remarks .......: This function uses the Windows API to format date and time according to the specified locale.
; Related .......: _Date_Time_EncodeSystemTime, _WinAPI_GetDateFormat, _WinAPI_GetTimeFormat, _WinAPI_GetLocaleInfo
; Link ..........: https://learn.microsoft.com/en-us/windows/win32/intl/day--month--year--and-era-format-pictures
;                  https://www.autoitscript.com/forum/topic/213249-free-style-datetimeformat/#comment-1546499
; Example .......: MsgBox(0, "Formatted Date", _DTFormat("2023/10/05 14:30:00", "MM/DD/YYYY|, HH:MM:SS"))
; ===============================================================================================================================
Func _DTFormat($sDate, $sFormat, $iLcid = $LOCALE_USER_DEFAULT)
    Local $asDatePart[4], $asTimePart[4]
    Local $sTempDate = "", $sTempTime = ""
    Local $sAM, $sPM, $sTempString = ""
    Local $bDate = True

    ; If there is no date, add a dummy one (2000/01/01)
    If StringInStr($sDate, "/") = 0 And Not @error Then
        $bDate = False
        $sDate = "2000/01/01 " & $sDate
    Else ; Verify If InputDate is valid
        If Not _DateIsValid($sDate) Then Return SetError(1, 0, "") ; Error date is not valid.
    EndIf

    ; Split the date and time into arrays
    _DateTimeSplit($sDate, $asDatePart, $asTimePart)
    If @error Then Return SetError(2, @error, "") ; Error in splitting the date string

    Local $aPart = StringSplit($sFormat, "|")

    If $bDate Then
        $sTempDate = $aPart[1]
        $sTempTime = ""
        If $aPart[0] = 2 Then $sTempTime = $aPart[2]
    Else
        $sTempTime = $aPart[1]
    EndIf

    ; If time parts exist, check for AM/PM and convert to 24-hour format
    If $asTimePart[0] > 1 Then

        ; Get locale's AM designator, or AM
        $sTempString = _WinAPI_GetLocaleInfo($iLcid, $LOCALE_S1159) ; AM designator.
        If Not @error And Not ($sTempString = '') Then
            $sAM = $sTempString
        Else
            $sAM = "AM"
        EndIf

        ; Get locale's PM designator, or PM
        $sTempString = _WinAPI_GetLocaleInfo($iLcid, $LOCALE_S2359) ; PM designator.
        If Not @error And Not ($sTempString = '') Then
            $sPM = $sTempString
        Else
            $sPM = "PM"
        EndIf

        ; Convert 12-hour clock (with PM) to 24-hour clock
        If (StringInStr($sDate, 'pm') > 0) Or (StringInStr($sDate, $sPM) > 0) Then
            If $asTimePart[1] < 12 Then $asTimePart[1] += 12
            ; Convert 12-hour clock (with AM) to 24-hour clock (handle 12 AM midnight case)
        ElseIf (StringInStr($sDate, 'am') > 0) Or (StringInStr($sDate, $sAM) > 0) Then
            If $asTimePart[1] = 12 Then $asTimePart[1] = 0
        EndIf
    EndIf

    ; Remove ' tt' if hour is in format H/24 hour
    If StringInStr($sTempTime, "H", 1) > 0 Then $sTempTime = StringReplace($sTempTime, " tt", "")

    ; Encode a system time structure (required by WinAPI date/time functions)
    Local $tSystem = _Date_Time_EncodeSystemTime($asDatePart[2], $asDatePart[3], $asDatePart[1], $asTimePart[1], $asTimePart[2], $asTimePart[3])
    If @error Then Return SetError(3, @error, "") ; Error in encoding SystemTime

    Local $sfinalTime = _WinAPI_GetTimeFormat($iLcid, $tSystem, 0, $sTempTime)
    If @error Then Return SetError(4, @error, "") ; Error in time formatting

    ; Force AM/PM if the format string contains 'tt' but regional settings didn't include it
    If StringInStr($sTempTime, "tt") Then
        If (StringInStr($sfinalTime, 'pm') = 0) And (StringInStr($sfinalTime, $sPM) = 0) And _
                (StringInStr($sfinalTime, 'am') = 0) And (StringInStr($sfinalTime, $sAM) = 0) Then
            If $asTimePart[1] < 12 Then
                $sfinalTime &= " " & $sAM
            Else
                $sfinalTime &= " " & $sPM
            EndIf
        EndIf
    EndIf

    Local $sResult = ""
    If $sTempDate <> "" Then $sResult &= _WinAPI_GetDateFormat($iLcid, $tSystem, 0, $sTempDate)
    If @error Then Return SetError(5, @error, "") ; Error in date formatting

    If $sTempTime <> "" Then $sResult &= $sfinalTime
    Return $sResult

EndFunc   ;==>_DTFormat

 

Edited by ioa747

I know that I know nothing

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
  • Recently Browsing   0 members

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