Jump to content

Basic Script Help


Recommended Posts

#include <INet.au3>

;~ $Address = InputBox('Address', ' Enter support@xxxxxxxxxx.com')
$Address = "support@xxxxxxxxxx.com"
$Subject = InputBox('Subject', 'Please enter the problem description.')
$Body = InputBox('Problem Details', 'Enter as much detail as possible regarding the problem you are having.')
_INetMail($address, $subject, $body)
Hello All,

Thank you for taking the time to read and if possible help me out a little... What I am trying to do in the example is (I am guessing somthing pretty simple) to create a form that a user fills out and then is automatically emailed. What I would like for it to do is to enter the users name and computer name into the body of the email automatically. But I can't figure out exactly how to do that. If someone could help and or point me in the right direction that would great. This is going to be used in a couple of different ways, one will be a GUI (to replace the OEM Help in Windows Start so I would like to make it similar) that when a button is pressed the form pops up then auto send the email. Also as just a simple help me from anywhere I can use it. I work for as IT engineer and I am trying to make things easier for the end user. But I am very new to the whole scripting thing (less than a week). Thanks in advance I look forward to your help.

RSG

Link to comment
Share on other sites

Hi,

Think what you need is:

@UserName

@ComputerName

Check out the macro reference in the help file. It has lots of short macros that are very helpful.

Cheers

-1

What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world.

Link to comment
Share on other sites

Hi,

Think what you need is:

@UserName

@ComputerName

Check out the macro reference in the help file. It has lots of short macros that are very helpful.

Cheers

-1

Thank you for the reply... I saw the Macro's in the help file but what I can't figure out is how to add it to the script and then add that info to the body of the email. I would like to use the @UserName and @ComputerName thought because that looks like the simplest way to get it done. Again thanks for the reply and the suggestion.

Link to comment
Share on other sites

#include <INet.au3>

;~ $Address = InputBox('Address', ' Enter support@xxxxxxxxxx.com')
$Address = "support@xxxxxxxxxx.com"
$Subject = InputBox('Subject', 'Please enter the problem description.')
$Body = InputBox('Problem Details', 'Enter as much detail as possible regarding the problem you are having.')

$Body2= "User name is: "&@UserName & @crlf & "Computer name is: "&@ComputerName &@crlf&"The problem is:"&@crlf & $Body
_INetMail($address, $subject, $Body2)

Give that a try. Remember every time you change a type of data from say string to variable or variable to macro separate them by an &.

Cheers

-1

What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world.

Link to comment
Share on other sites

#include <INet.au3>

;~ $Address = InputBox('Address', ' Enter support@xxxxxxxxxx.com')
$Address = "support@xxxxxxxxxx.com"
$Subject = InputBox('Subject', 'Please enter the problem description.')
$Body = InputBox('Problem Details', 'Enter as much detail as possible regarding the problem you are having.')

$Body2= "User name is: "&@UserName & @crlf & "Computer name is: "&@ComputerName &@crlf&"The problem is:"&@crlf & $Body
_INetMail($address, $subject, $Body2)

Give that a try. Remember every time you change a type of data from say string to variable or variable to macro separate them by an &.

Cheers

-1

That is exactly what I was trying to do thank you so much, I knew it was going to be something fairly simple. Being a n00b the syntax and the special characters is what is throwing me off a lot. I am in no way any kind of a programmer.

Thanks again, I am sure I will be asking for more help as I get further into my litte project I am working on.

Link to comment
Share on other sites

One more thing I can't figure out here is how to cancel this, if you hit cancel of the X it just takes you to the next window and then to the email. I tried

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

But that does nothing for me... Any ideas please would be great.

Link to comment
Share on other sites

Along with the question above I have another little issue. The email script is part of a GUI I created that has an image in it. What is happening is the image will not center or go to the left og the GUI. It is staying under the last object/button in the GUI on the right. Any idea on how to make it go to the left? I can post the code but it has alot of company data in it I would rather not post, although I can edit it if need be. I have added a pic so you can see what the problem I am having is... Thanks in advance.

post-56258-12670248034789_thumb.jpg

Link to comment
Share on other sites

  • Moderators

RedSoxGeek,

Answer to last night's question:

