Jump to content
Sign in to follow this  
johnmcloud

[SOLVED] Edit box - Read data from binary file

Recommended Posts

johnmcloud

Hi guys, i have created this simply gui:

$GUI2 = GUICreate("Form1", 309, 442, 194, 55)
$EditBase = GUICtrlCreateEdit("", 32, 24, 249, 161)
GUICtrlSetData(-1, "")
$EditResult= GUICtrlCreateEdit("", 30, 204, 249, 161)
GUICtrlSetData(-1, "")
$ButtonBase = GUICtrlCreateButton("First", 32, 384, 73, 33)
$Button = GUICtrlCreateButton("Second", 204, 385, 73, 33)
$Input = GUICtrlCreateInput("", 112, 384, 81, 21)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $ButtonBase
   Func()
EndSwitch
WEnd

$File = FileOpen(@WorkingDir & "\config.ini", 128 + 1)
$Read = GUICtrlRead($Editbase)
If $read <> "" Then
FileWrite($File, $Read)
EndIf

I have this problem. I want to save a txt from Editbase (work) and the $EditResult read another binary file, i never make this "inverse" process. And, if is possible, make inccassible $EditResult from write, i want only too see/copy the result.

Thanks guys for support and happy new year :)

Edited by johnmcloud

Share this post


Link to post
Share on other sites
czardas

You can use _GUICtrlEdit_GetText() or GUICtrlRead() since both functions will get the text from your edit control. You might also want to look at the functions FileOpen() , FileWrite() and FileCreate() .

Happy New Year to you. :)

Edited by czardas

Share this post


Link to post
Share on other sites
johnmcloud

You can use _GUICtrlEdit_GetText() or GUICtrlRead() since both functions will get the text from your edit control. You might also want to look at the functions FileOpen() , FileWrite() and FileCreate() .

Happy New Year to you. :)

I'll change the title, now is more clear.

i don't know if i understand, but i don't want to create a file from what i write into Edit Box ( i have just do it ) but i want to set into Edit Box the content of a binary file ( the EditBox need to read the content of a file ).

If you can make an example, i'll be grateful

Thanks

Edited by johnmcloud

Share this post


Link to post
Share on other sites
czardas

I didn't check all your code, but here is an example function.

#include <GUIConstants.au3>
#Include <GuiEdit.au3>

$GUI2 = GUICreate("Form1", 309, 442, 194, 55)
$EditBase = GUICtrlCreateEdit("", 32, 24, 249, 161)
GUICtrlSetData(-1, "")
$EditResult= GUICtrlCreateEdit("", 30, 204, 249, 161)
GUICtrlSetData(-1, "")
$ButtonBase = GUICtrlCreateButton("First", 32, 384, 73, 33)
$Button = GUICtrlCreateButton("Second", 204, 385, 73, 33)
$Input = GUICtrlCreateInput("", 112, 384, 81, 21)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $ButtonBase
      _MyFunction($EditBase)
EndSwitch
WEnd

;$File = FileOpen(@WorkingDir & "config.ini", 128 + 1)
;$Read = GUICtrlRead($Editbase)
;If $read <> "" Then
;FileWrite($File, $Read)
;EndIf

Func _MyFunction($EditBase)
    Local $sEditData = _GUICtrlEdit_GetText($EditBase)
    Local $hFile = FileOpen ( "My_Result.txt" , 1 ) ; Change this flag if you want to overwrite the file.
    Filewrite($hFile, $sEditData)
    FileClose($hFile)
EndFunc

Hmm, I misunderstood your question. Use FileRead.

Edited by czardas

Share this post


Link to post
Share on other sites
johnmcloud

Hmm, I misunderstood your question.

Yeah, don't worry. I want to read the "My Result.txt" ( in my case is a binary file ) on the second Editbox :) and, if possible, i want only to copy/read the result on the EditBox and make inacessible to write

Edited by johnmcloud

Share this post


Link to post
Share on other sites
czardas

It's a bit rough and ready, since I have a dinner appointment.

#include <GUIConstants.au3>
#Include <GuiEdit.au3>

$GUI2 = GUICreate("Form1", 309, 442, 194, 55)
$EditBase = GUICtrlCreateEdit("", 32, 24, 249, 161)
GUICtrlSetData(-1, "")
$EditResult= GUICtrlCreateEdit("", 30, 204, 249, 161)
GUICtrlSetData(-1, "")
$ButtonBase = GUICtrlCreateButton("First", 32, 384, 73, 33)
$Button = GUICtrlCreateButton("Second", 204, 385, 73, 33)
$Input = GUICtrlCreateInput("", 112, 384, 81, 21)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $ButtonBase
      _MyFunction($EditBase)
  Case $Button
      _GetFileText("My_Result.txt", $EditResult)
EndSwitch
WEnd

;$File = FileOpen(@WorkingDir & "config.ini", 128 + 1)
;$Read = GUICtrlRead($Editbase)
;If $read <> "" Then
;FileWrite($File, $Read)
;EndIf

