-
Feb 8th, 2011, 12:43 PM
#1
Thread Starter
New Member
Beginner's Quandry
Hey guys, I've been programming VBA for a while now, and I recently started developing straight VB appliactions for some peers. However, I must admit my VBA knowledge is much more extensive than my VB knowledge, and I've run into a few problems (common beginner problems, I'm sure). On any note, I have some code that I've attached below:
Code:
Public gblUserID 'String
Public gblUserPass 'String
Public gblAttackType 'Integer
Public gblAttackWho 'Integer
Public Sub Main()
'The main area of the code, this is where you enter.
'Start by asking the user some questions - put some error checking here to make sure they enter valid options
On Error Resume Next
Call GetUserInputs
If (Err.Number <> 0) Then
MsgBox "Your enteries were invalid. Please re-run the program and try again."
Exit Sub
End If
On Error Goto 0
End Sub
Private Sub GetUserInputs()
'Create the opening pop-up box
Set startIE = CreateObject("InternetExplorer.Application")
'Set that start box defaults
startIE.Navigate "about:blank"
startIE.ToolBar = False
startIE.Resizable = False
startIE.StatusBar = False
startIE.Width = 340
startIE.Height = 340
'Set up the height and width
With startIE.Document.ParentWindow.Screen
startIE.Left = (.AvailWidth - startIE.Width) \ 2
startIE.Top = (.AvailHeight - startIE.Height) \ 2
End With
'Loop until ready
Do While startIE.Busy: Wscript.Sleep 100: Loop
'Create the inner HTML for the box
startIE.Document.Body.InnerHTML = "<DIV ALIGN=""left""><P>Mouse: 1 - Rat: 2 - Chicken: 3 - " _
& "Dog: 4 - Cat: 5 - Bear: 6 - Dragon: 7</P>" & vbCrLf _
& "<P>Monster Number: <INPUT TYPE=""text"" SIZE=""2"" ID=""monster""</P>" & vbCrLf _
& "<P>1 for Strength, 2 for Defense: <INPUT TYPE=""text"" SIZE=""2"" ID=""attacktype""</P>" & vbCrLf _
& "<P>Username: <INPUT TYPE=""text"" SIZE=""20"" ID=""username""</P>" & vbCrLf _
& "<P>Password: <INPUT TYPE=""password"" SIZE=""20"" ID=""password""></P>" & vbCrLf _
& "<P><INPUT TYPE=""hidden"" ID=""OK"" NAME=""OK"" VALUE=""0""><INPUT TYPE=""submit"" VALUE="" Submit "" " _
& "OnClick=""VBScript:OK.Value=1""></P></DIV>"
'Show the completed box
startIE.Visible = True
'Keep looping until "Submit" is selected
On Error Resume Next
Do Until (startIE.Document.All.OK.Value = 1 Or startIE.Visible = False): Script.Wait 300: Loop
On Error GoTo 0
'Grab all our values
gblAttackWho = CInt(startIE.Document.All.monster.Value)
gblAttackType = CInt(startIE.Document.All.attacktype.Value)
gblUserID = CStr(startIE.Document.All.username.Value)
gblUserPass = CStr(startIE.Document.All.password.Value)
'Get rid of the start box
startIE.Quit
Set startIE = Nothing
End Sub
Now, in VBA I know I can have different routines, functions, and classes to call and utilize, but I don't know how to make it work for VB. I have created an executable from this code, but I think it just runs through the global variables and then stops. Is there a way to get the executable to start in a certain sub routine when it begins the run? Can I continue to use routines as I have in VBA? Any help is very much appreciated! Thanks!
-
Feb 8th, 2011, 01:08 PM
#2
Re: Beginner's Quandry
,
is modular code, if you add a module to your project then put your code in there, then goto project-->project properties and set the startup object to sub main() .
Either that or put your code in a form like you probably have and change
to
Code:
Private Sub Form_Load()
Also you can make your variables private.
Last edited by Jmacp; Feb 8th, 2011 at 01:12 PM.
-
Feb 8th, 2011, 01:28 PM
#3
Thread Starter
New Member
Re: Beginner's Quandry
What if I am working in VbsEdit?
-
Feb 8th, 2011, 01:42 PM
#4
Re: Beginner's Quandry
Originally Posted by dehboy
What if I am working in VbsEdit?
Ah your writing a vbs, yuo just haven't called sub main, just add a
under the variables but above sub main().
-
Feb 8th, 2011, 01:54 PM
#5
Thread Starter
New Member
Re: Beginner's Quandry
Well that seems ackward...but it worked, so thank you!
-
Feb 8th, 2011, 02:20 PM
#6
Re: Beginner's Quandry
Originally Posted by dehboy
What if I am working in VbsEdit?
Thread moved from 'VB6 and Earlier' forum to 'ASP, VBScript' forum
-
Feb 8th, 2011, 08:39 PM
#7
Re: Beginner's Quandry
Originally Posted by dehboy
Well that seems ackward...but it worked, so thank you!
It is awkward. There is no need for a Sub Main() in a WSH script, which is probably what you are making.
When WSH invokes the script engine the "outer block" code is always run:
Code:
Option Explicit
Dim Answer
Answer = InputBox("Question")
MsgBox "You answered " & Answer
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|