Jump to content

FileOpen newbness


Eli
 Share

Recommended Posts

Hi!

I'm working with FileOpen

The path is correct because a FileExists returns 1 and a msgbox with it returns the correct path

FileOpen does not open the file.

I have a feeling its some dumb newb error

#include <GUIConstants.au3>

;Initialize variables
Global $GUIWidth
Global $GUIHeight

$GUIWidth = 300
$GUIHeight = 250

;Create window
GUICreate("New GUI", $GUIWidth, $GUIHeight)


$Combo = GUICtrlCreateCombo("Choose", 10, 10, 280, 190)
$OK = GUICtrlCreateButton("OK", 75, 210, 70, 25)
$Cancel = GUICtrlCreateButton("Cancel", 165, 210, 70, 25)
$wap = GUICtrlCreateRadio("choose A",10,50,200)
GUICtrlCreateRadio("or B",10,75,200)

$data = GUICtrlSetData($Combo,"wert|yuiop")


GUISetState(@SW_SHOW)


While 1
   $msg = GUIGetMsg()

   Select
      Case $msg = $GUI_EVENT_CLOSE
       ;Destroy the GUI including the controls
         GUIDelete()
         Exit
         
    ;Check if user clicked on the "OK" button
      Case $msg = $OK
        $f2 = GUICtrlRead($Combo)  
        $w1 = GUICtrlRead($wap)
        If $w1 = $GUI_CHECKED Then
            $f1 = "\w_"
        Else
            $f1 = "\m_"
            endif
            

$file = FileOpen(@ScriptDir & $f1 & $f2 & ".txt",0) 

      Case $msg = $Cancel
         ExitLoop
        $msg = $GUI_EVENT_CLOSE
   EndSelect

WEnd
Link to comment
Share on other sites

Uh... how do I say that?

FileOpen is not for that kind of opening the file...

FileOpen opens the file internally for writting to it. What you want to do is to open the file in Notepad.

Try using:

$FileName = @ScriptDir & $f1 & $f2 & ".txt"
Run(@COMSPEC & " /c START " & $FileName, "", @SW_HIDE)

[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Link to comment
Share on other sites

This may help with your understanding of FileOpen() use some more.

#include <GUIConstants.au3>

;Initialize variables
Global $GUIWidth
Global $GUIHeight

$GUIWidth = 300
$GUIHeight = 250

;Create window
GUICreate("New GUI", $GUIWidth, $GUIHeight)

$Combo = GUICtrlCreateCombo("Choose", 10, 10, 280, 190)
$OK = GUICtrlCreateButton("OK", 75, 210, 70, 25)
$Cancel = GUICtrlCreateButton("Cancel", 165, 210, 70, 25)
$wap = GUICtrlCreateRadio("choose A", 10, 50, 200)
GUICtrlCreateRadio("or B", 10, 75, 200)

$data = GUICtrlSetData($Combo, "wert|yuiop")

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $GUI_EVENT_CLOSE
            ;Destroy the GUI including the controls
            GUIDelete()
            Exit

            ;Check if user clicked on the "OK" button
        Case $msg = $OK
            $f2 = GUICtrlRead($Combo)
            $w1 = GUICtrlRead($wap)
            If $w1 = $GUI_CHECKED Then
                $f1 = "\w_"
            Else
                $f1 = "\m_"
            EndIf
            $file = FileOpen(@ScriptDir & $f1 & $f2 & ".txt", 0)
            If $file <> -1 Then
                ; read something with $file handle
                ; ...
                FileClose($file); Close the handle
            Else
                MsgBox(0, @ScriptName, 'FileOpen Error')
            EndIf
            
        Case $msg = $Cancel
            ExitLoop
            $msg = $GUI_EVENT_CLOSE
    EndSelect

WEnd

:P

Link to comment
Share on other sites

Uh... how do I say that?

FileOpen is not for that kind of opening the file...

FileOpen opens the file internally for writting to it. What you want to do is to open the file in Notepad.

Try using:

$FileName = @ScriptDir & $f1 & $f2 & ".txt"
Run(@COMSPEC & " /c START " & $FileName, "", @SW_HIDE)
I got it to open with '"' around the fiilename

but all it does is pop up sa command prompt with the correct path.

these are simple txt files...is there no easy way to open them?

Edited by Eli
Link to comment
Share on other sites

Are you sure that a command promtp appears? Becaus @SW_HIDE is there just to make sure it doesn't.

Anyway, there is an alternative way:

Run('"notepad.exe" "' & $FineName & '"')

[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Link to comment
Share on other sites

yep, the command window stayed open

tried the run(notepad) thing....it opened notepad but it said it couldnt find the file would you like to create it instead

instead of opening a file

is there a relatively easy way to dump the contents of a txt file into say, a message box.

it it seems fileread() and filereadline() only do 1 character or line.

can you dump the WHOLE file into a variable?

Link to comment
Share on other sites

tried the run(notepad) thing....it opened notepad but it said it couldnt find the file would you like to create it instead

instead of opening a file

Then the file simply didn't exist and you didn't set $FineName to an already existing file.

Not important at this point though, as the following quote shows that this isn't what you want.

it it seems fileread() and filereadline() only do 1 character or line.

can you dump the WHOLE file into a variable?

Look at the last parameter for FileRead. Do a FileOpen, FileRead and then FileClose.

Read properly about these functions in the helpfile and you will make it.

Link to comment
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
 Share

  • Recently Browsing   0 members

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