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

    • 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?
    • wakillon
      By wakillon
      BinaryToAu3Kompressor v1.0.5.4
       

       
      It's now possible to see the best compression ratio using LZMA, LZNT and Base64 compressions with differents combinations.
      Nothing too complicate, you drag'n drop a file on the picture and script Test all compression types and return the ratios.
      ( Test duration depends of file size, slowest compression is LZNT, but all decompressions are fast  )
      Free to you after, to choose the compression(s) you want...
      Yes, LZMA needs a dll ( embedded & compressed in script ) but brings a powerfull compression. 
      It opens scite with your file compressed to an au3 script with or without decompression function as you want.
      Hold Left Shift key when clicking button for just copy script to clipboard.
      Use the 3 compressions at a time works but doesn't give a good ratio, that's why i don't display it.
      Usefull for little files you want include in your scripts !
      No externals files needed, they are already in script.
      Previous downloads : 1103
      Source and Executable
      BinaryToAu3Kompressor will be added to the next version of >SciTEHopper
      Thanks to Ward for his >Base64.au3 and LZMA.au3, and trancexx for his >LZNT functions and his >Base64Decode function.
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.