Sign in to follow this  
Followers 0
eMac

opening a .txt file in your program

11 posts in this topic

How would I go about creating a simple .txt file with text in it, and then adding a new menu item to my program, and calling the blah.txt file to open when the user clicked on that menu item.

I have the menu made, and the txt ready, I just need to write the code now to call it, so that it'll work.

thx,

eMac


Codename: Source ProgrammerWhat Is Codename: Source? A community designed operating system based off of the Windows OS. Source brings the ideas of the community to life as each user brings his or her own ideas into the development of this project.

Share this post


Link to post
Share on other sites



If  $msg = $button_1    Then
    $file = FileOpen("FILE_NAME", MODE)
    If  $file = -1  Then
        MsgBox(0,"Error","Their was an error trying to open " & $file)
    EndIf
    While 1
        MsgBox(0,"Success","Successfully opened" & $file)
        ExitLoop
    WEnd
    FileClose($file)
EndIf

something like that maybe? :)

Share this post


Link to post
Share on other sites

tried, doesn't open anything up, however, if I change the blah.txt to a file not yet created, then I get the error of it not being there, but if I type the .txt file correctly, doesn't work


Codename: Source ProgrammerWhat Is Codename: Source? A community designed operating system based off of the Windows OS. Source brings the ideas of the community to life as each user brings his or her own ideas into the development of this project.

Share this post


Link to post
Share on other sites

can you show me the code? it would be alot easier :)

Share this post


Link to post
Share on other sites

Codename: Source ProgrammerWhat Is Codename: Source? A community designed operating system based off of the Windows OS. Source brings the ideas of the community to life as each user brings his or her own ideas into the development of this project.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

here ya go, i crated an ipref.txt document to test with....... i left out a FileRead command >.< my bad lol it should have been like this

Case    $MSG = $MENUHELPIPRef
    $file = FileOpen("ipref.txt", 0)
    $read = FileRead($file)
    If $file = -1 Then
        MsgBox(0,"Error","Their was an error trying to open " & $file)
    Else
        MsgBox(0,"IP Referance List", $read)
    EndIf
        FileClose($file)

I switched it to a "Select ..... Case ....." statement instead of if..... then...... since that's what u were using :) also moved it up into the "while gui running loop" :(

V--Working Code--V

#Region Compiler directives section
#Compiler_Res_Comment=
#Compiler_Res_Description=IPView32
#Compiler_Res_Fileversion=7.0.0000
#Compiler_Res_LegalCopyright=© Codename: Source. All rights reserved.
#EndRegion

#include <GuiConstants.au3>

Dim $ID_MAIN = "IPView32"
Dim $ID_ABOUT = "About IPView32"
Dim $ID_IPREF = "IP Reference List"
Dim $OS = "Windows XP Professional"
Dim $VER = "1.00.ipview32"
Dim $W_HEIGHT = "300"
Dim $W_WIDTH = "200"
Dim $file
;=====================================================================================
; Name: $MAIN_WINDOW
; Description: $MAIN_WINDOW GUI Creation.
;=====================================================================================

$MAIN_WINDOW = GUICreate($ID_MAIN, $W_WIDTH, $W_HEIGHT)
GuiCtrlCreatePic("ipaddimg.jpg",0,0, 200,40)
$font="Verdana"
GUISetFont (8, $font)
GuiCtrlCreateLabel("Your IP address has been detected successfully.", 4, 50, 190, 40)

;=====================================================================================
; Name: Menu
; Description: Layout of IPView32 menu.
;=====================================================================================

$MENUFILE = GUICtrlCreateMenu("&File")
$MENUFILECLOSE = GUICtrlCreateMenuItem("E&xit", $MENUFILE)
$MENUSET = GUICtrlCreateMenu("&Settings")
$MENUSETADV = GUICtrlCreateMenuItem("&Advanced", $MENUSET)
;GUICtrlSetState(-1,$GUI_DISABLE)
$MENUHELP = GUICtrlCreateMenu("&Help")
$MENUHELPContents = GUICtrlCreateMenuItem("C&ontents", $MENUHELP)
$MENUHELPIPRef = GUICtrlCreateMenuItem("IP &Reference List", $MENUHELP)
$SEP1 = GuiCtrlCreateMenuitem ("",$MENUHELP)
$MENUHELPABOUT = GUICtrlCreateMenuItem("&About IPView32", $MENUHELP)

