Sign in to follow this  
Followers 0
gil900

i need Help with my first software

35 posts in this topic

Hello.

I build software that works with two files.

One file is: code.ini looks like this:

[HOUR]

h1=01

[MIN]

m1=01

[sEC]

s1=26

[DAY]

d1=22

[WDAY]

d1=7

[MOM]

m1=08

[YEAR]

y1=2011

[Alarm Type]

Type=1

[All Alarms]

1=201119330101

And the second file looks like this:

1=201122100101

3=201122121711

2=201122162411

......

I need help with the second file.

I need the code to do the following steps:

1) searches (second file), the lowest number (after the "=")

2) write the number (including what is before the "=") in code.ini like the picture:

Posted Image

Thanks for helpers

Share this post


Link to post
Share on other sites



I would do something like

  • $Variable = File Read code.txt
  • $Variable = String split right($variable, 12)
  • $Variable = String trim left($variable, 4)
  • Ini write($variable, code.ini)
Something like that, for each one. I would write a bit of it for you now but I am way too tired. If nobody has helped tomorrow, I will write a line for you and comment it so that you can continue with the program.

Share this post


Link to post
Share on other sites

Hi gil900,

what you are looking for is _FileReadToarray(), IniRead() and IniWrite().

1. read your file into an array with _FileReadToArray,

2. Loop through array and cut the first 2 chars (stringtrimleft())

3. Sort your array or use _ArrayMin() to get the lowest value

4. use stringMid and IniWrite() to get the data into file 1

as easy as 1-2-3 :mellow:


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks for your help

but For me it's too complicated.

I'd like to get same code for this ..

I tried to figure out how to do it for two days

Edited by gil900

Share this post


Link to post
Share on other sites

Aye,

_FileReadToArray then:

StringLeft($1, 4) = YEAR,
$day = StringTrimLeft($1, 4)
$day = StringTrimRight($day, 6)

u can go with this method :mellow:

- OR -

Simply put - between your 1= values. Like: 2011-22-11-33-44,

$splitted = StringSplit($1, "-", 1)

$year = $splitted[0]; or 1 ? :)

$day = $splitted[1]

$hour = $splitted[x]...


:alien: ~ Every Living Thing is a Code Snippet of World Application ~ :alien:

Share this post


Link to post
Share on other sites

Aye,

_FileReadToArray then:

StringLeft($1, 4) = YEAR,
$day = StringTrimLeft($1, 4)
$day = StringTrimRight($day, 6)

u can go with this method :mellow:

- OR -

Simply put - between your 1= values. Like: 2011-22-11-33-44,

$splitted = StringSplit($1, "-", 1)

$year = $splitted[0]; or 1 ? :)

$day = $splitted[1]

$hour = $splitted[x]...

And how the code will select the lowest number?

Can you give an example?

Share this post


Link to post
Share on other sites

And how the code will select the lowest number?

Can you give an example?

Autoit has a great help file :mellow:

#include <Array.au3>

;===============================================================================
; Example 1 (using a 1D array)
;===============================================================================
Local $avArray[10] = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]

_ArrayDisplay($avArray, "$avArray BEFORE _ArraySort()" )
_ArraySort($avArray)
_ArrayDisplay($avArray, "$avArray AFTER _ArraySort() ascending" )
_ArraySort($avArray, 1)
_ArrayDisplay($avArray, "$avArray AFTER _ArraySort() descending" )
_ArraySort($avArray, 0, 3, 6)
_ArrayDisplay($avArray, "$avArray AFTER _ArraySort() ascending from index 3 to 6" )

;===============================================================================
; Example 2 (using a 2D array)
;===============================================================================
Local $avArray[5][3] = [ _
[5, 20, 8], _
[4, 32, 7], _
[3, 16, 9], _
[2, 35, 0], _
[1, 19, 6]]

_ArrayDisplay($avArray, "$avArray BEFORE _ArraySort()" )
_ArraySort($avArray, 0, 0, 0, 0)
_ArrayDisplay($avArray, "$avArray AFTER _ArraySort() ascending column 0" )
_ArraySort($avArray, 0, 0, 0, 1)
_ArrayDisplay($avArray, "$avArray AFTER _ArraySort() ascending column 1" )
_ArraySort($avArray, 0, 0, 0, 2)
_ArrayDisplay($avArray, "$avArray AFTER _ArraySort() ascending column 2" )

