Jump to content

Recommended Posts

Posted (edited)

Hi, guys.

I got a new problem here..

Example : I want to input "abc" in textbox and reverse it into test.txt file dynamically..

I want the correct value is : "cba"

Error value : "abacba" in test.txt

#Include <String.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 262, 72, 504, 286)
$Input1 = GUICtrlCreateInput("", 48, 24, 177, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUIRegisterMsg($WM_COMMAND, "_KeyWordOnInputBoxEvent")

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

EndSwitch
WEnd




Func _KeyWordOnInputBoxEvent($hWnd, $imsg, $iwParam, $ilParam)
Local $setHK = False
$nNotifyCode = BitShift($iwParam, 16)
$nID = BitAND($iwParam, 0x0000FFFF)
$hCtrl = $ilParam
$time = 0
If $nNotifyCode = $EN_CHANGE Then
If $hCtrl = GUICtrlGetHandle($Input1) Then
If GUICtrlRead($Input1) <> "" Then
$startcheck = _StringReverse(GUICtrlRead($Input1))
$TEST = FileOpen("test.txt", 1)
FileWrite("test.txt", $startcheck)
FileClose($TEST)
EndIf
EndIf
EndIf
Return $GUI_RUNDEFMSG
EndFunc

Best Regard

Edited by Underdogger
  • Moderators
Posted

Underdogger,

How is AutoIt supposed to know when it is supposed to reverse the string? It cannot read your mind. ;)

If you only want to reverse after 3 characters then you need to add a StringLen condition into the code and only reverse/write when the count is correct. :)

And by the way there is no need to open and close the file in the handler - especially as you do not use the handle to write to it anyway. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

you could read it backward with stringmid, try this

ConsoleWrite(_reverseText("Autoit Text Message")&@LF)

Func _reverseText($intex)
Local $rev = ''
For $x = StringLen($intex) To 1 Step -1
$rev &=StringMid($intex,$x,1)
Next
Return $rev
EndFunc

Heroes, there is no such thing

  Reveal hidden contents

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Posted

  On 2/23/2013 at 5:35 PM, 'DiOgO said:

you could read it backward with stringmid, try this

ConsoleWrite(_reverseText("Autoit Text Message")&@LF)

Func _reverseText($intex)
Local $rev = ''
For $x = StringLen($intex) To 1 Step -1
$rev &=StringMid($intex,$x,1)
Next
Return $rev
EndFunc

There are more efficient and less 'memory intensive' ways of reversing a string.

For example >>

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

  On 2/23/2013 at 5:43 PM, 'guinness said:

There are more efficient and less 'memory intensive' ways of reversing a string.

For example >>

I really need to know how to work with dll's :ermm:

  On 2/3/2013 at 1:27 AM, 'BrewManNH said:

Func _StringReverse($s_String)

    Local $i_len = StringLen($s_String)
    If $i_len < 1 Then Return SetError(1, 0, "")

    Local $t_chars = DllStructCreate("wchar[" & $i_len + 1 & "]")
    DllStructSetData($t_chars, 1, $s_String)

    Local $a_rev = DllCall("MSVCR100.DLL", "ptr:cdecl", "_wcsrev", "struct*", $t_chars) ;<<<<<<<<<<<<
    If @error Or $a_rev[0] = 0 Then Return SetError(2, 0, "")

    Return DllStructGetData($t_chars, 1)
EndFunc ;==>_StringReverse

This works to reverses the string without using msvcrt.dll. Not sure which versions of Windows it would work on because of the dll used, but someone with more information than me can tweak as needed.

Heroes, there is no such thing

  Reveal hidden contents

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Posted (edited)

But Is it possible to write it into test.txt simultaneously ?

Typing "a" > test.txt gonna show "a"

then typing "b" > test.txt gonna show "ba"

then typing "c" > test.txt gonna show "cba"

Edited by Underdogger
Posted

  On 2/23/2013 at 5:56 PM, 'Underdogger said:

But Is it possible to write it into test.txt simultaneously ?

Typing "a" > test.txt gonna show "a"

then typing "b" > test.txt gonna show "ba"

then typing "c" > test.txt gonna show "cba"

in a edit or text box you just read the input text after you hit OK or triggred it somehow

you cannot wait until who is inputting the text to finish then read the inserted text and reverse?

Heroes, there is no such thing

  Reveal hidden contents

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Posted

  On 2/23/2013 at 5:50 PM, 'DiOgO said:

I really need to know how to work with dll's :ermm:

That API should only be use for low-level processes, not AutoIt. I was aiming more towards my version.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...