Sign in to follow this  
Followers 0
FireLordZi

For Loop not working...

7 posts in this topic

What's wrong with my For Loop?

$readsection = IniReadSection("C:\buddies.ini", "OnlineBuddies")
    If IsArray($readsection) Then
        For $z = 1 To $readsection[0][0]
            $var0 = StringSplit($readsection[$z][1], "~")
            $var1 = StringSplit($readsection[$z][1], ";")
            $date_ = StringTrimLeft($var1[UBound($var1)-1], 1)
            $dateitems = _GUICtrlListViewSetItemText($nListview, $z, 2, $date_); Sets the date from the INI file
        Next
    EndIf

Here's my .ini if you need:

[OnlineBuddies]

Nemo=sdfgdsg|sdfgsd|dsfg;~2-5-08

Ando=fdgdfsg|dsfgsd|rfgdf;~2-3-08

It is supposed to be setting the date to both of my listview items but it only sets 2-5-08 to the second listview item. What is wrong with my code?


While Alive() {
	 DrinkWine();
}
AutoIt Programmer

Share this post


Link to post
Share on other sites



What's wrong with my For Loop?

$readsection = IniReadSection("C:\buddies.ini", "OnlineBuddies")
    If IsArray($readsection) Then
        For $z = 1 To $readsection[0][0]
            $var0 = StringSplit($readsection[$z][1], "~")
            $var1 = StringSplit($readsection[$z][1], ";")
            $date_ = StringTrimLeft($var1[UBound($var1)-1], 1)
            $dateitems = _GUICtrlListViewSetItemText($nListview, $z, 2, $date_); Sets the date from the INI file
        Next
    EndIf

Here's my .ini if you need:

[OnlineBuddies]

Nemo=sdfgdsg|sdfgsd|dsfg;~2-5-08

Ando=fdgdfsg|dsfgsd|rfgdf;~2-3-08

It is supposed to be setting the date to both of my listview items but it only sets 2-5-08 to the second listview item. What is wrong with my code?

Don't know, but it looks like you should be saying

$dateitems = _GUICtrlListViewSetItemText($nListview, $z-1, 2, $date_); Sets the date from the INI file

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.

Share this post


Link to post
Share on other sites

You should be splitting by semi-colon first, then stripping.

sdfgdsg|sdfgsd|dsfg;~2-5-08

[1] = sdfgdsg|sdfgsd|dsfg

[2] = ~2-5-08

StringTrimLeft(1....)

Share this post


Link to post
Share on other sites

Thanks, both of your replies helped.


While Alive() {
	 DrinkWine();
}
AutoIt Programmer

Share this post


Link to post
Share on other sites

Don't know, but it looks like you should be saying

$dateitems = _GUICtrlListViewSetItemText($nListview, $z-1, 2, $date_); Sets the date from the INI file
Ok, I did this and now it is setting the date to the first listview item.

For example, if there are three items, and two items have dates, no matter

where the items are, it will set both dates in the first and second listview item.

This code is not working properly, any suggestions?


While Alive() {
	 DrinkWine();
}
AutoIt Programmer

Share this post


Link to post
Share on other sites

bump


While Alive() {
	 DrinkWine();
}
AutoIt Programmer

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Ok, I did this and now it is setting the date to the first listview item.

For example, if there are three items, and two items have dates, no matter

where the items are, it will set both dates in the first and second listview item.

This code is not working properly, any suggestions?

I think your problem is with your loop setup and this line:

_GUICtrlListViewSetItemText($nListview, $z

ListView items are ZERO-BASED and thus your $z needs at some point to = 0 to set the first ListView item (index = 0)

I think that's what martin was trying to get at?

if there are three items, and two items have dates, no matter

where the items are, it will set both dates in the first and second listview item.

this is because you are simply assigning the text to whatever $z is - which at the moment is 0 and 1 (using $z - 1). You're not telling autoit which listview item is the one you want to set the date to.

In my experience it's easier to re-write the whole list view from scratch every time you want to update things, otherwise you'd need to script to look for the correct listview item text (e.g. Nemo or Ando etc) get the index of that item then assign the date by that index.

Much easier to re-write the listview with the new date imo.

Edited by andybiochem

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

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