Mirage Source
VB6 - Basics 1 - Dim what? - Printable Version

+- Mirage Source (https://mirage-engine.uk/forums)
+-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61)
+--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18)
+---- Forum: Programming (https://mirage-engine.uk/forums/forumdisplay.php?fid=24)
+---- Thread: VB6 - Basics 1 - Dim what? (/showthread.php?tid=2891)



VB6 - Basics 1 - Dim what? - Jacob - 29-06-2009

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.



Re: VB6 - Basics 1 - Dim what? - Rian - 29-06-2009

[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]


Re: VB6 - Basics 1 - Dim what? - Joost - 30-06-2009

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


Re: VB6 - Basics 1 - Dim what? - Beres - 30-06-2009

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.


Re: VB6 - Basics 1 - Dim what? - Jacob - 30-06-2009

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.


Re: VB6 - Basics 1 - Dim what? - Joost - 30-06-2009

I was just testing you!

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