:alien: ~ Every Living Thing is a Code Snippet of World Application ~ :alien:

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I Success to do it:

; Check if file opened for reading OK
If "code.txt" = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
For $i = 3 to 1 Step -1
$Variable = FileReadLine("code.txt", $i)
$Variable = StringTrimLeft($Variable, 2)
MsgBox(4096, "Test", $Variable)
Next

It works but I do not know how to take the lowest number

Edited by gil900

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

#include <file.au3>

Dim $a_secondfile
_FileReadToArray("code.txt", $a_secondfile)
_ArrayDisplay($a_secondfile)
For $i = 1 To $a_secondfile[0]
    $a_secondfile[$i] = StringTrimLeft($a_secondfile[$i], 2)
Next
$i_lowest = _ArrayMin($a_secondfile, 1, 1)

:mellow:

But you can find all of this in the helpfile...

Now that you have a buch of tips on how to start try by yourself, if you still have problems, let us know.

Edited by Hannes123

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

Well this has been asked on the forums before. Try searching "Number sorting" or something like that.

Share this post


Link to post
Share on other sites

Well this has been asked on the forums before. Try searching "Number sorting" or something like that.

The OP was asking for the lowest number in the second file. Did you read my post at all?

Using _ArrayMin() will give him the answer he asks for without the need to sort the array.


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

I success to Do this:

#include <Array.au3>
If "code.txt" = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
For $i = 3 to 1 Step -1
$Variable = FileReadLine("code.txt", $i)
$Variable = StringTrimLeft($Variable, 2)
MsgBox(4096, "Test", $Variable)
Next
Local $avArray[3] = [????]
_ArraySort($avArray)

MsgBox(4096, $avArra[0])

Where I wrote "????" I have to write something that has all the numbers. But I do not know how to do it.

Thanks for helpers

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Ok this is what I have right now:

#include <file.au3>
#include <Array.au3>
$b = _FileCountLines("code.txt")
$Variable1 = FileReadLine("code.txt", 1)
$Variable1 = StringTrimLeft($Variable1, 2)
$Variable2 = FileReadLine("code.txt", 2)
$Variable2 = StringTrimLeft($Variable2, 2)
$Variable3 = FileReadLine("code.txt", 3)
$Variable3 = StringTrimLeft($Variable3, 2)
Local $avArray[$b] = [$Variable1, $Variable2, $Variable3]
_ArraySort($avArray)
MsgBox(4096, "Test", $avArray[0])

But it's not good enough.

I tried to change to this code:

#include <file.au3>
#include <Array.au3>
$b = _FileCountLines("code.txt")
For $i = 1 to $b Step 1
$Variable[$i] = FileReadLine("code.txt", $i)
$Variable[$i] = StringTrimLeft($Variable[$i], 2)
Next
Local $avArray[$b] = [$Variable[$i]]
_ArraySort($avArray)
MsgBox(4096, "Test", $avArray[0])

But I got an error ..

What's wrong?

Edited by gil900

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Your code is suboptimal.

Did you read my post earlier?

If not, I will just quote it for you again:

#include <file.au3>

Dim $a_secondfile, $i_lowest

_FileReadToArray("code.txt", $a_secondfile)
_ArrayDisplay($a_secondfile)
For $i = 1 To $a_secondfile[0]
    $a_secondfile[$i] = StringTrimLeft($a_secondfile[$i], 2)
Next
$i_lowest = _ArrayMin($a_secondfile, 1, 1)

Now the $i_lowest Variable holds the lowest value from your file.

About your script:

Using _FileCountLines() and then using FileReadLine() for the whole file is just a waste of resources.

If you insist to do it with FileReadLine() better look at the example in the helpfile.

The main fault in your script is that you didn't declare $Variable.

Edited by Hannes123

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

hy guys, i have one problem with my first program.

just sometimes react, these GUI buttons is very slowly get react, i need more than 1 click to activate one button :S,

and after when i could use the Start, the buttons never get react xD, (sry for my bad english) plz help anyone. and with Pause options i cant pausing script :S,

