Author Topic: Visual Basic 6.0 Variables  (Read 6145 times)

Caddberry

  • *
  • Posts: 1988
    • View Profile
    • http://animenfo.com/
Visual Basic 6.0 Variables
« on: 2002-02-08 05:41:00 »
It has been awhile since i had touched visual basic but now i am in a class "Intro to VB" just for kicks.. anyway doing the first project i declared variables like this

Dim X, Y, Z, As integer

the program didnt seem to like that very much as it completely messed up.. when i did it like this :

Dim X As Integer
Dim Y As Integer
Dim Z As Integer

The freaky thing worked.. i swear i declared them like this before.. might it have something to do with the Option Explicit or some kind of global declarations?

Needless to say i finished my project .. :) i got the thing working but i thought you could do that with commas seperating the names.. maybe i am thinking of Pascal..

Sephiroth 3D

  • *
  • Posts: 1679
    • View Profile
    • ModCitizen 42
Visual Basic 6.0 Variables
« Reply #1 on: 2002-02-08 07:11:00 »
No, you can do that in VB... I've personally never done it, but that SHOULD work... dunno why it didn't...

Sephiroth 3D

"I don't understand..." "You don't have to understand." - Final Fantasy: The Spirits Within

Sephiroth 3D.com
[email protected]

PurpleSmurf

  • *
  • Posts: 763
    • View Profile
Visual Basic 6.0 Variables
« Reply #2 on: 2002-02-08 08:23:00 »
funny cadberry.

try this in the global part of the proggie your working on:
Quote

a as integer
b as integer
c as integer

unless you need then through out the whole program in which case you need to global them

Quote

a as global
b as global
c as global


not doiing this really got me into trouble a while back.

The SaiNt

  • *
  • Posts: 1300
    • View Profile
Visual Basic 6.0 Variables
« Reply #3 on: 2002-02-08 09:34:00 »
*sigh*
In VB, integer declaration is done like this.
Code: [Select]
Dim X As Integer, Y As Integer, Z As Integer
Therefore, you can do this as well.
Code: [Select]
Dim X As Integer, Y As Double
Code: [Select]
Dim X, Y, Z As Integer
doesn't work because only Z is being assigned a "type".

Note : I'm not 100% sure of this since I use C a lot more than VB. I've only learnt a bit of VB for exam purposes, so I could be wrong ;)

Alhexx

  • *
  • Posts: 1894
    • View Profile
    • http://www.alhexx.com
Visual Basic 6.0 Variables
« Reply #4 on: 2002-02-08 11:19:00 »
SaiNt's right. That's the way it goes. If you declare some variables in one line, then only the word 'Dim' 'Private' ... is used for every variable in this line.

If you declare vars like this:
Code: [Select]

Dim X, Y, Z As Integer


then only Z will be type 'Integer' - X and Y will be 'Variant' Type ... that sucks....


 - Alhexx

dgp9999

  • *
  • Posts: 247
    • View Profile
    • http://molexroots.com
Visual Basic 6.0 Variables
« Reply #5 on: 2002-02-10 12:50:00 »
I haven't touched VB is ages, I've forgotten all of it, I didn't learn too much at the age of 12 though. I do remember that Public Sub can be used in the whole project, and Private Sub is something to do with one particular part of the program. I could be wrong.
I think Delphi's way of declaring is the best. "a,b,c :integer;" Easy peasy
-Dan

The SaiNt

  • *
  • Posts: 1300
    • View Profile
Visual Basic 6.0 Variables
« Reply #6 on: 2002-02-10 13:39:00 »
Quote

On 2002-02-10 08:50, dgp9999 wrote:
I think Delphi's way of declaring is the best. "a,b,c :integer;" Easy peasy

You do know that most programming languages use the same method right?

dgp9999

  • *
  • Posts: 247
    • View Profile
    • http://molexroots.com
Visual Basic 6.0 Variables
« Reply #7 on: 2002-02-10 15:50:00 »
I find it's the easiest method because all I've used is VB, TP, and Delphi. I nkow it's similar, but Delphi's uses less text than VB. I know, stupid point.
-Dan

Alhexx

  • *
  • Posts: 1894
    • View Profile
    • http://www.alhexx.com
Visual Basic 6.0 Variables
« Reply #8 on: 2002-02-10 18:42:00 »
I know this isn't necessary any more - but here's an VB example of that declaration crap...

Create a CommandButton and parse this code into its Click-Event:
Code: [Select]

  Dim a As Integer
  Dim b, c As Integer
  a = 1.95583
  b = 1.95583
  c = 1.95583
  MsgBox CStr(a) + vbCrLf + CStr(b) + vbCrLf + CStr(c)


Let's take a look at it...
We have declared 3 Variables ... it should be 3 Integers (well, they aren't - at least one of them)
Now we give a floating point number to these Vars.
B'cause Variable a and c are 'real' Integers, the floating point value is rounded to 2. But in Var b, which is Variant Type, VB stores the number as a floating point number - that's not what we wanted, right?

dgp9999 and SaiNt:
As for the method of declaring - I think it would *really* be better if Microsucks wouldn't have implemented that damn Variant Type - it's completely useless and just annoys programmers :x

 - Alhexx

Caddberry

  • *
  • Posts: 1988
    • View Profile
    • http://animenfo.com/
Visual Basic 6.0 Variables
« Reply #9 on: 2002-02-11 04:05:00 »
That is pretty shady.. but i thought that variant would work as an integer anyway.. You know.. i wanted to be a programmer awhile back.. but well... i dont want to anymore.. i think it sucks.. Madd props to all those that are programmers and actually know about it.. i know very little .. i have no clue in hell how Qhimm does the stuff he does.. or fice.. Saint i didnt know you got all into the mix either.. alhexx yeah i think i remembered som eof that i thought you programmed.. I think i am going to shoot for network administration .. i find programming boring.. maybe cuz i dont know what the hell i am doing half the time :) not writing code would be ok .. just making programs look neat would be my ideal field.. using photoshop and other image editors.. or editing sound for a program.. i have been into acid music.. ((((very little))))) but it seems kinda neat.. i have steinberg nuendo but havent begun to learn that damn thing.. Sigh..

Click Click Boom...

Alhexx

  • *
  • Posts: 1894
    • View Profile
    • http://www.alhexx.com
Visual Basic 6.0 Variables
« Reply #10 on: 2002-02-11 12:02:00 »
You're givin' up quite fast, boy ....

 - Alhexx

Caddberry

  • *
  • Posts: 1988
    • View Profile
    • http://animenfo.com/
Visual Basic 6.0 Variables
« Reply #11 on: 2002-02-13 04:53:00 »
not really.. i have read books and such... i have thought about being a programmer for a long time.. i just know its not what i want to do with my life.. i think my life is too crazy to be able to focus that much on a job.. maybe it will calm down...

PurpleSmurf

  • *
  • Posts: 763
    • View Profile
Visual Basic 6.0 Variables
« Reply #12 on: 2002-02-14 03:57:00 »
sint: of this is a bit delayed but i havn't been of then forums for like 3 days. and my method dose work. yours does too. the major factor between them is where they go. mine goes in the code before you have any subs or stuff. i havn't been in vb for a while but i seem to emember it's called general. your works in subs. and only in the sub you call it in.