Results 1 to 7 of 7

Thread: Is this possible in vb ?

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 1999
    Location
    Paderborn,NRW,Germany
    Posts
    1

    Post

    Dim a,b As Integer
    Dim a2,b2 as Integer

    a=2
    b=3
    a2=(a)
    b2=(b)

    a2 + b2 calculate 5 ??

    How can i work with pointer ?

    in dbase iV it was possible with a syntax like this..

    &a2. give 2

    Please Help ....

  2. #2
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Post

    First of all, a common mistake:

    Code:
    Dim a, b as integer
    Dim a2, b2 as integer
    This is what happens with this:
    a and a2 are declared as Variants
    b and b2 are declared as Integers
    Code:
    Dim a as Integer, b as integer
    Dim a2 as integer, b2 as integer
    Would be the correct alternative.

    Then, about your problem.

    As far as i know, VB does not support Pointers. The only sort of Pointer thing, is the AddressOf function, but you shouldn't ask me about that. I don't know how it works. It only returns the addresses of functions. (I think)

    r0ach™
    Don't forget to rate the post

  3. #3
    Addicted Member
    Join Date
    Oct 1999
    Location
    Oporto, Portugal
    Posts
    134

    Post

    Could someone tell if it is possible.
    Jorge Ledo
    [email protected]
    Portugal were the sun allways shine... for programmers.

  4. #4
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Post

    What do you want to do?

    I don't know why you want to use a pointer.
    Code:
    a2 = (a)
    b2 = (b)
    This sets the value of a2 equal to the value of a, and b2 equal to b.

    Code:
    Label1.Caption = a & " " & a2 & " " & b & " " & b2
    will set Label1's caption to:

    2 2 3 3

    so
    Code:
    Label1.Caption = a2 + b2
    would set the Caption to:

    5

    I don't understand what you want.

    r0ach™
    Don't forget to rate the post

  5. #5
    Addicted Member
    Join Date
    Oct 1999
    Location
    Oporto, Portugal
    Posts
    134

    Post

    A pointer in C works like this:

    a = 2
    b = (a)

    OK now b = 2 (fine).
    But if you do this.

    a = 5

    Without anything else b is now 5.
    A pointer works like a "=A1" in excel if you change "A1" the value of the current cell will change automatically.
    Jorge Ledo
    [email protected]
    Portugal were the sun allways shine... for programmers.

  6. #6
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    Post

    I think in VB 5.0 was an undocumented function farptr but AFAIK it doesn't still exist. But you can set something like a pointer. However, it works only with classes so you can't point to an integer.

    Code:
    Dim A as new TestClass 'Only a test, class doesn't really exist
    Dim B as TestClass 'This will be the pointer
    
    A.SetX 15
    
    Set B = A 'B points to A
    
    Print B.GetX 'Returns x of A
    it doens't matter wich var, A or B, you modify. They're always the same. It's like if A and B both points to the 'real' value .

  7. #7
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    Post

    PS:
    Don't worry about pointers in VB, code in C if you want to use pointers . For example if you call a function, VB automatically just transfers the pointers (You have to declare as ByVal explicitely to transfer *not* the pointer).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width