Jump to content


Check out our Community Blogs

travy92

Member Since 02 Sep 2007
Offline Last Active Sep 30 2015 08:17 PM
-----

#335754 Tutorial - OptionButtons + Command Buttons!

Posted by travy92 on 13 September 2007 - 01:27 AM

INTRO
Ok, so basically we'll be making a program that prints off different text onto the form when a certain OptionButton is pressed.

-------------------------------------------------------------------

GUI (LAYOUT)

Here is my GUI:
Posted Image

-------------------------------------------------------------------

WHAT YOU NEED:

1 Command Button with:
Name: Command1
Caption: Print

3 Option Buttons with:

#1 Option Button:
Name: Option1
Caption: Hello

#2 Option Button:
Name: Option2
Caption: Hey

#3 Option Button:
Name: Option3
Caption: None (Seriously, put "None" as the caption look at the GUI to see it.)

-------------------------------------------------------------------

CODE:

Private Sub Command1_Click()
If Option1.Value = True Then
Print "Hello"

ElseIf Option2.Value = True Then
Print "Hey"

End If
End Sub

A very simple code for a very simple program !

-----------------------------------------------------------------

CODE EXPLANATION!:

Private Sub Command1_Click()

Tells VB to do whatever code is specified under that line when the Command1 button is clicked.
_________________________________________________________

If Option1.Value = True Then
Print "Hello"

This code means that IF the Option1 button is ticked, print the word "Hello".
_________________________________________________________

ElseIf Option2.Value = True Then
Print "Hey"

Basically the same as the code above this one BUT this one is the Option2 Button.
_________________________________________________________

End If
End Sub

Ends to coding for this button (Command1 button).

-----------------------------------------------------------------

EXTRA:

Well this tutorial is about printing things onto the Form. But you can change this by:

1) Add a ListBox into the Form with:
Name: List1
Caption: (None)


2) Add these codes into the coding section of VB:

A) For the part that says:

If Option1.Value = 1 Then
Print "Hello"

Replace the above code with the below code:

List1.AddItem "Hello"

----------------------------------------------------------------

B)

ElseIf Option2.Value = True Then
Print "Hey"

Replace the above code with the following code:

List1.AddItem "Hey"

And you're done!

----------------------------------------------------------------

Thanks to Tcm9669 & TheComputerMaster for the Screenshot Program.

Thanks to YOU for appreciating my previous tutorials and inspiring me to make new tutorials!

Made by me, Travy92.

SAMPLES xD:

Attached Files


  • 1


#335709 Tutorial - VB + Flash games!

Posted by travy92 on 12 September 2007 - 12:53 AM

INTRO

Well in this tutorial we'll be making a Flash game player with some "hacks".

----------------------------------------------------------------

GUI (LAYOUT):

Here is my GUI:

Posted Image


----------------------------------------------------------------

What you need:

Here is what items/buttons you need:

3 Command Buttons with:

#1 Command Button:
Name: cmdCash
Caption: Get Cash

#2 Command Button:
Name: cmdPower
Caption: Get Power

#3 Command Button:
Name: cmdTurrets
Caption: Get Turrets

3 Text Boxes with:

#1 Text Box:
Name: txtCash
Caption (None)

#2 Text Box:
Name: txtPower
Caption: (None)

#3 Text Box:
Name: txtTurrets
Caption: (None)


And the last thing you need to add is a ShockwaveFlash item by:

Go to components or just press CTRL+T. Then scroll down to ShockWave Flash and tick it. A new item should appear on your toolbox, it looks like a piece of paper.

Now click it and make a big box because this is what you'll be viewing/playing the flash game with.

Give it the:
Name: Movie


Now to get the flash game playing.....

First go to a flash game site (like miniclips or something) and load up a game. Wait until it's 100% fully loaded and then go into your "Temporary Internet Files" folder and find the game name with the extension ".swf". Right-Click it and then copy the location, in this case mine's:


Posted Image

And then go back to VB and click on the Movie box (The thing we just made) and then do this:
Posted Image

And you're done! YAY!

----------------------------------------------------------------

CODE:

Here is the code:

Private Sub cmdCash_Click()
Call Movie.SetVariable("_root.money", txtCash.Text)
End Sub

Private Sub cmdPower_Click()
Call Movie.SetVariable("_root.power", txtPower.Text)
End Sub

Private Sub cmdTurrets_Click()
Call Movie.SetVariable("_root.available_turrets", txtTurrets.Text)
End Sub

