Sign in to follow this  
Followers 0
Synthesis

Help with VECTORS

6 posts in this topic

I got another problem :D

I have the function

$n = _stringexplode ("yahoo,msn,google",",")
$p = "5"
$i = "1"
do
  $i = $i + 1
  _GUICtrlComboBox_AddString ($combo, $n[$i])
until $i = $p

The error part is with $n[$i]. What is wrong?

Share this post


Link to post
Share on other sites



Nephentes,

What value does $i reach? And how many elements are there in $n? :D

Try looking at UBound in the Help file.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Nephentes,

What value does $i reach? And how many elements are there in $n? :D

Try looking at UBound in the Help file.

M23

$n = _stringexplode ("yahoo,msn,google",",")
$p = "5"
$i = "1"
do
  $i = $i + 1
  _GUICtrlComboBox_AddString ($combo, $n[$i])
until $i = $p

I have a GUI with a combo declared as $combo = (" ",10,10,200,20).

I want to add the content from $n to the combo, so the combo will have the elements yahoo ; msn ; google.

I hope you understand what I mean.

Share this post


Link to post
Share on other sites

Nephentes,

I will try again - but spell it out more clearly.

In your loop, you ask $i to run from 1 to 5 (or at least you would if you had declared your variables correctly!):

$p = "5"
$i = "1"
do
  $i = $i + 1
  ...
until $i = $p

But you will find that the array $n has only 3 elements:

$n = _stringexplode ("yahoo,msn,google",",")
; Reads:
; 0 yahoo
; 1 msn
; 2 google

So what do you think happens when you try to read the 4th and element? And what about element[0]?

Try something like this:

$n = _stringexplode ("yahoo,msn,google",",")

For $i = 0 To Ubound($n) - 1 ; because Autoit arrays start at 0
    _GUICtrlComboBox_AddString ($combo, $n[$i])
Next

Then you will always read the correct number of elements from the array, regardless of the string you start with.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Using _StringExplode() without the last parameter is the equivalent of using StringSplit(), So I'm going to use that instead.

$n = StringSplit("yahoo,msn,google",",")

This leaves you with $n defined as an array with four elements

$n[0]=3
$n[1]="yahoo"
$n[2]="msn"
$n[3]="google"

You are then accessing each element by counting from $i to $p

(Because these are numbers, It's better practice to not declare them as strings.)

$i = 1
$p = 5

You are getting an error because as it counts, eventually $i = 4, as a result, when it tries to read $n[$i] you get a Dimension range exceeded error because $n[4] doesn't exist.

Notice that StringSpilt() places the index of the final element in $n[0], which in this case is 3. If you looped instead from 1 to 3, you would not get an error.

For $i = 1 to $n[0]; for..next loops automatically increment the variable by 1.
  _GUICtrlComboBox_AddString ($combo, $n[$i]) 
Next

So a working version of your code snippet should look like this:

$n = StringSplit("yahoo,msn,google",",")
For $i = 1 to $n[0]
     ;For... Next loops automatically declare and increment the initial variable by 1.
     _GUICtrlComboBox_AddString ($combo, $n[$i]) 
Next

EDIT: Darn i was beaten :D

Edited by Paulie

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