Jump to content

how to translate this VBscript to autoit


Recommended Posts

Hi, Can someone help me to translate this VBscript to AutoIt. Thanks

Set oie = CreateObject("InternetExplorer.Application")

oie.Visible = True

oie.Navigate ("http://websms.starhub.com/websmsn/usr/createMsgSessionPageShow.do?method=initCreateSession")

While oie.Busy: Wend

oie.document.Forms("frmMsgCreateSession").ALL("recipients").Value = "1234567891"

oie.document.Forms("frmMsgCreateSession").ALL("SenderName").Value = "MyName"

oie.document.Forms("frmMsgCreateSession").ALL("Message").Value = "Test Message"

Link to comment
Share on other sites

Because I'm such a nice guy here is how it would look

#include <IE.au3>

$oIE = _IECreate("http://websms.starhub.com/websmsn/usr/createMsgSessionPageShow.do?method=initCreateSession")
;automatic wait till the page is loaded
$oForm = _IEFormGetObjByName($oIE,"frmMsgCreateSession") ; get form object
;the next lines fill in the forms by getting the element inside the form and then setting its value
$Recipient = _IEFormElementGetObjByName($oForm,"recipients")
_IEFormElementSetValue($Recipient,"123456")
$Name = _IEFormElementGetObjByName($oForm,"senderName")
_IEFormElementSetValue($Name,"some name")
$Message = _IEFormElementGetObjByName($oForm,"message")
_IEFormElementSetValue($Message,"This is a message")
;submits the form
_IEFormSubmit($oForm)
Link to comment
Share on other sites

Hi, Can someone help me to translate this VBscript to AutoIt. Thanks

Set oie = CreateObject("InternetExplorer.Application")

oie.Visible = True

oie.Navigate ("http://websms.starhub.com/websmsn/usr/createMsgSessionPageShow.do?method=initCreateSession")

While oie.Busy: Wend

oie.document.Forms("frmMsgCreateSession").ALL("recipients").Value = "1234567891"

oie.document.Forms("frmMsgCreateSession").ALL("SenderName").Value = "MyName"

oie.document.Forms("frmMsgCreateSession").ALL("Message").Value = "Test Message"

thatsgreat2345 has the best method but if you want the literal translaton here you are

$oie = ObjectCreate("InternetExplorer.Application")
 $oie.Visible = True
 $oie.Navigate ("http://websms.starhub.com/websmsn/usr/createMsgSessionPageShow.do?method=initCreateSession")
 While $oie.Busy
    $oie.document.Forms("frmMsgCreateSession").ALL("recipients").Value = "1234567891"
    $oie.document.Forms("frmMsgCreateSession").ALL("SenderName").Value = "MyName"
    $oie.document.Forms("frmMsgCreateSession").ALL("Message").Value = "Test Message"
Wend

I'm only showing this method so you can get a feel for translating VBS code. Of course it won't mean too much if you don't know VBS.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Thanks to Geosoft and Thatsgreat2345

Yes it works very fine.

Can someone explain to me what kind/type of object it is trying to get?

$oForm = _IEFormGetObjByName($oIE,"frmMsgCreateSession")

At this point, $oForm contain what?

I look at the helpfiles and I dont quite understand.

Thanks

Link to comment
Share on other sites

I'm only showing this method so you can get a feel for translating VBS code. Of course it won't mean too much if you don't know VBS.

Nice try.

But, there is nothing in the VBScript While...WEnd loop. I'll add a Sleep to make the loop go easy on the cpu and add better condition checking. ObjectCreate should also be ObjCreate.

$oie = ObjCreate("InternetExplorer.Application")
$oie.Visible = True
$oie.Navigate ("http://websms.starhub.com/websmsn/usr/createMsgSessionPageShow.do?method=initCreateSession")
While $oie.Busy
    Sleep(500)
Wend
$oie.document.Forms("frmMsgCreateSession").ALL("recipients").Value = "1234567891"
$oie.document.Forms("frmMsgCreateSession").ALL("SenderName").Value = "MyName"
$oie.document.Forms("frmMsgCreateSession").ALL("Message").Value = "Test Message"

:shocked:

Link to comment
Share on other sites

Your getting the form that you are looking at, their are forms marked by <form name="blah"> and then it ends </form> but there are the inputs inbetween so you define the form so it knows what form to look in for the elements your are telling it to put stuff in.

Thanks.

I check the web source code and the form name is frmMsgCreateSession (<form name="frmMsgCreateSession" method="POST" action="/websmsn/usr/createMsgSessionsubmit.do?method=createSession" onsubmit="return checkSubmit(this)" target="_parent">)

Looking at your code:- = _IEFormGetObjByName($oIE,"frmMsgCreateSession") , I guess that $oForm should contain something at this point of time, am I right?

I wanted to see what is inside $oForm and so I create the following, but I see nothing inside notepad. I am lost. Please explain.

#include <IE.au3>

$oIE = _IECreate("http://websms.starhub.com/websmsn/usr/createMsgSessionPageShow.do?method=initCreateSession")

$oForm = _IEFormGetObjByName($oIE,"frmMsgCreateSession")

Run("notepad.exe")

WinWaitActive("Untitled - Notepad")

Send ("$oForm")

Thanks again

Edited by jimmyjmmy
Link to comment
Share on other sites

Nice try.

But, there is nothing in the VBScript While...WEnd loop. I'll add a Sleep to make the loop go easy on the cpu and add better condition checking. ObjectCreate should also be ObjCreate.

$oie = ObjCreate("InternetExplorer.Application")
$oie.Visible = True
$oie.Navigate ("http://websms.starhub.com/websmsn/usr/createMsgSessionPageShow.do?method=initCreateSession")
While $oie.Busy
    Sleep(500)
Wend
$oie.document.Forms("frmMsgCreateSession").ALL("recipients").Value = "1234567891"
$oie.document.Forms("frmMsgCreateSession").ALL("SenderName").Value = "MyName"
$oie.document.Forms("frmMsgCreateSession").ALL("Message").Value = "Test Message"

:shocked:

100% correct on both counts. I almost didn't translate CreateObject at all. I work in too many scripting languages and it just looked normal.

However once I did start to translate it I don't know how I got Object instead of Obj.

And of course While oie.busy ;Wend is the equivalent of

While $oie.busy

;do nothing

Wend

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

$oForm will contain a special variant type called an "object"

It will look like a garbage string if you examine it directly - you can however use special object related functions on it like isObj and objName

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Thanks.

I check the web source code and the form name is frmMsgCreateSession (<form name="frmMsgCreateSession" method="POST" action="/websmsn/usr/createMsgSessionsubmit.do?method=createSession" onsubmit="return checkSubmit(this)" target="_parent">)

Looking at your code:- = _IEFormGetObjByName($oIE,"frmMsgCreateSession") , I guess that $oForm should contain something at this point of time, am I right?

I wanted to see what is inside $oForm and so I create the following, but I see nothing inside notepad. I am lost. Please explain.

#include <IE.au3>

$oIE = _IECreate("http://websms.starhub.com/websmsn/usr/createMsgSessionPageShow.do?method=initCreateSession")

$oForm = _IEFormGetObjByName($oIE,"frmMsgCreateSession")

Run("notepad.exe")

WinWaitActive("Untitled - Notepad")

Send ("$oForm")

Thanks again

sorry to break it to you but that isn't going to work, your getting the form object and then you need to get the element with in that form then use _IEFormElementSetValue(ControlGetText("Untitled - Notepad", "", "Edit1"))
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...