Jump to content
bahjat

When an Array isn't full

Recommended Posts

So i am practising AutoIt and i would like to split up a large message into arrays. The problem is that the message can be any number of bits long. Therefore the last array size will not be equal to the others. Can someone please help me on this, i am kind of confused what to do. I want it to recognise the last array so it still works. Please help, i am desperate. If anything needs clearing up i can clear it up. I look forward to hearing from you guys

#include-Once
#include <MsgBoxConstants.au3>
#include <Crypt.au3>


;;****Cutting the message up into manageable pices
;;**Input variable is $VariabletoBecut***

$VariableToBeCut = "1234567891011"
$ArrayForMessage = StringRegExp($VariableToBeCut, ".{2}", 3)

;;****Output variable is $Arrayformessage***

  For $ProcessingMessage = 0 To 28
    $Cut = $ArrayForMessage[$ProcessingMessage]
    MsgBox (0, "counting", $Cut)
 Next


;;;***Output variable is $cut****

 

Share this post


Link to post
Share on other sites

bahjat,

Please pay attention to where you post - the "Dev Chat" section where you started this thread is not for general support questions.  I have moved it for you, but would ask you to be more careful in future.

Use UBound to get the size of the returned array and use that to limit the loop cycles.

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

 

Share this post


Link to post
Share on other sites

bahjat,

Please pay attention to where you post - the "Dev Chat" section where you started this thread is not for general support questions.  I have moved it for you, but would ask you to be more careful in future.

Use UBound to get the size of the returned array and use that to limit the loop cycles.

M23

Ah ok sorry, i will keep that in mind next time i post. I was on the lines of thinking "I am developing my code so better put it on the developing chat section" lol 

​I have been experimenting with the "Redim" function to redetermine the final array but i have had no luck in doing this. I am so stuck on this. 
After using the Ubound function and the Redim function the new code i come up with is stated below. It still doesn't seem to be doing what i want it to do, which is show me the last value (number 7) and that's it. Can you help me please?

#include-Once
#include <MsgBoxConstants.au3>
#include <Crypt.au3>
;;****Cutting the message up into manageable pices
;;**Input variable is $VariabletoBecut***

$VariableToBeCut = "1234567"
$ArrayForMessage = StringRegExp($VariableToBeCut, ".{3}", 3)

;;****Output variable is $Arrayformessage***
  For $ProcessingMessage = 0 To 3
    $Cut = $ArrayForMessage[$ProcessingMessage]
         ReDim $Arrayformessage[UBound($Arrayformessage) + 2];
    MsgBox (0, "counting", $Cut)
Next

 

Share this post


Link to post
Share on other sites

I now read back, and you want to play with arrays.   However, 7 is not returned in that resulting array so that loop would never result with it.

$VariableToBeCut = "1234567"
msgbox(0, '' , StringRegExpReplace($VariableToBeCut, ".{3}" , ""))

 

something like this for ubound is what i would imagine

$VariableToBeCut = "12345678"
$aArray = StringRegExp($VariableToBeCut, ".{2}", 3)
msgbox(0, '' , $aArray[ubound($aArray) - 1])

 

 

 

Edited by boththose

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

Share this post


Link to post
Share on other sites

I now read back, and you want to play with arrays.   However, 7 is not returned in that resulting array so that loop would never result with it.

$VariableToBeCut = "1234567"
msgbox(0, '' , StringRegExpReplace($VariableToBeCut, ".{3}" , ""))

 

something like this for ubound is what i would imagine

$VariableToBeCut = "12345678"
$aArray = StringRegExp($VariableToBeCut, ".{2}", 3)
msgbox(0, '' , $aArray[ubound($aArray) - 1])

 

 

 

​Thank you, your help is much appreciated. I am a very slow learner but i am enjoying this programming language :) .
Once again your help is much appreciated

Share this post


Link to post
Share on other sites

See comments in script.   Hope this helps.

Local $VariableToBeCut = "1234567891011"
;$ArrayForMessage = StringRegExp($VariableToBeCut, ".{2}", 3) ; Will only match 2 characters
$ArrayForMessage = StringRegExp($VariableToBeCut, ".{1,2}", 3) ; Being greedy by default, will match the maximum (2 characters). But will match 1 character when there is only 1 character to match.

For $ProcessingMessage = 0 To UBound($ArrayForMessage) - 1
    $Cut = $ArrayForMessage[$ProcessingMessage]
    ;MsgBox(0, "counting", $Cut)
    ConsoleWrite($Cut & @LF)
Next

 

Share this post


Link to post
Share on other sites

This is one of the nicest codes i have seen written so far, thankyou for your help. It is most appreciated, would it be possible to pick your brain on another problem i am having?

See comments in script.   Hope this helps.

Local $VariableToBeCut = "1234567891011"
;$ArrayForMessage = StringRegExp($VariableToBeCut, ".{2}", 3) ; Will only match 2 characters
$ArrayForMessage = StringRegExp($VariableToBeCut, ".{1,2}", 3) ; Being greedy by default, will match the maximum (2 characters). But will match 1 character when there is only 1 character to match.

For $ProcessingMessage = 0 To UBound($ArrayForMessage) - 1
    $Cut = $ArrayForMessage[$ProcessingMessage]
    ;MsgBox(0, "counting", $Cut)
    ConsoleWrite($Cut & @LF)
