Jump to content

Annoying Arrays


Recommended Posts

Hello everyone, right now, I am making a few programs, one of which is a variable manager. What I am trying to do, I hope, will seem quite obvious, as I hope will be what I am doing wrong.

Local $a=0
    Do
        $a+=1
        _GUICtrlListView_AddItem($VariableDialoge, $Variables[$a])
    Until $a = UBound($Variables)

Does anybody have any ideas on what I am doing wrong?

Also, just to clear up a little bit, I cannot add an array to this list view to the best of my knowledge, because my array is in this format - $Variables[x] and not in the format $Variables[x][y]. (Is that what is meant by 1D and 2D by the way? Thanks).

Can anybody sopt what I am doing wrong here? Thanks. Hopefully, I will start helping more people with whatever I can soon, instead of leeching off all of you. I'm still learning and I have a far way to go so if I am doing something that seems illogical, go ahead and have a laugh, but please help me where you can. Hopefully, soon, I can and will start to help people.

Thanks for any help people. Cya all later.

Link to comment
Share on other sites

Hello everyone, right now, I am making a few programs, one of which is a variable manager. What I am trying to do, I hope, will seem quite obvious, as I hope will be what I am doing wrong.

Local $a=0
    Do
        $a+=1
        _GUICtrlListView_AddItem($VariableDialoge, $Variables[$a])
    Until $a = UBound($Variables)

Does anybody have any ideas on what I am doing wrong?

Also, just to clear up a little bit, I cannot add an array to this list view to the best of my knowledge, because my array is in this format - $Variables[x] and not in the format $Variables[x][y]. (Is that what is meant by 1D and 2D by the way? Thanks).

Can anybody sopt what I am doing wrong here? Thanks. Hopefully, I will start helping more people with whatever I can soon, instead of leeching off all of you. I'm still learning and I have a far way to go so if I am doing something that seems illogical, go ahead and have a laugh, but please help me where you can. Hopefully, soon, I can and will start to help people.

Thanks for any help people. Cya all later.

An array has UBound elements, but th efirst is [0] and the last is [uBound($var) - 1]

So

Local $a=0
    Do
        _GUICtrlListView_AddItem($VariableDialoge, $Variables[$a])
        $a+=1
    Until $a = UBound($Variables)

Or

Local $a=0
    while $a < UBound($Variables)
        _GUICtrlListView_AddItem($VariableDialoge, $Variables[$a])
        $a+=1
    wend

Or

Local $a
    for $a = 0 to UBound($Variables) - 1
        _GUICtrlListView_AddItem($VariableDialoge, $Variables[$a])
    next
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • Moderators

Mikeman27294,

I suggest you use a For...Next loop like this:

For $a = 0 To UBound($Variables) - 1
    _GUICtrlListView_AddItem($VariableDialoge, $Variables[$a])
Next

Much easier to code that way. ;)

And before you ask: :alien:

I assume your array runs from the first element [0] like this:

[0] - value 1
[1] - value 2
[2] - value 3

UBound will return 3 (as you have 3 elements) but you need to use [0] to [2] - hence For $a = 0 To UBound($Variables) - 1

But rememeber that if you get your array from a an AutoIt function like FileListToArray or StringSplit, you usually get the count in the [0] element array so you could use For $a = 1 To $Variables[0] to do the same thing.

All clear? :huh2:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks guys, atleast now it is reporting back (Using Melba23's for...to...next script). The only problem is that it is returning only "1", and none of these variables. Would it be that $a isnt increasing by 1 and needs $a+=1 to be placed into the script, or would it automatically do that? Thanks.

Link to comment
Share on other sites

Using the "for.. to" construct as M23 demonstrated will iterate through all the elements of the array.

$i+=1 is not needed because after the "to" in "for...to", Step 1 is implied (unless otherwise specified) :huh2:

Lookup "for..to" in the helpfile for more details.

Edit:Grammar

Edited by smartee
Link to comment
Share on other sites

Also not strictly on-topic, but when it comes to re-sizing your Arrays for whatever reason I suggest reading this post >> it's not a Function but information about being smart(ee) with Arrays.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • Moderators

Mikeman27294,

Add this to your script to see what is in your array and whether you are extracting the elements correctly: :)

; Put this at the top of your script
#include <Array.au3>

; And use this for the loop code
If IsArray($Variables) Then
    _ArrayDisplay($Variables, "$Variables")
Else
    MsgBox(0, "Error", "$Variables is not an array!")
EndIf
For $a = 0 To UBound($Variables) - 1
    ConsoleWrite("Element " & $a & " = " & $Variables[$a] & @CRLF)
Next

You should see a dialog appear which holds the whole array so you can check if the contents are what you expect - if $Variables is not an array, you will get an Error MsgBox. Assuming all is well you will then get a list of the individual elements appearing in the SciTE console. :alien:

If you do not get this then we need to look at how you are filling the array and why you are not getting what you want. :ph34r:

As several responders over the past few days have mentioned, it is ususal to provide a reasonable amount of code to debug when you ask for help. All you ever provide are small snippets which do not offer a lot to work on. I have also pointed out that short, staccato posts such as your one immediately above are of absolutely no use at all - what can we deduce from:

I found "for... to... step... next" but when I added that in to my script, that didnt work either

other than the code does not work? Have you made a syntax error? Have you declared the variables you are using? What error message did you get, if any? What returned "1"? If you do not provide code, the least you can do is explain in detail why you feel the code is not working as you wish and what symptoms you get. ;)

As with all newcomers to this forum, I am very happy to help you learn about AutoIt and to debug your script - that is one reason I am here after all. But if you carry on in this vein I will consider seriously whether I am prepared to continue offering assistance to someone who makes no effort to help those ready to help him. :huh2:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks for that little line of code. The array is set to one, which means that I have to re-assess that other function which places those variables in an array.

EDIT

Awesome, I figured out that other little problem, quite simple... it was not pointing to the file to read from properly. Thank you guys, I honestly could not have got this working without your help.

Edited by Mikeman27294
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...