Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
VB6 - Basics 1 - Dim what?
#1
I'm gonna post some basic tutorials / guides for the new users. If you see any errors or if you have any ideas please let me know.

Basics 1 - Variables.

Byte
8-bit: Values from 0 to 255. Whole numbers only.

Integer
16-bit: Values from -32768 to 32767. Whole numbers only. Takes 2 bytes in memory.

Long
32-bit: Values from -2,147,483,648 to 2,147,483,647. Whole numbers only. Takes 4 bytes in memory. (This is 'int' in c++ and c#)

Single
32-bit: Values from -3.402823e38 to -1.401298e-45 for negative values. Values from 1.401298e-45 to 3.402823e38 for positive values. Takes 4 bytes in memory.

Double
64-bit Values from -1.79769313486232e308 to -4.94065645841247e-324 for negative values. Values from 4.94065645841247e-324 to 1.79769313486232e308 for positive values. Takes 8 bytes in memory.

String
The String data type is usually used as a variable-length type of variable. A variable-length string can contain up to approximately 2 billion characters. Each character has a value ranging from 0 to 255 based on the ASCII character set. Strings are used when Text is involved.


In VB6, you declare variable in the following manner:
Code:
Dim [name of variable] as [Data Type]
Example - declaring 'b' as a byte:
Code:
Dim b as Byte

Project
Our first project will be a basic form application that will add 2 values together. The data types can be whatever you want. Display the output.

Overview
  • Declare variables.
  • Add 2 values together and display the new value.

Notes
  • Please provide the source when submitting a project.
  • Make sure to comment your code.
Reply
#2
[spoiler]Private Sub cmdAdd_Click()
Dim A As Double
Dim B As Double
Dim Result As Double

' Assign the textbox input to our variables
A = Str(txtVal1.Text)
B = Str(txtVal2.Text)

' Add our varibles together
Result = A + B

' Display the result
lblResult.Caption = Str(Result)
End Sub[/spoiler]
Reply
#3
Dim A As Byte, B As Byte
A=1
B=1
Msgbox("A+B")
Reply
#4
Joost Wrote:Dim A As Byte, B As Byte
A=1
B=1
Msgbox("A+B")
Now wont that just display "A+B" in the messagebox? It wont calculate it because its in strings.

Code:
MsgBox(A + B)
Thats the proper way.
Reply
#5
Beres Wrote:
Joost Wrote:Dim A As Byte, B As Byte
A=1
B=1
Msgbox("A+B")
Now wont that just display "A+B" in the messagebox? It wont calculate it because its in strings.

Code:
MsgBox(A + B)
Thats the proper way.

Beres is correct. Joost would just show "A+B" and not actually perform any math.
Reply
#6
I was just testing you!

Dim A As Byte, B As Byte
A=1
B=1
Msgbox("A+B = " & A + B)
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)