Jump to content

Show array in MsgBox instead of ConsoleWrite


Recommended Posts

I would appreciate if someone show how to convert the result of this code to string and to show the result in MsgBox.

Local $aCheck[10] = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
Local $aIgnore[3] = ["b", "d", "g"]

For $j = 0 To UBound($aCheck) - 1
    ; Get the next item in the array to check
    $sItem = $aCheck[$j]
    ; Set a flag
    $fValid = True
    ; Now loop through the exceptions
    For $i = 0 To UBound($aIgnore) - 1
        ; If it matches clear the flag
        If $sItem == $aIgnore[$i] Then
            $fValid = False
        EndIf
    Next
    ; If the flag is set it is a valid item
    If $fValid Then ConsoleWrite($aCheck[$j] & @CRLF)
Next

I tried this with no luck:

$Result = _ArrayToString($aCheck[$j], ", ", 1)

 

Link to comment
Share on other sites

  • Moderators

Technically, just putting a MsgBox in place of the ConsoleWrite works just fine; you get one MsgBox per letter in your for loop, just like consolewrite is outputting one letter per cycle through the loop:

image.png.038abe36f6b1a6c4487c01e08958dff3.png

I am guessing, though, what you mean is that you're after one MsgBox at the end with the entire string, something like this:

#include <MsgBoxConstants.au3>

Local $aCheck[10] = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
Local $aIgnore[3] = ["b", "d", "g"]
$sString = ""

For $j = 0 To UBound($aCheck) - 1
    ; Get the next item in the array to check
    $sItem = $aCheck[$j]
    ; Set a flag
    $fValid = True
    ; Now loop through the exceptions
    For $i = 0 To UBound($aIgnore) - 1
        ; If it matches clear the flag
        If $sItem == $aIgnore[$i] Then
            $fValid = False
        EndIf
    Next
    ; If the flag is set it is a valid item
    If $fValid Then $sString &= $aCheck[$j] & ","
Next

MsgBox($MB_OK, "MyString", StringTrimRight($sString, 1))

image.png.a4c8db0bd7d74a2c3ca8b0e65fd92a4c.png

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

in before the good regexes show up :)

#include<array.au3>

Local $aCheck[10] = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
Local $aIgnore[3] = ["b", "d", "g"]

msgbox(0, '' , stringreplace(stringregexpreplace(_ArrayToString($aCheck , ",") , _ArrayToString($aIgnore) , "") , ",," , ","))

 

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

Link to comment
Share on other sites

Thanks this one is interesting too. Additionally, to make the result shorter, is this the right way or there is a better one?

#include<array.au3>

Local $aCheck[10] = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
Local $aIgnore[3] = ["b", "d", "g"]

$work = stringreplace(stringregexpreplace(_ArrayToString($aCheck , ",") , _ArrayToString($aIgnore) , "") , ",," , ",")
$work_split = StringSplit($work, ",")
$work_array = _ArrayToString($work_split, ", ", 1, 4)
MsgBox($MB_SYSTEMMODAL, "", $work_array)

Exit

 

Edited by prodesigner
Link to comment
Share on other sites

the right way will depend on what the actual data is.  As long as it is single characters and simple criteria you get to choose from 1000s of ways to skin it.

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

Link to comment
Share on other sites

I am trying to get rid of the number 4 in the result, tried adding ,0 or ,1 after $sString &= $aCheck[$j] & "," no luck. 

 

#include <MsgBoxConstants.au3> ; for messages
#include <File.au3> ; for split path
#include <Array.au3> ; for tags


Global $Title = "One time is not enough, two times..."
Global $Title_Lowercase = StringLower($Title)

Local $aCheck = StringSplit("one two three four", " ")
Local $aIgnore = StringSplit($Title_Lowercase, " ")
$sString = ""

For $j = 0 To UBound($aCheck) - 1
    ; Get the next item in the array to check
    $sItem = $aCheck[$j]
    ; Set a flag
    $fValid = True
    ; Now loop through the exceptions
    For $i = 0 To UBound($aIgnore) - 1
        ; If it matches clear the flag
        If $sItem == $aIgnore[$i] Then
            $fValid = False
        EndIf
    Next
    ; If the flag is set it is a valid item
    If $fValid Then $sString &= $aCheck[$j] & ","
Next

MsgBox($MB_OK, "MyString", StringTrimRight($sString, 1))

Exit

 

Link to comment
Share on other sites

It's the return count from your stringsplit, which you can disable with a flag.  Go slow, and use _arraydisplay liberally.

stringsplit.PNG.5872407125ff3e3391de8144c5e5cfd8.PNG

 

  

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

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