Sign in to follow this  
Followers 0
meatsack

How to Increase amount of data converted array to string

3 posts in this topic

Is there a way to encrease the amount of data converted from array to string? I that that is the impediment I am having to enabling my program to read columns 2-20 and rows 1-5. I imagine each variable has a limitation to the amount of characters I can pass. Thanks for any help.

;##################################
; Include
;##################################
#Include<file.au3>
#include <Excel.au3>
#include <Array.au3>
#include <String.au3>


;##################################
; Variables
;##################################
Dim $aArray2d
Dim $Body
Dim $zString

$sFilePath1 = @ScriptDir & "\test.xls" ;This file should already exist
$oExcel = _ExcelBookOpen($sFilePath1)
$aArray2d = _ExcelReadSheetToArray($oExcel, 2, 2, 3, 3)
Local $aArray1D = _Array2DTo1D($aArray2d)

_ArrayDisplay($aArray1D)


Func _Array2DTo1D($aTwo_d)
    If UBound($aTwo_d, 0) <> 2 Then
        MsgBox(0, "Error", "Array not 2 dimensional")
        Return
    EndIf
    Local $iRow = UBound($aTwo_d)
    Local $iCol = UBound($aTwo_d, 2)
    Local $aOne_d[$iRow * $iCol]

    For $i = 0 To $iRow - 1
        For $j = 0 To $iCol - 1
            $aOne_d[$i * $iCol + $j] = $aTwo_d[$i][$j]
        Next
    Next
    Return $aOne_d
EndFunc   ;==>_Array2DTo1D
;




$zString = _ArrayToString($aArray1D)

$SmtpServer = "smtp.gmail.com"              ; address for the smtp-server to use - REQUIRED
$FromName = "john@gmail.com"                      ; name from who the email was sent
$FromAddress = "john@gmail.com" ; address from where the mail should come
$ToAddress = "doe@gmail.com"   ; destination address of the email - REQUIRED
$Subject = "Userinfo"                   ; subject from the email - can be anything you want it to be
$Body =    $zString               ; the messagebody from the mail - can be left blank but then you get a blank mail
$AttachFiles = ""                       ; the file you want to attach- leave blank if not needed
$CcAddress = ""       ; address for cc - leave blank if not needed
$BccAddress = ""     ; address for bcc - leave blank if not needed
$Importance = "Normal"                  ; Send message priority: "High", "Normal", "Low"
$Username = "john"                    ; username for the account used from where the mail gets sent - REQUIRED
$Password = "password"                  ; password for the account used from where the mail gets sent - REQUIRED
$IPPort = 465                            ; port used for sending the mail
$ssl = 1                                ; enables/disables secure socket layer sending - put to 1 if using httpS

;~ $IPPort=465                          ; GMAIL port used for sending the mail
;~ $ssl=1                               ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS

;##################################
; Script
;##################################
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
$rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
If @error Then
    MsgBox(0, "Error sending message", "Error code:" & @error & "  Description:" & $rc)
EndIf
;
; The UDF
_ArrayDisplay($Body)
Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
    Local $objEmail = ObjCreate("CDO.Message")
    $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
    $objEmail.To = $s_ToAddress
    Local $i_Error = 0
    Local $i_Error_desciption = ""
    If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
    If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
    $objEmail.Subject = $s_Subject
    If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then
        $objEmail.HTMLBody = $as_Body
    Else
        $objEmail.Textbody = $as_Body & @CRLF
    EndIf
    If $s_AttachFiles <> "" Then
        Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
        For $x = 1 To $S_Files2Attach[0]
            $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
            ConsoleWrite('@@ Debug(62) : $S_Files2Attach = ' & $S_Files2Attach & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
            If FileExists($S_Files2Attach[$x]) Then
                $objEmail.AddAttachment ($S_Files2Attach[$x])
            Else
                ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
                SetError(1)
                Return 0
            EndIf
        Next
    EndIf
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
    If Number($IPPort) = 0 then $IPPort = 25
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
    ;Authenticated SMTP
    If $s_Username <> "" Then
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
    EndIf
    If $ssl Then
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    EndIf
    ;Update settings
    $objEmail.Configuration.Fields.Update
    ; Set email Importance
    Switch $s_Importance
        Case "High"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High"
        Case "Normal"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal"
        Case "Low"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low"
    EndSwitch
    $objEmail.Fields.Update
    ; Sent the Message
    $objEmail.Send
    If @error Then
        SetError(2)
        Return $oMyRet[1]
    EndIf
    $objEmail=""
EndFunc   ;==>_INetSmtpMailCom
;
;
; Com Error Handler
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description, 3)
    ConsoleWrite("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & $oMyRet[1] & @LF)
    SetError(1); something to check for when this function returns
    Return
EndFunc   ;==>MyErrFunc

_ExcelBookClose($oExcel, 1, 0)

Share this post


Link to post
Share on other sites



Based upon the below quote, I take it my draft script can easily handle the 2 pages of data I want to process. Therefore, the problem with my script is that I am not processing the array and array transfer in a way that enables all my 2 pages to be copied and passed from array then processed by _ArrayToString then finally passed to a string variable, no?

Handling big files keep in mind the string size limit :mellow:... as far as I remember it depends on the installed memory size, on my notebook this code. . . kicked me out at ~ 236 MB with an "Error allocating memory".

According to help-file also Maximum string length is 2.147.483.647 characters (if you've got enough spare RAM :().

Share this post


Link to post
Share on other sites

It's still unclear what your problem is. Does your script terminate with a memory shortage error, crash or what? What free memory do you have for this script?

By the way, I just glanced at it so I may miss something. If your goal is just to read your 2-D spreadsheet and flatten it as a string, you don't need to do it this way. If you're short on RAM, why not adapt the _ExcelRead thing to produce directly a string with the style of cell and row separators you need?

Also if you want to save memory, pass large objects Byref and don't forget to destroy the large arrays you've been using as soon as they are no more needed.

Hint: avoid mixing main code and functions, that will make you code much more readable.


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)

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
Sign in to follow this  
Followers 0