Jump to content

Radio Buttons that Open Files


edena
 Share

Recommended Posts

Hi,

Please can anyone help, I want to open files using radio buttons.

For example:

Input[ txt here ]

Radio button ".html"

Radio button ".txt"

[button]

So when the button is pressed you'll see a browser or a txt file opens according to the radio buttons you've chosen.

Below you will see two scripts: The first one has the Radio Button I'm finding difficult to make and the second one has the Input Box for you to see how the behavior of the script should be for my first one.

First script that has Radio Button:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("WinTitleMatchMode", 2)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 155, 162, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 16, 16, 121, 21)
$html = GUICtrlCreateRadio(".html", 16, 56, 113, 17)
$txt = GUICtrlCreateRadio(".txt", 16, 88, 113, 17)
$Button1 = GUICtrlCreateButton("Button1", 40, 120, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button1
   $try = '<br />' & @CRLF
   $try &= '<p><h1>' & GUICtrlRead($Input1) & '</p></h1>' & @CRLF
    Sleep(1000)
    FileWrite(GUICtrlRead($html) & GUICtrlRead($txt), $try)
    Sleep(1000)
    Send(@DesktopDir)
    Sleep(1000)
    Send($html, ".html")
    Sleep(1000)
    Send($txt, ".txt")
    Sleep(1000)
    ShellExecute(GUICtrlRead($html, ".html"))
    ShellExecute(GUICtrlRead($txt, ".txt"))
EndSwitch
WEnd

Second script that has Input Box:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("WinTitleMatchMode", 2)
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 212, 193, 192, 124)
GUICtrlCreateLabel("My Note:", 40, 10)
$Input1 = GUICtrlCreateInput("Input1", 40, 24, 129, 21)
GUICtrlCreateLabel("File name:", 40, 50)
$Input2 = GUICtrlCreateInput("File", 40, 64, 129, 21)
GUICtrlCreateLabel("Extention:", 40, 90)
$Input3 = GUICtrlCreateInput("Html", 40, 104, 129, 21)
$Button1 = GUICtrlCreateButton("Button1", 40, 144, 131, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button1
   $try = '<br />' & @CRLF
   $try &= '<table width=350 border=0 style="border-width: medium medium medium medium; border-spacing: 1px; border-style: solid solid solid solid; border-collapse: separate;">' & @CRLF
   $try &= '<tr>' & @CRLF
   $try &= '<td width=60%>' & GUICtrlRead($Input1) & '</td>'
   FileWrite(GUICtrlRead($Input2) & "." & GUICtrlRead($Input3), $try)
   Sleep(1000)
   ShellExecute(GUICtrlRead($Input2) & "." & GUICtrlRead($Input3))
EndSwitch
WEnd

Thank You

Link to comment
Share on other sites

What are you trying to do here? :

ShellExecute(GUICtrlRead($html, ".html"))
    ShellExecute(GUICtrlRead($txt, ".txt"))

Because the second parm of GuiCtrlRead() can only be a 1 or 0.

You should also look at GUICtrlGetState() to check the radio buttons. Something like:

if BitAnd(GUICtrlGetState($txt), $GUI_CHECKED) then ShellExecute(....)
Edited by Beege
Link to comment
Share on other sites

Sorry Sir,

I'm really bad in programming :graduated:, I've run the script but it gave me an error message,

what seems to be the problem?

Please can you or anyone help?

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("WinTitleMatchMode", 2)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 155, 162, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 16, 16, 121, 21)
$html = GUICtrlCreateRadio(".html", 16, 56, 113, 17)
$txt = GUICtrlCreateRadio(".txt", 16, 88, 113, 17)
$Button1 = GUICtrlCreateButton("Button1", 40, 120, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button1
   $try = '<br />' & @CRLF
   $try &= '<p><h1>' & GUICtrlRead($Input1) & '</p></h1>' & @CRLF
    Sleep(1000)
    if BitAnd(GUICtrlGetState($txt, $GUI_CHECKED)) then ShellExecute(".txt")
EndSwitch
WEnd

Thank You

Link to comment
Share on other sites

This line: if BitAnd(GUICtrlGetState($txt, $GUI_CHECKED)) then ShellExecute(".txt") has several errors. You should probably write the first part like this If BitAND(GUICtrlGetState($txt), $GUI_CHECKED) Then ShellExecute(".txt") although your ShellExecute statement won't do anything because you're not actually telling it to run anything unless your file is name ".txt" otherwise it's going to error on you when you run it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Yes BrewManNH is right. Thats why I was asking above what the ShellExecute()'s were for and just left it empty in the sample. What do you want to happen with shellexecute?

Link to comment
Share on other sites

What do you want to happen with shellexecute?

I want it to open notepad which is the .txt and the browser which is the .html.

From my first post you can see it clear (Second Script) but it involves Input Boxes. I want to open this notepads and

browsers using Radio Buttons.

Thank You.

Link to comment
Share on other sites

I'm not saying that I want "shellexecute" to be the one and only script to open a browser or a notepad,

What I'm looking for is how the second script's behavior (from my first post) can open the browser. This script was given to me as an example by JoHanatCent ->>

I'm really finding it hard to put the logic correct here, when it comes to Radio Buttons.

Thank You

Link to comment
Share on other sites

Which part about the Radio Buttons dont you get? its just like a checkbox. Its either checked or its not. Thats all they do. Did the BitAnd() confuse you mabey?

As for launching the apps, I would just use the Run command. Like for notpad use Run(@WindowsDir & "\Notepad.exe", "")

And if you have a specific .txt file you want to open, then use shellexecute("FullPath and filename"). Same thing for the .html files.

Whats the input box for? What do you want to do with the string you get from it

Link to comment
Share on other sites

Whats the input box for? What do you want to do with the string you get from it

Sorry for the late reply if Beege you still there and if anyone can help me here,

I'm trying to create a GUI that can "translate" scripts to Notepad so I can see the full html script. That is why I am putting the Input box which is to just write plain text to make my personal work faster when I'm trying to create a static website from html. And if I want to preview it I'll then click on the html radio button so that a browser with the text I written should look like.

You can see that a basic html script when creating a webpage is like this inside Notepad:

<html>

<head><title>

Welcome to Autoit

</head></title>

<body>

<p>Autoit still the best!!!</p>

</body>

</html>

Now you don't want to type down that same old tags which are this: <html></html><title></title><body></body> and this <p></p>.

That is why I want to create two radio buttons that has an html option to open a browser and a notepad option - to see the text and tags for me to edit from there.

If anyone can help with this,

Thank You.

Link to comment
Share on other sites

you know you can simply context click then view source.

I know what you mean but I just want to know how to create a Autoit GUI that can do this because it is more faster when it comes to not writing down the tags. It just cuts down some steps were I've been doing several times before.

My aim is to stop doing repeated stuff like retyping the tags and to create a simple looking GUI non such like Dreamweaver or other complicated website creator you see on the market, just a custom one that I know and I can use specifically for a specific purpose.

Thank You.

Link to comment
Share on other sites

edena, I see in other threads you still havent got this figured out. I was wrong in the post above when I said to use Guictrlgetstate(). Should have been using Guictrlread(). I still dont completely understand what you want, but see if this gets you any closer.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <file.au3>
Opt("WinTitleMatchMode", 2)
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 155, 162, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 16, 16, 121, 21)
$html = GUICtrlCreateRadio(".html", 16, 56, 113, 17)
$txt = GUICtrlCreateRadio(".txt", 16, 88, 113, 17)
$Button1 = GUICtrlCreateButton("Button1", 40, 120, 75, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
$temptxtfile = @TempDir & '\temptxt.txt'
$temphtmlfile = @TempDir & '\temphtml.html'
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button1
   $try = '<br />' & @CRLF
   $try &= '<p><h1>' & GUICtrlRead($Input1) & '</p></h1>' & @CRLF
  
   If BitAND(GUICtrlRead($txt), $GUI_CHECKED) Then
    If Not FileExists($temptxtfile) Then _FileCreate($temptxtfile)
    $hfile = FileOpen($temptxtfile, 2) ;the 2 = Write mode (erase previous contents)
    FileWrite($hfile, $try)
    FileClose($hfile)
    ShellExecute($temptxtfile)
   EndIf
   If BitAND(GUICtrlRead($html), $GUI_CHECKED) Then
    If Not FileExists($temphtmlfile) Then _FileCreate($temphtmlfile)
    $hfile = FileOpen($temphtmlfile, 2) ;the 2 = Write mode (erase previous contents)
    FileWrite($hfile, $try)
    FileClose($hfile)
    ShellExecute($temphtmlfile)
   EndIf
EndSwitch
WEnd
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...