Next

 

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

  • Similar Content

    • By Blitzkid
      Hello, i want to search several directories for files with the largest numbers behind them (Like "video123") . They dont have a datatype. But there are also files with longer names and datatypes in these folders (Like "video778.mp4"). Is it possible to filter the _FileListToArray Syntax from
      to smth. like
       
      Here is my Code
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <array.au3> #include <File.au3> $filedir = @ScriptDir & "\" _checkfile() Func _checkfile() ConsoleWrite("______________________" & @CRLF) Local $arr[3] = ["music", "picture", "video"] For $i = 0 To UBound($arr) - 1 Local $arrayfiles = _FileListToArray($filedir & $arr[$i], $arr[$i] & "*", 1) If @error = 1 Then ConsoleWrite($arr[$i] & "Error 1") EndIf If @error = 4 Then ConsoleWrite($arr[$i] & "Error 2") ;Exit EndIf $arrayfilter = _ArrayMax($arrayfiles, 0, 1) Global $stringfiles = StringReplace($arrayfilter, $arr[$i], "") ConsoleWrite($arrayfilter & @CRLF) Next EndFunc ;==>_checkfile  
    • By jmp
      Script running good but error in line 7.
      When i run this script :
      #include <IE.au3> #include <Array.au3> $oIE = _IEAttach ("Shop") $oTable = _IETableGetCollection ($oIE, 1) $aTableData = _IETableWriteToArray ($oTable) For $inumber = 1 To UBound($aTableData) -1 $table = $aTableData[4][$inumber] MsgBox(0, "", $table) Next I got Error: array variable has incorrect number of subscripts or subscript dimension range exceeded
    • By nacerbaaziz
      Good morning guys, i hope that you're all well.
      guys, i have a problem and i hope that you can help me
      i've created an 3d array
      the array Contain a Categories info
      as folow
      $array[n][0][0] = Categorie name
      $array[n][0][1] = Categorie file path
      $array[n][0][2] = Categorie contents number
      $array[n][m][0] = link name
      $array[n][m][1] = link url
      $array[n][m][2] = link section name
      in my tool i want to add an option to delete a Category
      as you know the Categorie mean that must delete a region from the array
      when i tried to use _arrayDelete
      with the 2d array it work well
      but here i couldn't find any way to do that, can any one help me please?
      thanks in advance.
    • By nacerbaaziz
      hello sirs, please help me
      i tried to create a function that read a folder files to 3d array
      e.g
      $array[n][0][0] = ctName
      $array[n][0][1] = ctFilePath
      $array[n][0][2] = crtsections number
      $array[n][m][0] = KeyName
      $array[n][m][1] = KeyVal
      $array[n][m][2] = keySectionName
       
      that the array
      when i put one file into the folder all things work fine
      but when i put more than one file
      the last file worked fine but the others only the first key is showing
      please can you help me to correct this problem
      here is the example with the folder
      please accept my greetings
      and thanks in advance
       
      array3d.zip
    • By nacerbaaziz
      good morning everybody.
      today i liked to share an small example with you
      which it an function to read the registry values as an array
      the result array is 2d array witch
      $a_array[n][0] = value name
      $a_array[n][1] = value Data
      $a_array[0][0] = values count
      here's the function

      #include <Array.au3> #include <WinAPIReg.au3> #include <APIRegConstants.au3> Local $a_array = _RegReadToArray("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run") If @error Then     MsgBox(16, "error", @error)     Exit EndIf _ArrayDisplay($a_array) Func _RegReadToArray($s_RegKey)     Local $a_KeySplitInfo = StringSplit($s_RegKey, "\\", 2)     If UBound($a_KeySplitInfo) <= 1 Then         $a_KeySplitInfo = StringSplit($s_RegKey, "\", 2)         If UBound($a_KeySplitInfo) <= 1 Then Return (1, 1, 0)     EndIf     Local $H_KeyInfo = "", $s_RegKeyInfo = ""     Switch $a_KeySplitInfo[0]         Case "hklm", "HKEY_LOCAL_MACHINE", "hklm64", "HKEY_LOCAL_MACHINE64"             $H_KeyInfo = $HKEY_LOCAL_MACHINE         Case "hkCu", "HKEY_CURRENT_USER", "hkCU64", "HKEY_CURRENT_USER64"             $H_KeyInfo = $HKEY_CURRENT_USER         Case "hkCr", "HKEY_CLASSES_ROOT", "HKCR64", "HKEY_CLASSES_ROOT64"             $H_KeyInfo = $HKEY_CLASSES_ROOT         Case "HKU", "HKEY_USERS", "HKU64", "HKEY_USERS64"             $H_KeyInfo = $HKEY_USERS         Case Else             Return SetError(2, 2, 0)     EndSwitch     _ArrayDelete($a_KeySplitInfo, 0)     $s_RegKeyInfo = _ArrayToString($a_KeySplitInfo, "\")     Local $H_KeyInfoOpen = _WinAPI_RegOpenKey($H_KeyInfo, $s_RegKeyInfo, $KEY_READ)     Local $A_KeyInfo = _WinAPI_RegQueryInfoKey($H_KeyInfoOpen)     If @error Then Return SetError(1, 1, 0)     _WinAPI_RegCloseKey($H_KeyInfoOpen)     Local $A_RegVal[$A_KeyInfo[2] + 1][2]     Local $iV = 1, $s_RegRead = ""     While 1         $s_RegVal = RegEnumVal($s_RegKey, $iV)         If @error <> 0 Then ExitLoop         $s_RegRead = RegRead($s_RegKey, $s_RegVal)         If Not (@error) Then             $A_RegVal[$iV][0] = $s_RegVal             $A_RegVal[$iV][1] = $s_RegRead         EndIf         $iV += 1     WEnd     $A_RegVal[0][0] = UBound($A_RegVal) - 1     If $A_RegVal[0][0] >= 1 Then         Return $A_RegVal     Else         Return SetError(3, 3, 0)     EndIf EndFunc   ;==>_RegReadToArray
      i hope you benefit from it
      with my greetings
×
×
  • Create New...