$Form1 = GUICreate("Test Progress", 429, 182, 303, 198)

$Group1 = GUICtrlCreateGroup("Bot Menü", 16, 16, 393, 145)

$Button1 = GUICtrlCreateButton("Start", 24, 128, 75, 25)

$Button2 = GUICtrlCreateButton("Readme", 240, 128, 75, 25)

$Button3 = GUICtrlCreateButton("Exit/F10", 320, 128, 75, 25)

GUICtrlCreateGroup("", -99, -99, 1, 1)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1 ;Exit

$msg = GUIGetMsg()

Switch $msg

Case $GUI_EVENT_CLOSE

Exit

Case $Button3

Exit

EndSwitch

; About

$msg = GUIGetMsg()

Switch $msg

Case $GUI_EVENT_CLOSE

Case $Button2

MsgBox(0,"About","bla bla bla")

EndSwitch

; About

$msg = GUIGetMsg()

Switch $msg

Case $GUI_EVENT_CLOSE

Case $Button1

ToolTip("Bot is Running",0,0)

While 1

WinActivate("[CLASS:Notepad]")

Send ("y")

send ("1")

Sleep (1000)

Send ("2")

Sleep (1000)

Send ("3")

Sleep (10)

Send ("{SPACE}")

Sleep (10)

Send ("{SPACE}")

Sleep (10)

Send ("{SPACE}")

Sleep (10)

Send ("y")

send ("1")

Sleep (1000)

Send ("2")

Sleep (1000)

Send ("3")

Sleep (10)

Send ("{SPACE}")

Sleep (10)

Send ("{SPACE}")

Sleep (10)

Send ("{SPACE}")

Send ("7")

Sleep (10)

Send ("y")

send ("1")

Sleep (1000)

Send ("2")

Sleep (1000)

Send ("3")

Sleep (10)

Send ("{SPACE}")

Sleep (10)

Send ("{SPACE}")

Sleep (10)

Send ("{SPACE}")

send ("!1")

send ("!2")

send ("!3")

send ("!4")

send ("!5")

send ("!6")

send ("!7")

send ("!8")

WEnd

EndSwitch

WEnd

Share this post


Link to post
Share on other sites

Hello retaly,

please create your own post, it's not okay to use somebody's post. :mellow:


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

bro.. on more forums say always"dont open new post for ur topic, first look how have a post what do u want.."

why open if here is?..

"i need help with my first software2" >.<...

Edited by retaly

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

well it say "dont open new post for ur topic

this isnt your topic isnt it?

so looking on your script i see something, its for game bot?

if its not, open your own topic and try one more time to correct your code,

you have alot of

$msg = GUIGetMsg()

Switch $msg

that you dont need there

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

Your code is suboptimal.

Did you read my post earlier?

If not, I will just quote it for you again:

Now the $i_lowest Variable holds the lowest value from your file.

About your script:

Using _FileCountLines() and then using FileReadLine() for the whole file is just a waste of resources.

If you insist to do it with FileReadLine() better look at the example in the helpfile.

The main fault in your script is that you didn't declare $Variable.

Thanks

Your code did not work ..

I changed it to this:

#include <file.au3>
#include <Array.au3>
Dim $a_secondfile, $i_lowest

_FileReadToArray("code.txt", $a_secondfile)
For $i = 1 To $a_secondfile[0]
    $a_secondfile[$i] = StringTrimLeft($a_secondfile[$i], 2)
Next
$i_lowest = _ArrayMin($a_secondfile, 1, 1)
MsgBox(4096, "Test", $i_lowest)

And now it works!

Share this post


Link to post
Share on other sites

Thanks

Your code did not work ..

I changed it to this:

#include <file.au3>
#include <Array.au3>
Dim $a_secondfile, $i_lowest

_FileReadToArray("code.txt", $a_secondfile)
For $i = 1 To $a_secondfile[0]
    $a_secondfile[$i] = StringTrimLeft($a_secondfile[$i], 2)
Next
$i_lowest = _ArrayMin($a_secondfile, 1, 1)
MsgBox(4096, "Test", $i_lowest)

And now it works!

Well, ... blame me for not putting #include <array.au3> in the code. I thought it was obvious. :mellow:

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

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