Jump to content

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****

 

Link to comment
Share on other sites

  • Moderators

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

 

Link to comment
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

 

Link to comment
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

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

Link to comment
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

Link to comment
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

 

Link to comment
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

 

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

×
×
  • Create New...