----------------------------------------------------------------
CODE EXPLANATIONS:

Private Sub cmdCash_Click()
Call Movie.SetVariable("_root.money", txtCash.Text)
End Sub

This just means every time you click the "cmdCash" button, it changes the variable (code) number to the number specified in the txtCash Text Box.

----------------------------------------------------------------

Private Sub cmdPower_Click()
Call Movie.SetVariable("_root.power", txtPower.Text)
End Sub

This does exactly what the first one does BUT it changes a different code (_root.power).

----------------------------------------------------------------

Private Sub cmdTurrets_Click()
Call Movie.SetVariable("_root.available_turrets", txtTurrets.Text)
End Sub

Also does the same as the two other codes! Again, it just changes a different code (_root.available_turrets).

----------------------------------------------------------------

If you need any help with this tutorial/Sothink's SWF Decompiler/Flash games then please feel free to PM me or post in this Thread!

Thanks to TheComputerMaster and Tcm9669 for the ScreenShot programs.

Thanks to you for reading this tutorial!

Made by me, Travy92.

SAMPLES!:

Attached Files


  • 2


#335654 Tutorial - Date Calculator!

Posted by travy92 on 11 September 2007 - 03:21 AM

Welcome to this very simply date calculator!

What we're doing!

Basically we'll be making a program that calculates the date difference between the two dates specified!

GUI (LAYOUT):
This is my GUI:

Posted Image

----------------------------------------------------------------

What you need~
1 Command Button with:
Name: cmdCalc
Caption: Calculate!

1 ListBox with:
Name: lstAnswer

----------------------------------------------------------------
CODE (Very short & simple!)

Add this code into General Declarations before you begin adding the rest of the code:

Private Mint As Integer

----------------------------------------------------------------

Then add this code:

Private Sub cmdCalc_Click()
Mint = DateDiff("d", "5/09/2007", "11/09/2007")
lstAnswer.AddItem "The day difference = " & Mint
End Sub

----------------------------------------------------------------

Code Explanation:

Private Sub cmdCalc_Click()

Basically means whenever you click on the cmdCalc button ("Calculate!" button), do the code that's specified below the line.

----------------------------------------------------------------

Mint = DateDiff("d", "5/09/2007", "11/09/2007")

Means calculate the day difference between the dates specified.

----------------------------------------------------------------

lstAnswer.AddItem "The day difference = " & Mint

Simply means add the answer to the LixtBox.

----------------------------------------------------------------

You can also change this:

Mint = DateDiff("d", "5/09/2007", "11/09/2007")

The "d" can be changed into other things like:

Year(s): "yyyy"
Month(s): "m"
Week(s): "ww"
Day(s): "d"
Hour(s): "h"
Minute(s): "n"
Second(s): "s"

Just replace the "d" with one of those and you're done!

ALSO you can obviously change the dates to whatever you want!

Thanks to Tcm9669 for the Screenshot program.

Thanks to TheComputerMaster for the upgraded Screenshot program.

Thanks to you for reading this tutorial!

Made by me, Travy92.


Lol, Samples!:

Attached Files


  • 1


#335604 Tutorial - An Internet browser!

Posted by travy92 on 09 September 2007 - 11:55 PM

INTRODUCTION

Well basically i've been playing around with a few functions i've learned through other tutorials and i'd like to make a tutorial on making an internet browser with history saving & Menu.

-------------------------------------------------------------------
GUI (LAYOUT)
Here is my GUI:
Posted Image

-------------------------------------------------------------------

What you need:

6 Command buttons with the following Names/Captions:

Command Button #1:
Name: cmdHome
Caption: Home

Command Button #2
Name: cmdBack
Caption: Back

Command Button #3
Name: cmdForward
Caption: Forward

Command Button #4
Name: cmdStop
Caption: Stop

Command Button #5
Name: cmdRefresh
Caption: Refresh

Command Button #6
Name: cmdGo
Caption: Go

1 ComboBox with the following Name/Caption
(Caption is the same as Text... Just find "Text" in the properties window):
Name: cboURL
Caption/Text: (Nothing)

1 Label with the following Name/Caption:

Name: lbCaption
Text: Address:

1 Web Browser with the following Name:

Now for the web browser, you'll need to add the component:
"Microsoft Internet Controls" You can get to the components window by press CTRL+T on the keyboard, then scroll down and tick "Microsoft Internet Controls".

After doing the above procedures, there should be a new item on the list of the tool bar. It looks like the Earth. Now click on it and drag it onto your Form, make it big because it's what you'll be using to view pages with.. Use this Name:
Name: wWeb