Put If @error Then Exit after each of the InputBox lines. if you press Cancel or the [X] you get an error of 1 returned. It is all in the Help file, you know... :mellow:

As for today's question:

It is pretty difficult to offer more advice without seeing what you have done to create the GUI. What command are you using to get the picture into the GUI? If you used GUICtrlCreatePic, what did you use as left and top parameters?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <INet.au3>

$GUI = GUICreate("XXXXXXXXXX Help & Support", 800, 600)
$Pic = GUICtrlCreatePic("XXXXXXXXXX logo.bmp", 0, 0, 131, 77)
$Pic = GUICtrlCreatePic("about.jpg", 0, -1, 640, 201)

Opt('MustDeclareVars', 1)

Help_Support()

Func Help_Support()
    Local $Button_1, $Button_2, $msg
    GUICreate("XXXXXXXXXX Help & Support", 640, 680) ; will create a dialog box that when displayed is centered
    $Pic = GUICtrlCreatePic("XXXX001.jpg", 0, 1, 640, 137)
    $Pic = GUICtrlCreatePic("About.jpg", -1, 140, 640, 201)
    $Pic = GUICtrlCreatePic("Number.jpg", -1, 345, 640, 31)
    
    Opt("GUICoordMode", 2)
    $Button_1 = GUICtrlCreateButton("To Request Remote Assistance Please Click Here", -1, 1, 320)
    $Button_1 = GUICtrlSetImage(-1, "XXXX_Icon.ico") 
    $Button_2 = GUICtrlCreateButton("To Create an Online Service Ticket Please Click Here", -0, -1, 320)
    $Button_2 = GUICtrlSetImage(-1, "XXXX_Icon.ico") 
    $Pic = GUICtrlCreatePic("Filler.jpg", -1, 0, 10, 1)
    $Pic = GUICtrlCreatePic("Hours.jpg", -1, 0, 640, 205)
    GUICtrlSetPos($Pic, -1, 0)
    
    GUISetState()      ; will display a dialog box with 2 button

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button_1
                Run('Email.exe')    ; Will automatically send an email requesting Remote assistance, with computername, username and problem description...
            Case $msg = $Button_2
                Run('Online.exe')    ; Will Launch IE and bring user to XXXX's online web page...
        EndSelect
    WEnd
EndFunc   ;==>Help_Support

RedSoxGeek,

Answer to last night's question:

Put If @error Then Exit after each of the InputBox lines. if you press Cancel or the [X] you get an error of 1 returned. It is all in the Help file, you know... :mellow:

As for today's question:

It is pretty difficult to offer more advice without seeing what you have done to create the GUI. What command are you using to get the picture into the GUI? If you used GUICtrlCreatePic, what did you use as left and top parameters?

M23

Hi M23...

I have been trying to use the Help File, and it has been a lot of help, but I am still having trouble deciphering so of it, which is why I am coming to you experts for help. I will try your suggestion on the @error and let you know.

I have added when I have in the script for the GUI and edited out the bits I can't really share. I am sure it is not the prettiest thing in the world but I am blindly mashing my way through this stuff right now.

Link to comment
Share on other sites

  • Moderators

RedSoxGeek,

OK, I think we can fix that.

