Jump to content

Array Help (ANSWERED)


Recommended Posts

I am working on some code to modify the current date to a different format and have ran into a snag. The last array element I am trying to assign will not work and gives errors. All of the other assignments work and when I comment out #12, the code works. It has to be something very simple I am missing, but I just do not see it. Can someone take a look and help me out? Also, is there a way I can do these assignments without using so much space?

Thanks ...

;=====================================================
; Script name:  Date_Test
; Author:   Barry Bowden
; Purpose:  Test various date variables and arrays to get a specific
;               date format from the current date.
; Created:      6 March 2011
; Changes:      n/a)
; Last rev.     n/a
;=====================================================
MsgBox(0,"Date","Today is ... " & @MDAY & " " & _Month() & " " & @YEAR & @CRLF & @CRLF & "Hour = " & @HOUR & @CRLF & "Minutes = " & @MIN & @CRLF & "Seconds = " & @SEC & @CRLF & @CRLF & @HOUR & ":" & @MIN & ":" & @SEC)

Func _Month()
    Dim $Months[12]
    $Months[1] = "Jan"
    $Months[2] = "Feb"
    $Months[3] = "Mar"
    $Months[4] = "Apr"
    $Months[5] = "May"
    $Months[6] = "Jun"
    $Months[7] = "Jul"
    $Months[8] = "Aug"
    $Months[9] = "Sep"
    $Months[10] = "Oct"
    $Months[11] = "Nov"
    $Months[12] = "December"
    
    $MonthName = $Months[@MON]
    ;MsgBox(0,"Month Born","You were born in the month of " & $MonthName)
    Return $MonthName
EndFunc
Edited by bqbowden
Link to comment
Share on other sites

you have 13 elements, just because you dont put something in [0] doesnt mean its not still there.

#include <array.au3>

;=====================================================
; Script name:  Date_Test
; Author:   Barry Bowden
; Purpose:  Test various date variables and arrays to get a specific
;               date format from the current date.
; Created:      6 March 2011
; Changes:      n/a)
; Last rev.     n/a
;=====================================================
MsgBox(0,"Date","Today is ... " & @MDAY & " " & _Month() & " " & @YEAR & @CRLF & @CRLF & "Hour = " & @HOUR & @CRLF & "Minutes = " & @MIN & @CRLF & "Seconds = " & @SEC & @CRLF & @CRLF & @HOUR & ":" & @MIN & ":" & @SEC)

Func _Month()
    Dim $Months[12]
    $Months[1] = "Jan"
    $Months[2] = "Feb"
    $Months[3] = "Mar"
    $Months[4] = "Apr"
    $Months[5] = "May"
    $Months[6] = "Jun"
    $Months[7] = "Jul"
    $Months[8] = "Aug"
    $Months[9] = "Sep"
    $Months[10] = "Oct"
    $Months[11] = "Nov"
;~     $Months[12] = "December"

_ArrayDisplay ($Months)

    $MonthName = $Months[@MON]
    ;MsgBox(0,"Month Born","You were born in the month of " & $MonthName)
    Return $MonthName
EndFunc

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

So in AutoIt there is a position [0] in their arrays? That is why it was giving me errors. If I do not put a value in [0] will that cause me problems later?

I knew it was something simple.

Thanks iamtheky for the help.

Link to comment
Share on other sites

You can safely ignore the first element [0] if you want. But remember it is there even if you are not using it. For example when you use Ubound() to get the size of the array it will include [0] in the count. And if you want an array with n elements (not counting 0), you have to declare it with n+1 elements.

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...