;=====================================================================================
; Name: Controls
; Description: All controls that deal with $MAIN_window.
;=====================================================================================

$lbl_IP1 = GuiCtrlCreateLabel("IP1................................", 10, 100, 150, 20)
$lbl_IP2 = GuiCtrlCreateLabel("IP2................................", 10, 130, 150, 20)
$lbl_IP3 = GuiCtrlCreateLabel("IP3................................", 10, 160, 150, 20)
$lbl_IP4 = GuiCtrlCreateLabel("IP4................................", 10, 190, 150, 20)

$lbl_InputIP1 = GuiCtrlCreateLabel("" & @IPADDRESS1, 120, 100, 80, 20)
$lbl_InputIP2 = GuiCtrlCreateLabel("" & @IPADDRESS2, 120, 130, 80, 20)
$lbl_InputIP3 = GuiCtrlCreateLabel("" & @IPADDRESS3, 120, 160, 80, 20)
$lbl_InputIP4 = GuiCtrlCreateLabel("" & @IPADDRESS4, 120, 190, 80, 20)


;=====================================================================================
; Function Name: GuiSetState()
; Description: Performs actions at IPView32 startup.
;=====================================================================================


GuiSetState()
TrayTip("" & @IPADDRESS1, + "Your IP address has been detected successfully.", 1)

While 1
$msg = GUIGetMsg()
Select

Case    $MSG = $MENUHELPIPRef
    $file = FileOpen("ipref.txt", 0)
    $read = FileRead($file)
    If $file = -1 Then
        MsgBox(0,"Error","Their was an error trying to open " & $file)
    Else
        MsgBox(0,"IP Referance List", $read)
    EndIf
        FileClose($file)

Case $MSG = $MENUHELPABOUT
GUISetState(@SW_HIDE, $MAIN_WINDOW)
_About($ID_ABOUT, $MAIN_WINDOW); Title for 'About' Dialog
GUISetState(@SW_SHOW, $MAIN_WINDOW)

        
#comments-start
Case $MSG = $MENUHELPIPRef
GUISetState(@SW_HIDE, $MAIN_WINDOW)
_IPREF($ID_IPREF, $MAIN_WINDOW); Title for 'IPRef' Dialog
GUISetState(@SW_SHOW, $MAIN_WINDOW)
#comments-end
Case $MSG = $GUI_EVENT_CLOSE Or $MSG = $MENUFILECLOSE
ExitLoop
EndSelect
WEnd



;=====================================================================================
; Function Name: _About()
; Description: Stores the resources that make up the "About IPView32"
; page.
;=====================================================================================

Func _About($ID_ABOUT, $MAIN_WINDOW)



Local $cmd_OK, $lbl_SEC1, $lbl_SEC2, $MSG, $ABOUT_WINDOW, $img_LOGO, $img_H_LINE, $lbl_COMPNAME, $lbl_USRNAME
Local $ABOUT_TEXT1 = "Codename: Source ® Build 1550" & @CRLF & @CRLF & _
"IPView32" & @CRLF & _
"Version 2006 (cn_source.build_1550.ipview32)" & @CRLF & _
"Copyright © 2006 CMX-Networks, Inc." & @CRLF & @CRLF & _
"This product is registered under the User-End License Agreement." & @CRLF & @CRLF & _
"Computer Name"
Local $ABOUT_TEXT2 = "Username"

$ABOUT_WINDOW = GUICreate($ID_ABOUT, 413, 322, -1, -1, -1, -1, $MAIN_WINDOW)
$img_LOGO = GuiCtrlCreatePic("cn_banner.bmp",0,0, 413,72)
$img_H_LINE = GuiCtrlCreatePic("h_line.jpg",40,270, 351,2)

$font="Verdana"
GUISetFont (8, $font)

$lbl_SEC1 = GUICtrlCreateLabel($ABOUT_TEXT1, 50, 80, 450, 165)
$lbl_SEC2 = GUICtrlCreateLabel($ABOUT_TEXT2, 50, 220, 450, 35)
$cmd_OK = GUICtrlCreateButton("OK", 310, 290, 85, 20)
$lbl_COMPNAME = GuiCtrlCreateLabel("" & @COMPUTERNAME, 60, 199, 80, 20)
$lbl_USRNAME = GuiCtrlCreateLabel("" & @USERNAME, 60, 235, 80, 20)
GUISetState()
Do
$MSG = GUIGetMsg()
Select
Case $MSG = $cmd_OK
ExitLoop
EndSelect
Until $MSG = $GUI_EVENT_CLOSE
GUIDelete($ABOUT_WINDOW)
EndFunc;==>_About