Top tip - avoid GUICoordMode like the plague - absolute coordinates are much easier to understand (and to follow when you go back to your code a few months later! :( ). So by using normal coordinates, I can get this (you will have to put your images back in and maybe adjust the sizes a little):

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <INet.au3>

;$GUI = GUICreate("XXXXXXXXXX Help & Support", 800, 600) ; <<<<<<<<<<<<<<<<<<<< What is this stuff doing here?!?!?!?!?!?!
;$Pic = GUICtrlCreatePic("XXXXXXXXXX logo.bmp", 0, 0, 131, 77)
;$Pic = GUICtrlCreatePic("about.jpg", 0, -1, 640, 201)

Opt('MustDeclareVars', 1)

Help_Support()

Func Help_Support()
    Local $hGUI, $Button_1, $Button_2, $msg
    $hGUI = GUICreate("XXXXXXXXXX Help & Support", 640, 680)
    GUICtrlCreatePic("M:\Program\Au3 Scripts\Images\test1.jpg", 0, 1, 640, 137)
    GUICtrlCreatePic("M:\Program\Au3 Scripts\Images\test2.jpg", 0, 140, 640, 201)
    GUICtrlCreatePic("M:\Program\Au3 Scripts\Images\test3.jpg", 0, 345, 640, 31)

    ;Opt("GUICoordMode", 2) ; <<<<<<<<<<<<<<<<<<<<<<<<<< Avoid like the plague!
    $Button_1 = GUICtrlCreateButton("To Request Remote Assistance Please Click Here", 0, 377, 320)
    ;$Button_1 = GUICtrlSetImage(-1, "XXXX_Icon.ico") ; <<<<<<<<<<<<<<< Will not work unless you use $BS_ICON style - and then you get no text!
    $Button_2 = GUICtrlCreateButton("To Create an Online Service Ticket Please Click Here", 321, 377, 320)
    ;$Button_2 = GUICtrlSetImage(-1, "XXXX_Icon.ico") ; <<<<<<<<<<<<<<< Will not work unless you use $BS_ICON style - and then you get no text!
    ;$Pic = GUICtrlCreatePic("Filler.jpg", 0, 10, 10, 1) ; <<<<<<<<<<<<<<< This is only 1 pixel deep - why use it?
    GUICtrlCreatePic("M:\Program\Au3 Scripts\Images\test4.jpg", 0, 408, 640, 205)
    ;GUICtrlSetPos($Pic, -1, 0) ; not necessary

    GUISetState()

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button_1
                Run('Email.exe')    ; Will automatically send an email requesting Remote assistance, with computername, username and problem description...
            Case $msg = $Button_2
                Run('Online.exe')    ; Will Launch IE and bring user to XXXX's online web page...
        EndSelect
    WEnd
EndFunc   ;==>Help_Support

Further points - most of which are explained in the script:

1. You cannot put images on a button unless you create it with the $BS_ICON style - and then you need some extra code to get text on it as well.

2. You only need to use a variable to store the ControlID of a control if you intend to use it later - like the buttons. There is no point in keeping the ControlIDs of the picture controls - particularly if you use the same variable each time and so overwrite each value. :lol:

3. Why create a 1 pixel wide graphic? Just expand your other pic controls a bit!

You are obviously pretty new to scripting (no problem - we all started there! :mellow: ) but I would seriously advise taking the time to work through the tutorials that you find here and here. It will save a lot of frustration later - for both you and us! :P

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

M23... Thank You Again, that is excatly what I need, it works the way it shold now. Just to let you know for some reason when I do the $Button_1 = GUICtrlSetImage(-1, "XXXX_Icon.ico") it actually puts the little pic in there on the button, no idea how or why though, but when the button is pressed nothing happens. I will see if I can get the image and text thing figured out. But for now the thing works... As for the rest of the junk that was in the script, well I had it there when I was first making it and it did not hard or cause the script to error out so I left it, but when I removed it would error out. Again thanks for your help.

Edited by RedSoxGeek
Link to comment
Share on other sites

  • Moderators

RedSoxGeek,

I have dug out the code to get both icon and text on a button. Only inconvenient, the icon is always to the left and the test is centred so they can overlap if you make the text too long.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>

$hGUI = GUICreate("Test", 500, 500)

$hButton = IconButton("Icon and Text", 10, 10, 150, 64, 32, "C:\Program Files\AutoIt3\Icons\au3.ico")

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        case $hButton
            MsgBox(0, "", "Pressed")
    EndSwitch

WEnd

; Credit Valuater
Func IconButton($BItext, $BIleft, $BItop, $BIwidth, $BIheight, $BIconSize, $BIDLL, $BIconNum = -1)

    GUICtrlCreateIcon($BIDLL, $BIconNum, $BIleft + 5, $BItop + (($BIheight - $BIconSize) / 2), $BIconSize, $BIconSize)
    GUICtrlSetState( -1, $GUI_DISABLE)
    Local $XS_btnx = GUICtrlCreateButton($BItext, $BIleft, $BItop, $BIwidth, $BIheight, $WS_CLIPSIBLINGS)
    Return $XS_btnx

EndFunc

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

RedSoxGeek,

I have dug out the code to get both icon and text on a button. Only inconvenient, the icon is always to the left and the test is centred so they can overlap if you make the text too long.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>

$hGUI = GUICreate("Test", 500, 500)

$hButton = IconButton("Icon and Text", 10, 10, 150, 64, 32, "C:\Program Files\AutoIt3\Icons\au3.ico")

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        case $hButton
            MsgBox(0, "", "Pressed")
    EndSwitch

WEnd

; Credit Valuater
Func IconButton($BItext, $BIleft, $BItop, $BIwidth, $BIheight, $BIconSize, $BIDLL, $BIconNum = -1)

    GUICtrlCreateIcon($BIDLL, $BIconNum, $BIleft + 5, $BItop + (($BIheight - $BIconSize) / 2), $BIconSize, $BIconSize)
    GUICtrlSetState( -1, $GUI_DISABLE)
    Local $XS_btnx = GUICtrlCreateButton($BItext, $BIleft, $BItop, $BIwidth, $BIheight, $WS_CLIPSIBLINGS)
    Return $XS_btnx

EndFunc

M23

Thanks again you are the best...

Link to comment
Share on other sites

  • Moderators

RedSoxGeek,

This is how you incorporate the function - and you will see what I meant about the length of the text:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <INet.au3>

Opt('MustDeclareVars', 1)

Help_Support()

Func Help_Support()
    Local $hGUI, $Button_1, $Button_2, $msg
    $hGUI = GUICreate("XXXXXXXXXX Help & Support", 640, 680)
    GUICtrlCreatePic("M:\Program\Au3 Scripts\Images\test1.jpg", 0, 1, 640, 137)
    GUICtrlCreatePic("M:\Program\Au3 Scripts\Images\test2.jpg", 0, 140, 640, 201)
    GUICtrlCreatePic("M:\Program\Au3 Scripts\Images\test3.jpg", 0, 345, 640, 31)

    $Button_1 = IconButton("To Request Remote Assistance Please Click Here", 0, 380, 320, 36, 32, "C:\Program Files\AutoIt3\Icons\au3.ico")
    $Button_2 = IconButton("To Create an Online Service Ticket Please Click Here", 321, 380, 320, 36, 32, "C:\Program Files\AutoIt3\Icons\au3.ico")
    GUICtrlCreatePic("M:\Program\Au3 Scripts\Images\test4.jpg", 0, 408, 640, 205)

    GUISetState()

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button_1
                Run('Email.exe')    ; Will automatically send an email requesting Remote assistance, with computername, username and problem description...
            Case $msg = $Button_2
                Run('Online.exe')    ; Will Launch IE and bring user to XXXX's online web page...
        EndSelect
    WEnd
EndFunc   ;==>Help_Support

Func IconButton($BItext, $BIleft, $BItop, $BIwidth, $BIheight, $BIconSize, $BIDLL, $BIconNum = -1)

    GUICtrlCreateIcon($BIDLL, $BIconNum, $BIleft + 5, $BItop + (($BIheight - $BIconSize) / 2), $BIconSize, $BIconSize)
    GUICtrlSetState( -1, $GUI_DISABLE)
    Local $XS_btnx = GUICtrlCreateButton($BItext, $BIleft, $BItop, $BIwidth, $BIheight, $WS_CLIPSIBLINGS)
    Return $XS_btnx

EndFunc

Go read those tutorials! :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

M23... Again thank you that is exactly what I needed. I do see what you mean about the text, but I can tweak it to make it fit and look pretty. I will read those tutorials as sson as I am done with this one script. I am on a time deadline but that is the next thing on my agenda. You have been very helpful and patient.

Link to comment
Share on other sites

  • Moderators

RedSoxGeek,

Not sure you (or your boss) have the priorities in the right order there. If you want a good end product, get your boss to agree to a short delay while you find out WTH you are doing. Otherwise you risk ending up with unmaintainable code which will cost even more time in the long run.

Tell him I said so! :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Oh I will read don't you worry I would really like to learn this. I know it will come in handy and become very useful to me and my job. The deadline was more self imposed. I just had to show that it was possible or I would have been shut down. My boss did not want me wasting my time.

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...