If you're having problems like an error when you click "Microsoft Internet Controls" just PM me and i'll help you out.
----------------------------------------------------------------

CODE WITH EXPLANATIONS!

Add this code to cmdHome button (Double click on the Home button to bring up code window.

[quote]Private Sub cmdHome_Click()
wWeb.GoHome
End Sub[/quote]This makes the web browser (wWeb) go to the home page when you click the "Home" button.
(The home page for me is Google, i think it jsut uses your other browser's home page...)

----------------------------------------------------------------

[quote]Private Sub cmdBack_Click()
wWeb.GoBack
End Sub[/quote]This makes the web browser (wWeb) go to the previous page whenever you click the "Back" button.

----------------------------------------------------------------

[quote]Private Sub cmdForward_Click()
wWeb.GoForward
End Sub[/quote]This code instructs the web browser to go to the subsequent page when you click the "Forward" button.

----------------------------------------------------------------

[quote]Private Sub cmdGo_Click()
wWeb.Navigate (cboURL.Text)
cboURL.AddItem (cboURL.Text)
End Sub[/quote]Okay, it's getting a bit harder now.
The above code makes the web browser (wWeb) go to the page specified by the cboURL box (ComboBox).
AND also whatever is entered into the cboURL box is also added to the drop down arrow box (like history).

----------------------------------------------------------------

[quote]Private Sub cmdRefresh_Click()
wWeb.Refresh
End Sub[/quote]This refreshes the web browser when you click the "Refresh" button.

----------------------------------------------------------------

[quote]Private Sub cmdStop_Click()
wWeb.Stop
End Sub[/quote]This code stops the web browser in it's tracks! Basically just stopping it from loading any further.

----------------------------------------------------------------

MENU + CODES

Ok to add a menu to the form you need to go to Tools>Menu Editor or just press CTRL+E.

A window like this will pop-up:
Posted Image


Now add the following in:

[quote]Caption: File
Name: mnuFile[/quote]----------------
Then press "Next"

And then press the Right-Arrow key to make the 3 dots appear:

Add this in:

[quote]Caption: Print
Name: mnuFilePrint[/quote]------------------
Then press "Next"
(Let 3 dots appear):

[quote]Caption: Exit
Name: mnuFileExit[/quote]------------------
Press "Next" again.
(This time take away the 3 dots by pressing the left arrow key)

[quote]Caption: Edit
Name: mnuEdit[/quote]----------------
Press the "Next" button again!
(And make the 3 dots appear again by pressing the right-arrow key)

[quote]Caption: Move
Name: mnuEditMove[/quote]---------------------
Press the "Next" button again!
(Keep the 3 dots):

[quote]Caption: Resize
Name: mnuEditResize[/quote]----------------------
MENU CODE

[quote]'Invoke PrintForm method for this Form (Me)
'Sends image of Form to printer - useful for hardcopy
Private Sub mnuFilePrint_Click()
Me.PrintForm
End Sub[/quote]Basically just prints off the page.

----------------------------------------------------------------

[quote]Private Sub cboURL_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
wWeb.Navigate cboURL.Text
End If
End Sub[/quote]This is an essential code to make the "History" function work.. It makes history work.. Lol.

----------------------------------------------------------------

[quote]Private Sub mnuFileExit_Click()
End
End Sub[/quote]Closes the program.

----------------------------------------------------------------

[quote]'Invoke Move method for this Form (Me)
'Look at Form object --> Methods in Help
Private Sub mnuEditMove_Click()
Me.Move 0, 0

End Sub[/quote]Moves the program window.

----------------------------------------------------------------

[quote]'Parameters of move are: left edge, top edge, width, height
'Measurements in twips (see Lesson 7)
Private Sub mnuEditResize_Click()
Me.Move 6000, 6000, 6000, 5000
End Sub[/quote]Resizes the program.


And if you're lazy and just want the full code:

[quote]Private Sub cboURL_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
wWeb.Navigate cboURL.Text
End If
End Sub

Private Sub cmdBack_Click()
wWeb.GoBack
End Sub

Private Sub cmdForward_Click()
wWeb.GoForward
End Sub

Private Sub cmdGo_Click()
wWeb.Navigate (cboURL.Text)
cboURL.AddItem (cboURL.Text)
End Sub

Private Sub cmdHome_Click()
wWeb.GoHome
End Sub

Private Sub cmdRefresh_Click()
wWeb.Refresh
End Sub

Private Sub cmdStop_Click()
wWeb.Stop
End Sub

Private Sub Form_Load()

Dim Response As Integer



Response = MsgBox("Open Program?", vbInformation + vbYesNo, "Are you sure?")



If Response = vbYes Then
MsgBox "Welcome to Trav's Internet Explorer!"
Load Me

ElseIf Response = vbNo Then

Me.Refresh

End If



End Sub


Private Sub Form_Unload(Cancel As Integer)
Dim Response As Integer



Response = MsgBox("Exit Program?", vbInformation + vbYesNo, "Are you sure?")



If Response = vbYes Then
MsgBox "Thankyou for using Trav's Internet Explorer!"
Unload Me

ElseIf Response = vbNo Then

Me.Refresh

End If



End Sub


'Invoke Move method for this Form (Me)
'Look at Form object --> Methods in Help
Private Sub mnuEditMove_Click()
Me.Move 0, 0

End Sub

'Parameters of move are: left edge, top edge, width, height
'Measurements in twips (see Lesson 7)
Private Sub mnuEditResize_Click()
Me.Move 6000, 6000, 6000, 5000
End Sub

Private Sub mnuFileExit_Click()
End
End Sub

'Invoke PrintForm method for this Form (Me)
'Sends image of Form to printer - useful for hardcopy
Private Sub mnuFilePrint_Click()
Me.PrintForm
End Sub
[/quote]----------------------------------------------------------------

EXTRA

You can also add extra message boxes to the exit buttons just in case you accidentally press Exit.

Here is the code:
[quote]Private Sub mnuFileExit_Click()
Dim Response1 As Integer



Response1 = MsgBox("Exit Program?", vbInformation + vbYesNo, "Are you sure?")



If Response1 = vbYes Then
MsgBox "Thankyou for using Trav's Internet Explorer."
Unload Me

ElseIf Response1 = vbNo Then

Me.Refresh

End If
End Sub[/quote]----------------------------------------------------------------

Or:
[quote]Private Sub Form_Unload(Cancel As Integer)
Dim Response As Integer



Response = MsgBox("Exit Program?", vbInformation + vbYesNo, "Are you sure?")



If Response = vbYes Then
MsgBox "Thankyou for using Trav's Internet Explorer!"
Unload Me

ElseIf Response = vbNo Then

Me.Refresh

End If



End Sub[/quote]----------------------------------------------------------------

Or jsut simply:
[quote]End[/quote](Put this code between the Private Sub "?"_Click ()
and End)
(The "?" stands for the button name... Put the button name in, whatever it is)

----------------------------------------------------------------

THANKS:

Thanks to Tcm9669 for the original Screenshot program.
Thanks to TheComputerMaster for the updated "hidden" version of the Screenshot program.

And thanks to you for taking the time to read this awfully long tutorial.

This tutorial was made by me, Travy92.

Samples!! WOOH!:

Attached Files


  • 2


#335564 A simple timer

Posted by travy92 on 09 September 2007 - 02:30 AM

In this tutorial we'll be making a simple timer that prints off a line every second into a ListBox.
----------------------------------------------------------------
GUI (Layout)
Here's my GUI (layout):

Posted Image

----------------------------------------------------------------
What you need to add:

4 Command Buttons:

With the following names/captions:

#1 Command Button:
Name: cmdStart
Caption: Start Timer

#2 Command Button:
Name: cmdStop
Caption: Stop Timer

#3 Command Button:
Name: cmdClear
Caption: Clear Text

#4 Command Button:
Name: cmdExit
Caption: Exit

1 ListBox
With:

Name:lstCount
Caption: (None)

1 Timer
With:

Name: tmrTimer
Caption: (None)

----------------------------------------------------------------
CODE:
Add this code to General Declarations:

Dim Response As Integer
Dim mintCount As Integer

Then this:

Private Sub cmdClear_Click()
lstCount.Clear
End Sub

Private Sub cmdExit_Click()
Response = MsgBox("Exit Program?", vbInformation + vbYesNo, "Are you sure?")
If Response = vbYes Then
Unload Me

ElseIf Response = vbNo Then
Me.Refresh

End If

End Sub

Private Sub cmdStart_Click()



mintCount = 0

Cls

tmrTimer.Enabled = True



End Sub



Private Sub cmdStop_Click()



tmrTimer.Enabled = False



End Sub





Private Sub tmrTimer_Timer()



mintCount = mintCount + 1

lstCount.AddItem "Timer fired again. Count = " & mintCount



End Sub

---------------------------------------------------------------
CODE EXPLANATION:

Private Sub cmdClear_Click()
lstCount.Clear
End Sub

This just means whenever you click the "Clear Text" button, the ListBox will be cleared of all text.

---------------------------------------------------------------

Private Sub cmdExit_Click()
Response = MsgBox("Exit Program?", vbInformation + vbYesNo, "Are you sure?")
If Response = vbYes Then
Unload Me

ElseIf Response = vbNo Then
Me.Refresh

End If

End Sub

What this does is whenever you click the "Exit" button, it asks you if you REALLY want to exit. If YES then it will exit, if NO then it will jsut go back to the previous screen.

----------------------------------------------------------------

Private Sub cmdStart_Click()



mintCount = 0

Cls

tmrTimer.Enabled = True



End Sub

This code makes the timer start every time you click the "Start Timer" button.

----------------------------------------------------------------

Private Sub cmdStop_Click()



tmrTimer.Enabled = False



End Sub

Very simple code that stops the timer when you click the "Stop Timer" button.

----------------------------------------------------------------

Private Sub tmrTimer_Timer()



mintCount = mintCount + 1

lstCount.AddItem "Timer fired again. Count = " & mintCount



End Sub

Ok this is a tad harder then the rest of the codes...
"mintCount" was dimmed as an integer in the "General declarations" section. With this said, the code means that every time the mintCount function is used, it adds +1 onto itself.

lstCount.AddItem "Timer fired again. Count = " & mintCount

Means that every time the mintCount is used, it adds the line "Timer fired again. Count = ?" Into the ListBox.
(The "?" means the number that the timer is up to)

----------------------------------------------------------------

Well this is the end of my Tutorial. Thanks for taking the time to read my tutorial.

Posted Image

This tutorial made completely by me, Travy92.
Special thanks the Tcm9669 for the screenshot program.

I've enclosed the sample:

Attached Files


  • 1


#335549 Tutorial - ListBox, ComboBox & Command button.

Posted by travy92 on 08 September 2007 - 10:04 PM

INTRODUCTION
Seeing as i've learned quiet a bit about visual basic, I'd like to introduce you to my second tutorial.
(My first was "Tutorial - SmarterChild Copy")
-------------------------------------------------------------------
WHAT WE'RE DOING
Basically in this mini tutorial we'll learn about adding text to a ListBox using a command button and a combo box/saving search history in combo box.
-------------------------------------------------------------------
GUI (Layout of the form)
This is my GUI (Layout)
Posted Image
You can use any GUI but this is mine.

It consists of:
1 Command Button:
Name: "cmdPrint"
Caption: "Add text to ListBox"

1 ListBox:
Name: "lstList"
Caption: (None)

1 ComboBox:
Name: "cboText"
Caption: (None)

Note: Don't add the quotes in caption/name(").
----------------------------------------------------------------
NAME EXPLANATIONS:
cmdPrint: "cmd" stands for Command, since it's a command button, use cmd. "Print" means Print... Nothing special.. It can be anything you want.

lstList: "lst" stands for List, since it's a ListBox, use lst. List simply means a list.

cboText: "cbo" stands for ComboBox, since it's a ComboBox, use cbo. "Text" means text.
----------------------------------------------------------------
CODE

Private Sub cmdPrint_Click()
lstList.AddItem cboText.Text
cboText.AddItem cboText.Text
End Sub

This is all that's needed to make this very simply program.
----------------------------------------------------------------
CODE EXPLANATION

Private Sub cmdPrint_Click()

Basically this means everytime you click cmdPrint, it will do the action as specified (Below)
----------------------------------------------------------------

lstList.AddItem cboText.Text

This code means add whatever text is written in the cboText.Text box to lstList box.
----------------------------------------------------------------

cboText.AddItem cboText.Text

This code means add the text that's written in cboText box into the cboText box... (So like saving history... This function can be used for an internet browser... I may be writing a tutorial on making an internet browser, if you want)
----------------------------------------------------------------

End Sub

This needs to be added at the end of every code.
---------------------------------------------------------------------------------
And you're done!
Posted Image
This is the example of the product with text in the ListBox.

And another one with the text saved in the ComboBox (Or History if you will):
Posted Image
---------------------------------------------------------------------------------
So this is goodbye for now.

This tutorial was made by me, Travy92.

Special thanks to Tcm9669 for the Screenshot program.

EDIT - I'll include some samples for the lazy people..

Attached Files


  • 2


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download