Sign in to follow this  
Followers 0
aquilesboy

Read file and ComboBox

4 posts in this topic

Hello there, 
I'm working with a .txt full of info about the payment of some employees but what I'm trying to do is just take their names in a string of 30 chars max.  and add them to a combobox for later selection.
The first name start at line 4 and every name comes after 24 lines. In the code i have im just able to add the last name of the query (FileReadLine), and display in a msgbox the names one after another. Seems like the the $namestring isnt working because the msgbox display full line not just 30 char.
 
 
Func _ButtonOpen()

$filepath = GUICtrlRead($Input1)
FileOpen($filepath,0)
for $i = 4 to _FileCountLines($filepath) Step + 24
$line = FileReadLine($filepath,$i)
$namestring = FileRead($filepath,30)
GUICtrlSetData($Combo1,$line)
msgbox(0,'','the line ' & $i & ' is ' & $line)
Next
FileClose($archivo)

EndFunc
 
I'm new to this so any help would be great,  thanks in advance.

Share this post


Link to post
Share on other sites



Hi there and welcome to the forum.  It appears to me that you are setting the message box to the full line with your $line variable.  You attempt to read the first 30 characters of the FILE (not the line) with the $namestring function but you never actually do anything with it.   You could take $line and do this to make it no greater than 30 characters:

$lineLength= StringLen ($line)
if $lineLength > 30 then 
$line=StringTrimRight ($line, ($lineLength-($lineLength-30)) )
endif

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites

 

Hi there and welcome to the forum.  It appears to me that you are setting the message box to the full line with your $line variable.  You attempt to read the first 30 characters of the FILE (not the line) with the $namestring function but you never actually do anything with it.   You could take $line and do this to make it no greater than 30 characters:

$lineLength= StringLen ($line)
if $lineLength > 30 then 
$line=StringTrimRight ($line, ($lineLength-($lineLength-30)) )
endif

Thanks for responding Jfish, thats exactly what I was looking for, it worked like a charm!

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