Jump to content

StringSplit and several results in one


yton
 Share

Recommended Posts

Greetings,

the example here (http://www.autoitscript.com/autoit3/docs/functions/StringSplit.htm) says:

$days = StringSplit("Sun,Mon,Tue,Wed,Thu,Fri,Sat", ",")

;$days[1] contains "Sun" ... $days[7] contains "Sat"

I wonder, if it is possible to use a piece of array and return SEVERAL results

e.g. Wed,Thu,Fri,Sat as a one result

smth like $days[3-7]

?

thanks,

Link to comment
Share on other sites

The same functions! What in the helpfile makes you believe that these functions are limited in such way?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

  • Moderators

yton,

if I have more than 7 results?

Go and read the Help file for _ArrayToString and pay particular attention to the $iEnd parameter. :idea:

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

The same functions! What in the helpfile makes you believe that these functions are limited in such way?

the reality :idea:

that's the part of my script:

21 $array = StringSplit(ClipGet(), "ZZZ", 1)
22 MsgBox(0, "Clipboard contains:", $array[3])
23 For $i = 1 To 7 ;Loop
24  _ExcelWriteCell($oExcel, $array[$i], $i, 15)
25 Next

it works fine

but if i try to increase loops form 7 to 10 (fill in 10 cells in a column), it sends me an error message, saying

error: array variable has incorrect number of subscripts or subscript dimension range exceeded (about line 22)

and, of course, excel remains empty

loops 1 to 7 work fine

that's why i'm puzzled

Edited by yton
Link to comment
Share on other sites

  • Moderators

yton,

You need to match the loop upper limit to the number of elements in the array. :)

When you use StringSplit, "the first element ($array[0]) contains the number of strings returned" (from the Help file). So you need to set your loop to that value:

; Get the array
$array = StringSplit(ClipGet(), "ZZZ", 1)
MsgBox(0, "Clipboard contains:", $array[3])
; Now set the loop to run through the elements that exist
For $i = 1 To $array[0]
    _ExcelWriteCell($oExcel, $array[$i], $i, 15)
Next

That should prevent the error. But if I were you , I would add a check to make sure that you actually have an array. :(

I hope that helps. Ask if anything is unclear. :idea:

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

problem found

i checked the input data, put it in the clipboard ad then manually put in excel

it splitted my array (supposed to be 1 row) in 3 rows because initial array was supposedly too big for it

however, when i split the array into strings, i request to show me the array(N) - small piece of data, not the whole array

and each cell is filled in with small $array[N], not the whole data input

now, i am puzzled again - why the script shows error?

Edited by yton
Link to comment
Share on other sites

No code, only guesswork! Remember that AutoIt arrays are zero-based, which means that an array of 5 elements like Local $Arr[5] = ['a', 'b', 'c', 'd', 'e'] has $Arr[0] = 'a' and $Arr[4] = 'e' (accessing $Arr[5] gives an error).

Is that related to your problem?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

No code, only guesswork! Remember that AutoIt arrays are zero-based, which means that an array of 5 elements like Local $Arr[5] = ['a', 'b', 'c', 'd', 'e'] has $Arr[0] = 'a' and $Arr[4] = 'e' (accessing $Arr[5] gives an error).

Is that related to your problem?

actually, no

1) i call 50 arrays and ask to show me the 5th array' content and the error message pops out

2) i test the script with 50 arrays but i cut each array so that it has has far less data

and the script works fine...

i even use

$array = StringSplit(ClipGet(), "ZZZ", 1)
_ArrayToClip($array, 1)
MsgBox(0, "_ArrayToClip() Test", $array[5])

and it fails in the first case

Edited by yton
Link to comment
Share on other sites

Without a solid clipboard content to test, we're talking thin air.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Length of cell contents (text) 32,767 characters. Only 1,024 display in a cell; all 32,767 display in the formula bar.

- that's what excel faq says

perhaps, this is a problem?

it seems to me that I face somewhat internal limitation

but why in this case the _ArrayToClip does not work as well?

Link to comment
Share on other sites

Without a solid clipboard content to test, we're talking thin air.

checked stats in word - my whole input data is about 70000 chars

will it solve the problem if I send you 15-paged word doc?

Link to comment
Share on other sites

yton,

You have me lost. I can't understand clearly what you're talking about nor what your actual problem really is.

Form a table of day names, we went to clipboard copies of Excel large (too large?) cells, then to a 70Kb Word document and still I can't say which problem you encounter.

Please try to post sample simple code that demonstrates a problem or behavior you don't expect, along with the data which causes it, so we can reproduce/diagnose/explain.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

ok

perhaps, it's my fault (messy situation explanation)

1) I used the example script with day names to understand how StringSplit works

2) then I tried to combine it with _ExcelWriteCell - and it was ok

3) then I decided to apply this script to my needs - split big text in strings and paste each string in the corresponding excel cell - and it was ok as I used only 7 (number is randomly chosen) strings (results) to test my script.

However, when I used 10 results, the script started to show error

4) I checked manually the script part responsible for data input - it ended with send(^a^c) - so I pasted in in excel

and excel divided my text string into 3 (the clipboard was filled in 3 rows, not 1)

5) after that i read about length of excel cell contents (text) limitation (32,767 characters)

6) so i made a conclusion that excel cuts my strings and it causes errors of autoit.

after checking how the script work with less text amount, i was absolutely confident in it.

so, the question is: why autoit returns error if all operations are not handled in excel but in the clipboard?

why if i use

$array = StringSplit(ClipGet(), "ZZZ",

_ArrayToClip($array,

MsgBox(0, "_ArrayToClip() Test", $array[5])

it returns me an error again?

and what's the solution?

#include <IE.au3>
#include <Excel.au3>
#include <Word.au3>
#include <ClipBoard.au3>
#include <Array.au3>

; i get data from the clipboard here and set flags in the text for further StringSplit
$oWordapp = _WordCreate("Z:\_script\content2.doc")
$activate1 = WinGetTitle("content2.doc - Microsoft Word")
WinActivate($activate1)
Send("^v")
$oDoc = _WordDocGetCollection($oWordapp, 0)
$oFind = _WordDocFindReplace($oDoc, "<br><br>^p", "ZZZ")
$oFind = _WordDocFindReplace($oDoc, "^p", "")
Send("^a^c")
_WordQuit($oWordapp, 0)

$oExcel = _ExcelBookOpen("Z:\_script\content.csv")
_ExcelSheetActivate($oExcel, "content")

$array = StringSplit(ClipGet(), "ZZZ", 1)
MsgBox(0, "Clipboard contains:", $array[4])
For $i = 1 To $array[0] ;Loop
    _ExcelWriteCell($oExcel, $array[$i], $i, 15)
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...