Func _GetFileText($hFile, $EditControl)
    $hFileHandle = FileOpen ($hFile)
    If @error Then Return SetError(1) ; Error checks needed adding
    Local $sEditData = FileRead($hFileHandle)
    _GUICtrlEdit_SetText($EditControl, $sEditData)
    FileClose($hFileHandle)
EndFunc

Func _MyFunction($EditBase)
    Local $sEditData = _GUICtrlEdit_GetText($EditBase)
    Local $hFile = FileOpen ( "My_Result.txt" , 1 ) ; Change this flag if you want to overwrite the file.
    If @error Then Return SetError(1)
    Filewrite($hFile, $sEditData)
    FileClose($hFile)
EndFunc

Added some error checks. Good luck with it.

Edited by czardas

Share this post


Link to post
Share on other sites
johnmcloud

Thanks, i'll recode for my GUI :)

Edited by johnmcloud

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  

  • Similar Content

    • aiter
      By aiter
      I am trying to get an image showing through a edit box.  I am only successful in making the edit box totally transparent
      #include-once #include <GUIConstants.au3> #include <GDIPlus.au3> #include <WinAPISys.au3> #include <colorconstants.au3> ;WS_EX_TRANSPARENT $gui = GUICreate("", 1000, 800, -1, -1, -1 , $WS_EX_LAYERED) ; use layered to get _winapi_setlay... to work $pic = GUICtrlCreatePic("c:\Program Files (x86)\AutoIt3\Examples\GUI\Merlin.gif", 0,0,1000, 800) GUICtrlSetState(-1, $GUI_DISABLE) $edit = GUICtrlCreateEdit("First line" & @CRLF, 176, 32,200,600) GUICtrlSetBkColor(-1,$COLOR_YELLOW) _WinAPI_SetLayeredWindowAttributes($gui,$COLOR_YELLOW,199) ; 199 is alpha (transparency level) GUISetState(@SW_SHOW,$gui) While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else EndSelect WEnd Exit Func Terminate() exit(0) EndFunc So I am making the edit box's background yellow then using the _WINAPI_SetLayeredWIndowAttributes command to make the yellow disappear (which it does), but the alpha level is supposed to give a bit of opaqueness to it, but its not, just making it totally transparent.  The alpha level is in fact affecting the window itself and not the edit box. I only want the edit box to be partially transparent.
      Help appreciated.
       
    • FMS
      By FMS
      Hello,
      I'm trying to read a binary file to an array but couln't get it to work.
      Also I coul not find any help in the forum around this subject whish was helpfull.
      Is there any way it could be done?
      I tried a lot of ways but maybe somebody know's the right way?
      #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <File.au3> #include <Array.au3> #include <AutoItConstants.au3> Local $in=FileOpen("TEST_labels.idx1-ubyte",16) ; 16+0=Read binary Local $data = FileRead($in) Local $FileArray = BinaryToString($data,4) ;~ $FileArray = StringSplit($BinarydData, @CRLF, 1+2) ;~ Local $FileArray = StringRegExp($BinarydData, "[^\r\n]+", 3) FileClose($in) _ArrayDisplay($FileArray,"$FileArray","",32) MsgBox($MB_SYSTEMMODAL, "", "$FileArray = " & $FileArray )  
      TEST_labels.idx1-ubyte
    • Dragonfighter
      By Dragonfighter
      I'm searching a way to do xor and shift and if possible also other operations. Thanks in advance for the replies.
    • rudi
      By rudi
      Hello.
      I'm too stupid to see my mistake:
      To investigate the internal "dictionary" of TIFF files I'd like to read in the files in binary mode and to check, if there are more than one pages "in" this TIFF.
      Notepad++, "View as Hex" is presenting the first bytes as "49 49 2a 20 08 20 20 20 12" for the TIF attached to this posting
      The "TIFF Header Format" is easy:
      Offset 00h, 2 Byte = Byte Order, "II"=intel, "MM"=motorola. (I = 0x49)
      --> II
      Offset 02h, 2 Byte = Version Nr.
      Offset 04h, 4 Byte = pointer to first IFD entry
      Description of TIFF header: https://www.awaresystems.be/imaging/tiff/faq.html#q3
       

      Howto read and analyse the binary content correctly? This is my messy, not operational code:
       
      $sampleTiff="H:\daten\tif\11\11\111111.TIF" $h=FileOpen($sampleTiff,16) $content=FileRead($h) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console FileClose($h) $type=VarGetType($content) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $type = ' & $type & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $ToString=BinaryToString($content) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ToString = ' & $ToString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF & @CRLF) $content=StringTrimLeft($content,2) ; cut off the leading "0x" ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console for $i = 1 to 8 step 8 $next=StringMid($content,$i,2) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $next = ' & $next & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $Chr=BinaryToString($next) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Chr = ' & $Chr & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF & "---" & @CRLF) Next Regards, Rudi.
      111111.TIF
    • ur
      By ur
      When I am trying to compile the autoit files with aut2exe.
      I am getting below error.
      There is no issue in code as the same code is getting compiled on different machine.
      I tried reinstalling the AUtoIT, but the issue replicates.

      Any suggestions?
×