Sign in to follow this  
Followers 0
johnmcloud

[SOLVED] Edit box - Read data from binary file

7 posts in this topic

#1 ·  Posted (edited)

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



#2 ·  Posted (edited)

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

#3 ·  Posted (edited)

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

#4 ·  Posted (edited)

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

#5 ·  Posted (edited)

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

#6 ·  Posted (edited)

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

#7 ·  Posted (edited)

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  
Followers 0

  • Similar Content

    • 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.
    • hcI
      By hcI
      Hello everyone !
      I'm making a little password generator with save function.
      And i would like to set a line limit at 25.
      For my script, the user have to enter a name in "$input1" and click on the button "$btn_save" to display it in the editbox "$edit1".
      The user can't edit himself because the edit box have $ES_READONLY
      If someone know how, Thanks you !
       
      PS: I've already looked in the help and didn't find anything..
    • olmanRvr
      By olmanRvr
      I want to show or hide a edit control depending if a radio button is checked or not.The following Autoit code appears semantically ok but not working.Can anyone please help?
      thanks
      olmar
      While 1 $nMsg = GUIGetMsg() $isradioChk=GUICtrlRead($radio_AbsP);checked=1,not checked=4 Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $isradioChk If $isradioChk<==1 Then GUICtrlSetState($edit_AbsP,$GUI_SHOW) GUICtrlSetState($edit_RelP,$GUI_HIDE) Else GUICtrlSetState($edit_AbsP,$GUI_HIDE) GUICtrlSetState($edit_RelP,$GUI_SHOW) EndIf Case $usrPrefs EndSwitch WEnd