Jump to content

GuiCtrlRead() Not returning variables as string?


Recommended Posts

I'm currently making a program for a user to send emails to multiple mail servers (aol, gmail, yahoo, etc). For this I am using Jos's SMTP UDF located here:

I have tested this UDF without a GUI by directly inputting needed information and it works, phenomenally. So i decided to make a GUI version because not everyone is going to have AU3 installed.

In the GUI I am using GuiCtrlRead() to return the values directly to the variables needed for sending the mail. I've done this for dozens of programs I've made in the past and this is the first one to ever give me a hard time. It's as if the GuiCtrlRead() function isn't returning the proper type of variable or just nothing at all.

Any help as to why the heck this is happening would be much more than appreciated. I have been stressing over this for a few days D:

PS My background with Autoit3 is about 1 year of constant coding plus background with java, VB6, C++ and a few others.

Below is a screenshot of the error.

http://gyazo.com/b1a6136a7f0677ae8a677f4e1f91ec99.png?1333606993

Here is the snippet of code I am using to grab the needed value, etc etc.

#include <file.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AutoMail v0.1", 577, 294, 320, 233)
$FromNameIn = GUICtrlCreateInput("", 8, 56, 121, 21)
$FromEmailIn = GUICtrlCreateInput("", 136, 56, 121, 21)
$ToEmailIn = GUICtrlCreateInput("", 8, 104, 121, 21)
$CcAddressIn = GUICtrlCreateInput("", 8, 152, 121, 21)
$BodyIn = GUICtrlCreateEdit("", 288, 192, 185, 89)
GUICtrlSetData(-1, "")
$AttachButt = GUICtrlCreateButton("Attachment", 160, 148, 75, 25)
$BccAddressIn = GUICtrlCreateInput("", 136, 104, 121, 21)
$SubjectIn = GUICtrlCreateInput("", 288, 152, 121, 21)
$UsernameIn = GUICtrlCreateInput("", 344, 56, 121, 21)
$PasswordIn = GUICtrlCreateInput("", 344, 80, 121, 21)
$SendButt = GUICtrlCreateButton("Send", 488, 256, 75, 25)
GUICtrlCreateLabel("Body", 288, 176, 28, 17)
GUICtrlCreateLabel("Subject", 288, 128, 40, 17)
GUICtrlCreateLabel("From Name", 8, 40, 58, 17)
GUICtrlCreateLabel("From Email", 136, 40, 55, 17)
GUICtrlCreateLabel("To Email", 8, 88, 45, 17)
GUICtrlCreateLabel("Bcc", 136, 88, 23, 17)
GUICtrlCreateLabel("Cc", 8, 136, 17, 17)
GUICtrlCreateLabel("Username", 288, 56, 52, 17)
GUICtrlCreateLabel("Password", 288, 80, 50, 17)
GUICtrlCreateLabel("AutoMail - HackCommunity.com: The Best Ethical Hacking Forum", 132, 8, 313, 17)
GUICtrlSetColor(-1, 0xFF00FF)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
;##################################
; Variables
;##################################
$SmtpServer = "smtp.gmail.com" ; address for the smtp-server to use - REQUIRED
$FromName = GUICtrlRead($FromNameIn) ; name from who the email was sent
$FromAddress = GUICtrlRead($FromEmailIn) ; address from where the mail should come
$ToAddress = GUICtrlRead($ToEmailIn) ; destination address of the email - REQUIRED
$Subject = GUICtrlRead($SubjectIn) ; subject from the email - can be anything you want it to be
$Body = GUICtrlRead($BodyIn) ; the messagebody from the mail - can be left blank but then you get a blank mail
$AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
$CcAddress = GUICtrlRead($CcAddressIn) ; address for cc - leave blank if not needed
$BccAddress = GUICtrlRead($BccAddressIn) ; address for bcc - leave blank if not needed
$Importance = "Normal" ; Send message priority: "High", "Normal", "Low"
$Username = GUICtrlRead($UsernameIn) ; username for the account used from where the mail gets sent - REQUIRED
$Password = GUICtrlRead($PasswordIn) ; password for the account used from where the mail gets sent - REQUIRED
$IPPort = 25 ; port used for sending the mail
;$ssl = 0                               ; enables/disables secure socket layer sending - put to 1 if using httpS
$IPPort = 465 ; GMAIL port used for sending the mail
$ssl = 1 ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $AttachButt
   _vSend()
  Case $SendButt
   $AttachFiles = FileOpenDialog("Please choose your attachment", @WorkingDir, "All (*.*)", 3)
  Case $GUI_EVENT_CLOSE
   Exit
EndSwitch
WEnd
Func _vSend()
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
$rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
If @error Then
  MsgBox(0, "Error sending message", "Error code:" & @error & "  Description:" & $rc)
EndIf
EndFunc   ;==>_vSend
Edited by Opie
Link to comment
Share on other sites

Think about when you are reading the controls, before the main-loop, before the user have had a chance to write anything, long long before you are interested in what is currently in them.

To make it simple, what you need to do is to move your GUICtrlRead()'s to the _vSend() function ;)

Link to comment
Share on other sites

Think about when you are reading the controls, before the main-loop, before the user have had a chance to write anything, long long before you are interested in what is currently in them.

To make it simple, what you need to do is to move your GUICtrlRead()'s to the _vSend() function :)

I have no idea why i've been missing that :OO

Thanks so much for pointing it out for me ;)

AdmiralAlkex you're a great guy ^__^

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