Sign in to follow this  
Followers 0
thepip3r

Quick Question about Ubound

7 posts in this topic

Ok... So I'm trying to read a file and check whether or not there's any contents in it. If there's not, my script creates the file but when it does this (and I've verified there's no contents in the file), my Ubound is still returning a 2 and I'm not sure why. I've tried every way I can think of to try and see what exactly is in the array that's causing Ubound to read a 2, but have failed miserably. Can anyone give me some advice as far as if they can see what I'm doing wrong with evaluating the array OR why an empty file being read into an array is reading 2 elements??

$progConfDir    = @ScriptDir & "\bin"
$progConfCustom = $progConfDir & "\custom.csv"

If Not FileExists($progConfCustom) Then 
    $null = FileOpen($progConfCustom, 1+8)
    If $null = -1 Then  errHandler(100,"Error Opening File", "An error occurred while trying to open " & $progConfCustom & ".")
EndIf



_ArrayDisplay($arrCustom)

If IsArray($arrCustom) Then MsgBox(0,"","True")

MsgBox(0,"",Ubound($arrCustom))

For $elem In $arrCustom
    MsgBox(0,"",$elem)
Next

My Additions:- RunAs AdminDeviant Fun:- Variable Sound Volume

Share this post


Link to post
Share on other sites



Ok... So I'm trying to read a file and check whether or not there's any contents in it. If there's not, my script creates the file but when it does this (and I've verified there's no contents in the file), my Ubound is still returning a 2 and I'm not sure why. I've tried every way I can think of to try and see what exactly is in the array that's causing Ubound to read a 2, but have failed miserably. Can anyone give me some advice as far as if they can see what I'm doing wrong with evaluating the array OR why an empty file being read into an array is reading 2 elements??

$progConfDir    = @ScriptDir & "\bin"
$progConfCustom = $progConfDir & "\custom.csv"

If Not FileExists($progConfCustom) Then 
    $null = FileOpen($progConfCustom, 1+8)
    If $null = -1 Then  errHandler(100,"Error Opening File", "An error occurred while trying to open " & $progConfCustom & ".")
EndIf



_ArrayDisplay($arrCustom)

If IsArray($arrCustom) Then MsgBox(0,"","True")

MsgBox(0,"",Ubound($arrCustom))

For $elem In $arrCustom
    MsgBox(0,"",$elem)
Next
Hi,

You probably have an emty line in the file; so post the file for a look!

$ar[0]=1

$ar[1]=""

ubond($ar)=2

Best, Randall

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

why an empty file being read into an array is reading 2 elements??

just a guess, Maybe the file has some spaces or more than 1 lines in it. Autoit is stupid & reads all spaces etc... So a suggestion, better check for file size

_If Size = 0Bytes then
     File empty 
Else
     _ArrayDisplay($conteents of the file)
Edited by goldenix

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

that's what i'm saying tho... i'm deleting the file and having it be recreated by my script:

$progConfDir    = @ScriptDir & "\bin"
$progConfCustom = $progConfDir & "\custom.csv"

If Not FileExists($progConfCustom) Then 
    $null = FileOpen($progConfCustom, 1+8)
    If $null = -1 Then  errHandler(100,"Error Opening File", "An error occurred while trying to open " & $progConfCustom & ".")
EndIf

...so basically, because of this... it should be completely blank right? ...yet it's still reading a Ubound of 2!!?!

Edited by thepip3r

My Additions:- RunAs AdminDeviant Fun:- Variable Sound Volume

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I dont get it what exactly you are trying to do?

you want to check if file is empty? so you use if file size is 0 bytes = empty

& then you want to delete this empty file & make new one using?:

$file = FileOpen("test.txt", 1)
FileClose($file)
Edited by goldenix

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Ok... here's the whole subset of code... what I'm trying to accomplish here is a simple check to see if the file exists and whether it has contents in it or not. If the file doesn't exist, I'm automatically creating the file. If it does exist, I'm trying to load the file into an array so I can manipulate the data therein. The problem is that when the file is blank (opened to verify it's blank, check file size and it's reading 0 bytes, and also delete the file so the script recreates the file with 0 data in it) or first created (and thus, should be blank), my array reading functions are erroring out stating: "Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded." -- And this error only comes up when the files is empty... when data is in it, the script runs great.

$progConfDir    = @ScriptDir & "\bin"
$progConfCustom = $progConfDir & "\custom.csv"

If Not FileExists($progConfCustom) Then 
    $null = FileOpen($progConfCustom, 1+8)
    If $null = -1 Then  errHandler(100,"Error Opening File", "An error occurred while trying to open " & $progConfCustom & ".")
EndIf

MsgBox(0,"",FileGetSize($progConfCustom))
; Load the Custom Files into an array from the custom CSV
Dim $arrCustom
_FileReadToArray($progConfCustom, $arrCustom)
If @error Then 
    errHandler("10","Error Loading File","Error occurred trying to load " & $progConfCustom & ".  ")
EndIf

_ArrayDisplay($arrCustom)
If IsArray($arrCustom) Then MsgBox(0,"","True")
MsgBox(0,"",Ubound($arrCustom))
;For $elem In $arrCustom
;   MsgBox(0,"",$elem)
;Next
Edited by thepip3r

My Additions:- RunAs AdminDeviant Fun:- Variable Sound Volume

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

does this help? Ah jaa I tested it with empty file & i get no errors. Bttw why you need Uboundhire I dont get it.. seems to be useless, try to do it without Ubound.

#include <file.au3>
#include <Array.au3>

; File cant be Empty, there is always atleast 1 line
; $aRecords[0] - First array line, Starting count from [0] shows the nr. of the lines in the file 
; $aRecords[1] - second line of the array shows the contents of the first line, [2] second line etc...

Dim $aRecords,$y
If Not _FileReadToArray("test.txt",$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf

For $x = 1 to $aRecords[0]
If $aRecords[$x] = '' Then $y += 1
Next

MsgBox(4096,"",'Lines in the file: ' & $aRecords[0] & @CRLF & 'Empty lines: ' & $y)
 
_ArrayDisplay($aRecords, "Class List of Active Window")
Edited by goldenix

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

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