Jump to content

Array Help


Recommended Posts

How would I assign strings to arrays with a function. What I have at the moment is a list displaying values entered by the user.

What I would like to do is assign each of those values put into the list to an array. That array will be then called by a function to put the value into a html code one at a time.

In case you are not sure as to what I mean...

http://www.google.com/search?hl=en&rlz=1C1GGLS_enUS307US307&q=xxxxxxxxxx

xxx being a value that the array stores, thus the script will go through the list and systematically produce unique queries.

I have a few ideas for the solution, and I would like to know if I am on the right track with this...

Func AddCode()
            $text = GUICtrlRead($input)
            GUICtrlSetData($list, $text)
        EndFunc
            
        Func SearchIt ()
            $array = $text
;add rest of function

Now this seems like it would be the simple answer, but if I am not mistaken...wouldn't this just add one long string to a single value of the array?

Edited by hodgepodge
Link to comment
Share on other sites

How would I assign strings to arrays with a function. What I have at the moment is a list displaying values entered by the user.

What I would like to do is assign each of those values put into the list to an array. That array will be then called by a function to put the value into a html code one at a time.

In case you are not sure as to what I mean...

http://www.google.com/search?hl=en&rlz=1C1GGLS_enUS307US307&q=xxxxxxxxxx

xxx being a value that the array stores, thus the script will go through the list and systematically produce unique queries.

I have a few ideas for the solution, and I would like to know if I am on the right track with this...

Func AddCode()
             $text = GUICtrlRead($input)
             GUICtrlSetData($list, $text)
         EndFunc
             
         Func SearchIt ()
             $array = $text
;add rest of function

Now this seems like it would be the simple answer, but if I am not mistaken...wouldn't this just add one long string to a single value of the array?

Could I be right that you don't 'get' arrays?

The code yoiu have shown is insufficient for us to know what you are doing IMO. I assume $text and $array are global variables. If $array has been declared as an array then it will no longer be an array after you set it to be the same as $text with

$array = $text

If you have all the different strings in a listbox then you don't need an array. You can loop through all the items

#include <guilistbox.au3>

for $n = 0 to GuiListBox_GetCount($list) - 1
  SearchIt(GUICtrlListBox_GetText($list,$n))
next
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Could I be right that you don't 'get' arrays?

The code yoiu have shown is insufficient for us to know what you are doing IMO. I assume $text and $array are global variables. If $array has been declared as an array then it will no longer be an array after you set it to be the same as $text with

$array = $text

If you have all the different strings in a listbox then you don't need an array. You can loop through all the items

#include <guilistbox.au3>

for $n = 0 to GuiListBox_GetCount($list) - 1
  SearchIt(GUICtrlListBox_GetText($list,$n))
next
Well this is what I have so far...

#include <IE.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>

Opt("GUIOnEventMode", 1 )

#Region ### Main GUI


GUICreate( "Product Search")

;Array is for the product codes and their prices
Dim $array[100][2]
Local $list
Local $add
Local $msg
Local $search
Local $in
Local $text
Local $s_1 = 'upcdatabase.com/item/'
Local $s_2 = 'http://www.amazon.com/s/ref=nb_ss_hi?url=node%3D468240%2C328182011&field-keywords='
Local $s_3 = 'http://www.google.com/products?q='

GUISetOnEvent($GUI_EVENT_CLOSE, "ProductClose")

$search = GUICtrlCreateButton("Search!", 296, 120, 65, 25) ; fix all the alignment later
GUICtrlSetOnEvent($search, "SearchIt")

$add = GUICtrlCreateButton("Add", 296, 72, 65, 25)
GUICtrlSetOnEvent($add, "AddCode")

$list = GUICtrlCreateList("Items to search for", 72, 96, 217, 175)

$in = GUICtrlCreateInput("" , 72, 72, 217, 21)

GUISetState(@SW_SHOW)
#EndRegion


While 1
    Sleep(100)
WEnd

#Region ### Functions 
        Func AddCode()
            $text = GUICtrlRead($in)
            GUICtrlSetData($list, $text)
        EndFunc
            
        Func SearchIt ()
            $array = GUICtrlRead($in)
        EndFunc
        
        Func ProductClose ()
            Exit
        EndFunc
        
        
#EndRegion

Im trying to take the values entered into the list, plug them into the url, enter the url... After that, I want the the program to parse, or search the url some way and find the value I am looking for. Finally, I want the value found and the value searched for displayed on a table together.

To make a table of this sort wouldn't it make more sense to use arrays? And if so how would I make sure that the correct values are entered into their respective locations in the array?

Hopefully that helps... :D

Link to comment
Share on other sites

Your searchIt function could be something like this

Func SearchIt()
       Local $iItems = GuiListBox_GetCount($list)
   
       If UBound($array, 1) < $iItems Then ReDim $array[$iItems][2]
   
       For $n = 0 To $iItems - 1
           $array[$n][0] = GUICtrlListBox_GetText($list, $n)
           $StrToSearch = _INetGetSource($s_2 & $array[$n][0])
           $Res = FindFromString($StrToSearch)
           $array[$n[$n][1] = $Res
       Next
       
   EndFunc ;==>SearchIt
   
   Func FindFromString($s1);something to get the part you want from the source code
       Return _StringBetween($s1, "before", "after")
   
   EndFunc ;==>FindFromString

You could use a listview to display the results with 2 columns, and you could write the results straight to the listview rather than to the array, or use the array and copy from there to the listview.

Looks to me like it might be difficult to get the information you want from the url source code.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...