;=====================================================================================
; Function Name: _IPREF()
; Description: Stores the resources for the IP Reference Page
;=====================================================================================
#comments-start
Func _IPREF($ID_IPREF, $MAIN_WINDOW)



Local $cmd_OK, $lbl_SEC1, $lbl_SEC2, $MSG, $ABOUT_WINDOW, $img_LOGO, $img_H_LINE, $lbl_COMPNAME, $lbl_USRNAME
Local $ABOUT_TEXT1 = "IP Reference List" & @CRLF & @CRLF & _
"IPView32" & @CRLF & _
"Version 2006 (cn_source.build_1550.ipview32)" & @CRLF & _
"Copyright © 2006 CMX-Networks, Inc." & @CRLF & @CRLF & _
"This product is registered under the User-End License Agreement." & @CRLF & @CRLF & _
"Computer Name"
Local $ABOUT_TEXT2 = "Username"

$ABOUT_WINDOW = GUICreate($ID_IPREF, 413, 322, -1, -1, -1, -1, $MAIN_WINDOW)
$img_LOGO = GuiCtrlCreatePic("cn_banner.bmp",0,0, 413,72)
$img_H_LINE = GuiCtrlCreatePic("h_line.jpg",40,270, 351,2)

$font="Verdana"
GUISetFont (8, $font)

$lbl_SEC1 = GUICtrlCreateLabel($ABOUT_TEXT1, 50, 80, 450, 165)
$lbl_SEC2 = GUICtrlCreateLabel($ABOUT_TEXT2, 50, 220, 450, 35)
$cmd_OK = GUICtrlCreateButton("OK", 310, 290, 85, 20)
$lbl_COMPNAME = GuiCtrlCreateLabel("" & @COMPUTERNAME, 60, 199, 80, 20)
$lbl_USRNAME = GuiCtrlCreateLabel("" & @USERNAME, 60, 235, 80, 20)
GUISetState()
Do
$MSG = GUIGetMsg()
Select
Case $MSG = $cmd_OK
ExitLoop
EndSelect
Until $MSG = $GUI_EVENT_CLOSE
GUIDelete($ABOUT_WINDOW)
EndFunc;==>_IPRef
#comments-end
GUIDelete()
Exit
Edited by 4gotn1

Share this post


Link to post
Share on other sites

Thanks! Finally got it working, well you did! heh. Quick question btw, now that I can do it one way to pull it from a txt file, how would I do the other way, to where clicking on that link actually brings UP notepad, and my txt file shows up in notepad.


Codename: Source ProgrammerWhat Is Codename: Source? A community designed operating system based off of the Windows OS. Source brings the ideas of the community to life as each user brings his or her own ideas into the development of this project.

Share this post


Link to post
Share on other sites

Run("notepad.exe " & "PATH TO txt file")

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

what cserindere said.....

Case    $MSG = $MENUHELPIPRef
    $file = FileOpen("C:\Path\To\ipref.txt", 0)
    If $file = -1 Then
        MsgBox(0,"Error","Their was an error trying to open " & $file)
    Else
        Run("notepad.exe" & $file)
    EndIf
        FileClose($file)

i * think * this would be ok to replace my "other" code with ( if you notice i removed the command for AutoIt to actually "read" the .txt file but to make sure it can open it, then does in notepad if it can :)

Edited by 4gotn1

Share this post


Link to post
Share on other sites

I am pretty sure you need to put a space in the Run command for it to work.

In other words

Run("notepad.exe " & $file)

instead of

Run("notepad.exe" & $file)

enjoy

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

you dont open/close or read a file that is not opned by autoit

Case    $MSG = $MENUHELPIPRef
    $file = "C:\Path\To\ipref.txt"
    If Not FileExists($file) Then
        MsgBox(0,"Error","Their was an error trying to open " & $file)
    Else
        Run("notepad.exe " & FileGetShortName($file))
    EndIf

8)

Edited by Valuater

NEWHeader1.png

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