A Place For Gamers By Gamers


You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

#1
 ZyCLoX

avatar
Founder
Founder
Hi there, I am going to help you guys on how to learn Visual Basic. I will try my best to explain the content as softly and carefully as I can so you can understand.
First off, you will need the program, thanks to the founder we have the serial key for it and the program download heres the link: [You must be registered and logged in to see this link.]

After you have downloaded that open up the program and read the following.


Lets start with something basic... perhaps make a calculator using VB (visual basic) code.

1.) Make 19 Buttons and one text box
2.) Then declare the variables


'Declare the global variables to be used throughout the form

Dim mfirst As Single

Dim msecond As Single

Dim manswer As Single

' Declare the global variables for the operators: Add,Sub,Mul and DIV

Dim mbutton As Integer

'Change the sign of the number from + or - or vice versa

' Depending on its state now they show in txtNUMBER text box

Dim Signstate As Boolean

Apply this to your line of code, just copy and paste

3.)  we will make it so that the number buttons actually do something so add the code into the your form
[Note]: Dont mind the 01,02,03 numbers beside/up on top of the code, I copied this directly from my line of code.

Private Sub cmd0_Click()
02
'Put the value 0 into the txtNUMBER text box
03
txtNUMBER = txtNUMBER + "0"
04
End Sub
05

06
Private Sub cmd1_Click()
07
'Put the value 1 into the txtNUMBER text box
08
txtNUMBER = txtNUMBER + "1"
09
End Sub
10

11
Private Sub cmd2_Click()
12
'Put the value 2 into the txtNUMBER text box
13
txtNUMBER = txtNUMBER + "2"
14
End Sub
15

16
Private Sub cmd3_Click()
17
'Put the value 3 into the txtNUMBER text box
18
txtNUMBER = txtNUMBER + "3"
19
End Sub
20

21
Private Sub cmd4_Click()
22
'Put the value 4 into the txtNUMBER text box
23
txtNUMBER = txtNUMBER + "4"
24
End Sub
25

26
Private Sub cmd5_Click()
27
'Put the value 5 into the txtNUMBER text box
28
txtNUMBER = txtNUMBER + "5"
29
End Sub
30

31
Private Sub cmd6_Click()
32
'Put the value 6 into the txtNUMBER text box
33
txtNUMBER = txtNUMBER + "6"
34
End Sub
35

36
Private Sub cmd7_Click()
37
'Put the value 7 into the txtNUMBER text box
38
txtNUMBER = txtNUMBER + "7"
39
End Sub
40

41
Private Sub cmd8_Click()
42
'Put the value 8 into the txtNUMBER text box
43
txtNUMBER = txtNUMBER + "8"
44
End Sub
45

46
Private Sub cmd9_Click()
47
'Put the value 9 into the txtNUMBER text box
48
txtNUMBER = txtNUMBER + "9"
49
End Sub

Remember DO NOT ADD the numbers you see floating everywhere thats the line count on VB. Anyways, Noticing that all the number buttons are called cmd# (# is the number) as your buttons need to have these names.

4.) Now were going to make the buttons. "+" is first.

Private Sub cmdADD_Click()
2
'User slected the add button
3
mbutton = 1
4
'Convert into a number and transfer the value from
5
'The text box on the form into the first number
6
mfirst = Val(txtNUMBER)
7

8
txtNUMBER = ""
9
End Sub


5.) Subtract "-"

Private Sub cmdSUBTRACT_Click()
2
'User slected the minus button
3
mbutton = 2
4
'Convert into a number and transfer the value from
5
'The text box on the form into the first number
6
mfirst = Val(txtNUMBER)
7

8
txtNUMBER = ""
9
End Sub


6.) Multiply = "*"

Private Sub cmdMULTIPLY_Click()
2
'User slected the multiply button
3
mbutton = 3
4
'Convert into a number and transfer the value from
5
'The text box on the form into the first number
6
mfirst = Val(txtNUMBER)
7

8
txtNUMBER = ""
9
End Sub

7.) Divide = "/"

Private Sub cmdDIVIDE_Click()
2
'User slected the Divide button
3
mbutton = 4
4
'Convert into a number and transfer the value from
5
'The text box on the form into the first number
6
mfirst = Val(txtNUMBER)
7

8
txtNUMBER = ""
9
End Sub

8.) Making the Equals button.

Private Sub cmdEQUALS_Click()
02
msecond = Val(txtNUMBER)
03

04
Select Case mbutton
05
Case Is = 1
06
manswer = mfirst + msecond
07
Case Is = 2
08
manswer = mfirst - msecond
09
Case Is = 3
10
manswer = mfirst * msecond
11
Case Is = 4
12
manswer = mfirst / msecond
13
End Select
14
txtNUMBER = manswer
15
End Sub


At this point, you should be able to run and test. Once it works, come back here and read the following to add Decimal points.

9.) DECIMAL

Private Sub cmdDOT_Click()
2
txtNUMBER = txtNUMBER + "."
3
End Sub

I am going to show younext bit of code to change sign state

10.) Sign

Private Sub cmdSIGN_Click()
02
'Sign state = false on load of form
03
If txtNUMBER = "-" + txtNUMBER Then
04
   MsgBox "error start again"
05
End If
06
If Signstate = False Then
07
txtNUMBER = "-" + txtNUMBER
08
Signstate = True
09
Else
10
'SignState = True
11

12
minusvalue = Val(txtNUMBER)
13
'Value now positive
14
minusvalue = Val("-1" * minusvalue)
15
txtNUMBER = minusvalue
16
Signstate = False
17

18
End If
19
End Sub

11.) Final step, this is to cancel (empty the textbox and to end the program)

Private Sub cmdEXIT_Click()
2
Unload frmCALCULATOR
3
End Sub
4

5
Private Sub cmdCANCEL_Click()
6
'Remove the values in the txtNUMBER text box
7
txtNUMBER = " "
8
End Sub

That is it, for a little simple calculator, when you are writing this code you will see yourself which each of the code does in the program. This is a learning project for beginners, it worked for me although, I will admit it was a bit simpled down. Learning this straight off the bat will make you code more complex programs, necause with just the functions i have provided you can do a whole lot more than just a calculator.

Hope you enjoyed the tutorial. If you need any help with this just PM on here, I have been playing around with Visual Basic studios and etc for over 4 years now.





View user profile http://Team-PSN.net

View previous topic View next topic Back to top  Message [Page 1 of 1]


Permissions in this forum:
You cannot reply to topics in this forum

Share URL

URL Direct
BBcode
HTML