Jump to content
Sign in to follow this  
johnmcloud

[SOLVED] Edit box - Read data from binary file

Recommended Posts

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

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

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

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

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

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

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Stew
      (Edited from original.  Please note that I AM NOT AN AUTOIT EXPERT.  I write code using Autoit frequently but I am no expert, especially when it comes to I/O.  So any remarks that start with "Why did you..." can be answered by referring to the first sentence.  This project was done in Autoit because of an interface I built to display the data.)
      Attached is a program and ascii input file I wrote to read stock price data, convert it to binary and then read it back into the program in binary.  The goal was to show increased performance for reading the files in binary and provide a demo on how to read/write binary for int32, int64, double and strings for anyone who might find it helpful.  The results on my PC show the following:
      Time to read ascii file only: 456.981951167202
      Ascii read & process time: 6061.83075631701
      Binary write file time: 14787.9184635239
      Time just to read binary file: 42.418867292311
      Binary read and process time: 4515.16129830537
      A couple things to note:
      1) The 32 MB ascii file took 10x longer to read than the 15 MB binary file.  Not entirely sure why.  Both were read into a buffer.
      2) The Binary write takes a long time but I made no effort to optimize this because the plan was to write this file one time only so I don't mind if it takes longer to write this file.  I care much more about how long it takes to read the file because I will be reading it many times.
      3) There was a modest gain in converting the ascii file to binary in terms of file size and reading speed.
      So big picture... not sure it's worth the effort to convert the files to binary even though most of the data is numerical data in the binary file.  That was actually surprising as I expected there would be more of a difference.  Any ideas on how to get the binary data to read at a faster rate would be great.
       
      binary.au3
      2019_02_08.zip
    • By vin1
      i have a script that let you type text then give a random result on an output box, writes the result on a text file and tries to add the result text to an edit box but doesn't support multiple lines. I want the script to add lines of results on the edit box (as a log of results)
      #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <File.au3> #include <Date.au3> Global $result1s[3]=["one", "two", "three"] _Main() Func _Main() Local $button1 Local $output, $die, $msg, $results1 Local $file = FileOpen("test.txt", 1) Local $g_idEdit GUICreate("test", 600, 400, -1, -1) $button1 = GUICtrlCreateButton("Result", 432, 350, 80, 40) $sText = $results1 $edit = GUICtrlCreateEdit($sText & @CRLF & $sText & @CRLF & $sText, 60, 50, 450, 300, BitOr($GUI_SS_DEFAULT_EDIT, $ES_READONLY)) $output1 = GUICtrlCreateInput("", 60, 30, 450, 20, BitOR($ES_CENTER, $ES_READONLY)) $g_idEdit = GUICtrlCreateEdit("", 60, 10, 450, 20, $SS_LEFT) $die = GUICtrlCreateLabel("", 700, 500, 700, 20, $SS_SUNKEN) GUICtrlSetFont($output, 8, 800, "", "Verdana") GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select Case $msg = $button1 $results1 = Random(1, 2, 1) GUICtrlSetData($output1, $result1s[$results1]) GUICtrlSetData($edit, $result1s[$results1]) $read1 = GUICtrlRead($output1) FileWriteLine($file, _NowDate()& " " & _nowTime() & " " &GUICtrlRead($g_idEdit)) FileWriteLine($file, _NowDate()& " " & _nowTime() & " " &$read1) EndSelect If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>_Main  
       

    • 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.
       
    • 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
    • By Dragonfighter
      I'm searching a way to do xor and shift and if possible also other operations. Thanks in advance for the replies.
×
×
  • Create New...