Sign in to follow this  
Followers 0
simy8891

Weird thing or just blind?

2 posts in this topic

#1 ·  Posted (edited)

Hi guys,

I'm either going crazy or AutoIT is.. :D

Basically I need to get to the parent folder of @scriptdir, to do that, I used:

$parentFolder=StringLeft(@ScriptDir, StringInStr(@ScriptDir, "\", 0, -1)) 

So far, all good. When I use MsgBox to show $parentfolder, I'm indeed able to see the folder above @scriptdir. Now, I've added a subfolderfile to the string with:

$PPID_Bulk_Big_printers_csv_path=$parentFolder&'Printers\printers_PPID_Big.csv' 

And also here, all fine, MsgBox shows me the file location correctly.

Now, for some weird reason, $PPID_Bulk_Big_printers_csv_path changes again!

See the complete part of the script below:

; CSV to 2D array
    $parentFolder=StringLeft(@ScriptDir, StringInStr(@ScriptDir, "\", 0, -1)) ;Goes one folder up
    MsgBox(0,'',@ScriptDir&'----'&$parentFolder&'Printers\printers_PPID_Big.csv')
    $PPID_Bulk_Big_printers_csv_path=$parentFolder&'Printers\printers_PPID_Big.csv' ;CSV location

    Dim $PPID_Bulk_Big_printers

    $PPID_Bulk_Big_filereadtoarray_result = _FileReadToArray($PPID_Bulk_Big_printers_csv_path, $PPID_Bulk_Big_printers) ;$PPID_Bulk_Big_filereadtoarray_result will contain any error (if there's any) - $printers is an array which contains the list of printers
MsgBox(0,'',$PPID_Bulk_Big_printers_csv_path) ; Still shows correct path
    ;Check if there was any error with the _FileReadToArray
        If $PPID_Bulk_Big_filereadtoarray_result <> 0 Then ;If no error reading the file

;Do Something
            
        Else ;If there was an error reading the CSV file
MsgBox(0,'hhh',"msg="&$PPID_Bulk_Big_printers_csv_path)
            MsgBox(48,'Problem detected!','The file "'&$PPID_Bulk_Big_printers_csv_path&'" was not found. Software will exit!')
            Sleep (50)
            Exit

        EndIf

So what's happening here is, I'm getting into the ELSE part of the script, so there was an error with reading the file and I'm getting indeed the message box with "Problem detected!" but NOT the message box above?? Why?

Cheers :)

Edited by simy8891

Share this post


Link to post
Share on other sites



All, please disregard and close the topic.

I was just blind: there are more functions down below in the script with a similar .csv file name, so it was complaining about the other and not this function.

Basically it's a script I've made a few months ago that I'm not re-elaborating so it took me a while to figure out what passed in my mind such a long time ago.

Thanks

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

  • Similar Content

    • TrashBoat
      By TrashBoat
      How do i add a path to a file in Include.
      I want my script to get the udf in the same folder as the script/exe:
      Include "@ScriptDir/udf.au3" can this be done?
    • fopetesl
      By fopetesl
      Attempting to extract data from CSV file to display in _ExtMsgBox, sometimes it works fine but mostly it fails with Error:
      3 - File lines have different numbers of fields (only if $FRTA_INTARRAYS flag not set) I have tried all the available $iFlags combinations without success.
      The CSV file format is fixed for any data collected, sample attached. The two CSV MsgBox() show correct file name
      $sText = "" Global $aLines, $fFile, $fLine, $fFcopy $fFile = FileOpen ( "QuickPlotData.dat", 0 ) ; find current CSV file $fLine = FileReadLine ( $fFile ) ; read correct CSV file name MsgBox(0,"CSV file: ", $fLine) ; Read file to 2D array MsgBox(0,"CSV[2] file: ", $fLine) ; _FileReadToArray($fLine, $aLines) ; 'simple' call _FileReadToArray($fLine, $aLines,$FRTA_NOCOUNT+$FRTA_ENTIRESPLIT,',') If @error Then MsgBox($MB_SYSTEMMODAL, "ERROR!", "CSV read error " & @error) exit(0) EndIf _ArrayDisplay($aLines)  
      ZZj2_Test.Won.Two.csv
    • timmy2
      By timmy2
      I figure there must be a reason for _FileReadToArray to exist when FileReadToArray can already read an entire text file into an array, but I don't understand the _FileReadToArray examples in the Help File.  The threads about _FileReadToArray here in the forum all seem to end up using StringSplit to work with delimiters, yet _FileReadToArray has some sort of built-in delimiter capability. 
      Here's where I was hoping _FileReadToArray might be applicable.  Let's assume the text file I wish to read into my script is like this:
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras hendrerit tristique purus quis eleifend. @@ Maecenas interdum dui in magna tincidunt, eget imperdiet tellus ornare. * Fusc * blandit * tellu * metus Nulla nec blandit ligula. @@ Fusce nec rhoncus enim. Cras facilisis velit velit, in fringilla felis porttitor sed. Cras vel nisi lobortis, vestibulum justo quis, lacinia est. Maecenas eu dolor ac est posuere semper a a enim. I would like to import the text file into a 1D array, with the @@'s used as delimiters.  So in this example the resulting 1D array would have 3 elements in it. Note that I want to retain the formatting and line endings (CRLF's).
      Can _FileReadToArray be used to accomplish this on its own?
      Thank you.
    • VIP
      By VIP
      CSV1:
      "Index","Name","Home Address","Last Love" "1","Rola Takizawa","Nữ hoàng, Nga Nhật","24/04/2016 22:37:00 PM" "2","Saori Hara","Hình Ảnh Nóng, Đức Nhật","21/03/2016 21:07:00 PM" "3","Ozawa","phổ biến nhất","23/04/2016 23:31:00 PM" "3","Akiho Ameri Ichinose","Kanagawa, Ameri, Ichinose","22/04/2016 21:50:00 PM"  
      CSV2:
      Index,Name,Home Address,Last Love 1,Takizawa,"Nữ hoàng, Nga Nhật","24/04/2016 22:37:00 PM" 2,"Saori Hara","Hình Ảnh Nóng, Đức Nhật","21/03/2016 21:07:00 PM" 3,Ozawa,"phổ biến nhất","23/04/2016 23:31:00 PM" 3,"Akiho Ameri Ichinose","Kanagawa, Ameri, Ichinose","22/04/2016 21:50:00 PM"  
      CSV3:
      Index,Name,Home Address,Last Love 1,Takizawa,"Nữ hoàng, Nga Nhật",24/04/2016 22:37:00 PM 2,Saori Hara,"Hình Ảnh Nóng, Đức Nhật",21/03/2016 21:07:00 PM 3,Ozawa,phổ biến nhất,23/04/2016 23:31:00 PM 3,Akiho Ameri Ichinose,"Kanagawa, Ameri, Ichinose",22/04/2016 21:50:00 PM ---------------------------------------------------------------------------------- Global $CSV3 = 'Index,Name,Home Address,Last Love' & @CRLF $CSV2 &= '1,Takizawa,"Nữ hoàng, Nga Nhật",24/04/2016 22:37:00 PM' & @CRLF $CSV2 &= '2,Saori Hara,"Hình Ảnh Nóng, Đức Nhật",21/03/2016 21:07:00 PM' & @CRLF $CSV2 &= '3,Ozawa,phổ biến nhất,23/04/2016 23:31:00 PM' & @CRLF $CSV2 &= '3,Akiho Ameri Ichinose,"Kanagawa, Ameri, Ichinose",22/04/2016 21:50:00 PM' & @CRLF  
      Does not work when have more ","
      #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <GUIListView.au3> #include <Array.au3> #include <File.au3> Global $CSV1 = '"Index","Name","Home Address","Last Love"' & @CRLF $CSV1 &= '"1","Rola Takizawa","Nữ hoàng, Nga Nhật","24/04/2016 22:37:00 PM"' & @CRLF $CSV1 &= '"2","Saori Hara","Hình Ảnh Nóng, Đức Nhật","21/03/2016 21:07:00 PM"' & @CRLF $CSV1 &= '"3","Ozawa","phổ biến nhất","23/04/2016 23:31:00 PM"' & @CRLF $CSV1 &= '"3","Akiho Ameri Ichinose","Kanagawa, Ameri, Ichinose","22/04/2016 21:50:00 PM"' & @CRLF Global $CSV2 = "Index,Name,Home Address,Last Love" & @CRLF $CSV2 &= "1,Takizawa,'Nữ hoàng, Nga Nhật','24/04/2016 22:37:00 PM'" & @CRLF $CSV2 &= "2,'Saori Hara','Hình Ảnh Nóng, Đức Nhật','21/03/2016 21:07:00 PM'" & @CRLF $CSV2 &= "3,Ozawa,'phổ biến nhất','23/04/2016 23:31:00 PM'" & @CRLF $CSV2 &= "3,'Akiho Ameri Ichinose','Kanagawa, Ameri, Ichinose','22/04/2016 21:50:00 PM'" & @CRLF Local $hOpen=FileOpen("CSV1.csv",128) FileWrite($hOpen,$CSV1) FileClose($hOpen) Local $hOpen=FileOpen("CSV2.csv",128) FileWrite($hOpen,$CSV2) FileClose($hOpen) Global $rArrayCSV1,$rArrayCSV2 Local $ArrayCSV1 = _FileReadToArray("CSV2.csv", $rArrayCSV1, Default,',') ConsoleWrite( $ArrayCSV1 & ' - ' & 'error = ' & @error & @CRLF) _ArrayDisplay($rArrayCSV1) Local $ArrayCSV2 = _FileReadToArray("CSV2.csv", $rArrayCSV2, Default,',') ConsoleWrite( $ArrayCSV2 & ' - ' & 'error = ' & @error & @CRLF) _ArrayDisplay($rArrayCSV2)  
    • TThomasson
      By TThomasson
      Hi everyone. New guy here. I'm still learning this awesome language and I'm unable to figure this one out from google searches. Heres my problem:
      I'm working on a small application to help users in my environment connect to wireless projectors. To keep this easily updated with new projectors I'm reading the room names and IP addresses from a csv file and putting them into a 2D array. (MeetingRoom1,xxx.xxx.xxx.xxx)
      So far I'm able to read the 0 column and display the room names in a combo box. Where I am stuck is how to take the user's room selection from the gui and associate it with an IP address in the array. After that point I've got things prepared to pass the address to the connection application.  
      Any help you all could provide would be greatly appreciated.