Jump to content

Recommended Posts

Posted

I have excel sheet as attached and i am getting the values of each cell and doing a concatenation and storing the concatenated values of each row in a 1-D array as per below code:

Local $aArray[200]
 
        For $yrow = 2 to 500  ;this is excel rows
      
         _ExcelSheetActivate($oExcel, "Report List")
          $xlRepTitle = _ExcelReadCell($oExcel, $yrow, 1)
         $xlrepType = _ExcelReadCell($oExcel, $yrow, 2)
         $xlradName = _ExcelReadCell($oExcel, $yrow, 3)
         $xlConcatVal =  $xlRepTitle & "+" & $xlrepType & "+" & $xlradName
        
         For $i = 1 to UBound($aArray)
          $aArray[$i] = $xlConcatVal              
         Next
        Next

Now from the code i have another concatenated value, i want to check whether the two values match. See the code below:

I am getting the subscript error.

$ConcatVal =  $currRepTitle & "+" & $repType & "+" & $radName
      
        Local $aiResult = _ArrayFindAll($aArray, $ConcatVal)
          If $aiResult <> -1 Then     
           $foundReport = 1   
           ExitLoop
          EndIf

post-65245-0-27738100-1316540194_thumb.j

Posted (edited)

What exactly are you trying to do with that first piece of code, because it's not doing what you're thinking it's doing I'm guessing? The $aArray is going to contain 199 copies of the last value of $x1ConcatVal after it runs. One copy in each of the elements of the array, except $aArray[0] which will be empty.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

I want to get $aArray[1] = 8g-- (3M) CDS Next Review by Service+Listing+DocMS MS-DRG

$aArray[2] = 8h-- (3M) CDS Next Review by Unit+Listing+DocMS MS-DRG

$aArray[3] = 13a-- (3M) CDIS LOS Variance+Listing+CDI System MS-DRG and so on till the end of the attached excel...

And then in the second code snippet, i am just checking whether $ConcatVal is present in the array $aArray... How to do that

Posted

This is one way of doing it:

Local $aArray[500] ; <<<<<<<<<<<<< decalare the array with enough elements, you only had it set to 200
For $yrow = 2 To 500 ;this is excel rows
 _ExcelSheetActivate($oExcel, "Report List")
 $xlRepTitle = _ExcelReadCell($oExcel, $yrow, 1)
 $xlrepType = _ExcelReadCell($oExcel, $yrow, 2)
 $xlradName = _ExcelReadCell($oExcel, $yrow, 3)
 $xlConcatVal = $xlRepTitle & "+" & $xlrepType & "+" & $xlradName
 $aArray[$yrow - 1] = $xlConcatVal ; <<<<<<<<<<<<<<< this adds the contents of $xlConcatVal to the elements of the array
Next
$ConcatVal = $currRepTitle & "+" & $repType & "+" & $radName
Local $aiResult = _ArraySearch($aArray, $ConcatVal)
If $aiResult <> -1 Then
 $foundReport = 1
 ExitLoop
EndIf
; If you want the searching to be faster, in case you had a large amount of data to search through, you could do it
; this way as well
#cs
 _ArraySort($aArray)
 Local $aiResult = _ArrayBinarySearch($aArray, $ConcatVal)
 If $aiResult <> -1 Then
 $foundReport = 1
 ExitLoop
 EndIf
#ce

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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
  • Recently Browsing   0 members

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