Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 4th, 2008, 6:35 PM   #1
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 272
Rep Power: 2 Jabo is on a distinguished road
Visual Basic pointers

Ok, I know that when passing variables to functions, you can either pass by value or pass by reference. Does this mean that VB uses pointers like C and C++ except that it's abstracted to prevent programmer errors?
Jabo is offline   Reply With Quote
Old Jul 10th, 2008, 8:40 AM   #2
melbolt
Hobbyist Programmer
 
melbolt's Avatar
 
Join Date: Feb 2005
Location: PA, USA
Posts: 242
Rep Power: 4 melbolt is on a distinguished road
Send a message via AIM to melbolt Send a message via Yahoo to melbolt
Re: Visual Basic pointers

yes, it is considered unsafe code since .NET uses its special garbage collector to free up memory and pointers fall outside the scope of the garbage collector.

in C# however there is a way to use pointers, but its not common.
http://www.c-sharpcorner.com/UploadF...sInCSharp.aspx
__________________
I have never let my schooling interfere with my education. -Mark Twain-

Xbox live gamertag: melbolt
melbolt is offline   Reply With Quote
Old Jul 10th, 2008, 9:08 AM   #3
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 549
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: Visual Basic pointers

Quote:
Originally Posted by melbolt View Post
yes, it is considered unsafe code since .NET uses its special garbage collector to free up memory and pointers fall outside the scope of the garbage collector.
I'm not an expert VB programmer but pass-by-reference is pretty common in VB. And I doubt the .NET garbage collection is even relevent to the question.

Quote:
Originally Posted by melbolt View Post
in C# however there is a way to use pointers, but its not common.
http://www.c-sharpcorner.com/UploadF...sInCSharp.aspx
That is completely irrelevent to the question of VB. Who gives a dam what C# does or doesn't do.
__________________
True Terror is to wake up one morning and discover that your high school class is running the country - Kurt Vonnegut Jr.
Ancient Dragon is offline   Reply With Quote
Old Jul 10th, 2008, 10:10 AM   #4
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3 Jimbo is on a distinguished road
Re: Visual Basic pointers

I'm not entirely sure how the language is implemented, but I think it works similarly to C#'s ref keyword. If you have Sub Foo(ByVal bar as SomeType) you can modify the contents of the SomeType object locally scoped as bar; since it's the same object as the calling function, these changes would go back. If you make bar point to a new object, then the corresponding variable in the caller will not be affected. If, on the other hand, you have Sub Foo2(ByRef bar2 as SomeType) then any changes to what object bar2 points at or its contents will affect the caller's variable as well.

<reiteration of disclaimer>I'm not positive that this is how it works, and I'm too lazy to write an app to check, but that's how I'd guess it works</reiteration>
__________________
<insert disclaimer here>
<insert shameless plug for Visual Studio here>

Last edited by Jimbo; Jul 10th, 2008 at 10:37 AM.
Jimbo is offline   Reply With Quote
Old Jul 15th, 2008, 12:50 AM   #5
melbolt
Hobbyist Programmer
 
melbolt's Avatar
 
Join Date: Feb 2005
Location: PA, USA
Posts: 242
Rep Power: 4 melbolt is on a distinguished road
Send a message via AIM to melbolt Send a message via Yahoo to melbolt
Re: Visual Basic pointers

Quote:
Originally Posted by Ancient Dragon View Post
I'm not an expert VB programmer but pass-by-reference is pretty common in VB. And I doubt the .NET garbage collection is even relevent to the question.


That is completely irrelevent to the question of VB. Who gives a dam what C# does or doesn't do.
Yea, pass-by-reference is used alot, if you thought I said it wasn't or that it was bad practice, that is not what i meant at all. I was just saying that is why I thought the .NET Framework abstracted it out this way, and the garbage collector was brought into the topic because the .NET Framework's garbage collector will free these resources allocated "under the hood" by the .NET Framework for you rather than doing it the unmanaged way and getting into more memory leaks and whatnot.

check the link I put up there

quote:
"The C# statements can be executed either as in a safe or in an unsafe context. The statements marked as unsafe by using the keyword unsafe runs out side the control of Garbage Collector. Remember that in C# any code involving pointers requires an unsafe context. "

question #2: I disagree that it is completely irrelevant, that's my opinion. I give a damn because they are very similar langauges, they both run on the .NET Framework and often if you have a career programming in one there is a good chance you will use the other at times as well. often controls written in one langauge of the .NET framework are not available in the other, so what do you do? I've had lots of times where I use C# assembly within a VB .NET app That's why this was brought into the conversation.

extra information is not always a bad thing, if i'm wrong, correct me but please go into detail so that I and others may learn from my mistakes.
__________________
I have never let my schooling interfere with my education. -Mark Twain-

Xbox live gamertag: melbolt
melbolt is offline   Reply With Quote
Old Jul 15th, 2008, 1:21 AM   #6
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 272
Rep Power: 2 Jabo is on a distinguished road
Re: Visual Basic pointers

Quote:
Originally Posted by Jimbo View Post
I'm not entirely sure how the language is implemented, but I think it works similarly to C#'s ref keyword. If you have Sub Foo(ByVal bar as SomeType) you can modify the contents of the SomeType object locally scoped as bar; since it's the same object as the calling function, these changes would go back. If you make bar point to a new object, then the corresponding variable in the caller will not be affected. If, on the other hand, you have Sub Foo2(ByRef bar2 as SomeType) then any changes to what object bar2 points at or its contents will affect the caller's variable as well.

<reiteration of disclaimer>I'm not positive that this is how it works, and I'm too lazy to write an app to check, but that's how I'd guess it works</reiteration>
In my VB class, it was said that by ref passes a reference into the function, allowing you direct access to that variable/object. I thought pointers were what made C and C++ so powerful, so if VB has them also, why do people not like VB or consider it a toy language?
Jabo is offline   Reply With Quote
Old Jul 15th, 2008, 5:50 AM   #7
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 549
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: Visual Basic pointers

Quote:
Originally Posted by melbolt View Post
question #2: I disagree that it is completely irrelevant, that's my opinion. I give a damn because they are very similar langauges, they both run on the .NET Framework and often if you have a career programming in one there is a good chance you will use the other at times as well. often controls written in one langauge of the .NET framework are not available in the other, so what do you do? I've had lots of times where I use C# assembly within a VB .NET app That's why this was brought into the conversation.

extra information is not always a bad thing, if i'm wrong, correct me but please go into detail so that I and others may learn from my mistakes.
This is a VB board, not C#. If the OP wanted to know something about C# he/she would have posted in the C# board. You are correct about what you said above, but lets not intermingle languages here when its not necessary. Stick to the topic being discussed and not diverge too much. If I want to know how to do something in VB then I don't want to know how its also done in other languages.
__________________
True Terror is to wake up one morning and discover that your high school class is running the country - Kurt Vonnegut Jr.
Ancient Dragon is offline   Reply With Quote
Old Jul 15th, 2008, 11:48 AM   #8
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,034
Rep Power: 5 lectricpharaoh will become famous soon enough
Re: Visual Basic pointers

Don't forget that most of the similarities mentioned are between C# and VB.NET, not legacy VB.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Jul 15th, 2008, 9:26 PM   #9
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3 Jimbo is on a distinguished road
Re: Visual Basic pointers

Quote:
Originally Posted by Jabo View Post
In my VB class, it was said that by ref passes a reference into the function, allowing you direct access to that variable/object. I thought pointers were what made C and C++ so powerful, so if VB has them also, why do people not like VB or consider it a toy language?
Because of either it's reputation (as a Basic language), or because of it's unfamiliarity. We use VB.NET for most of our testing at work (on my team at least), but the devs tend to prefer C#. Each language has some things unique to it, but since both are developed by the sibling teams, they end up copying each other often - sort of leapfrogging with new language features. It's pretty fun sometimes to listen to people arguing the merits of each (and yes, "familiar syntax" comes up often for C#).

Regarding pointers, a lot of their benefit is inherent in C# and VB.NET. Note that you don't actually get a pointer, but it's more like a "safe" pointer: most of the powerful features, but less ways to blow up your program.
__________________
<insert disclaimer here>
<insert shameless plug for Visual Studio here>
Jimbo is offline   Reply With Quote
Old Jul 16th, 2008, 3:17 PM   #10
melbolt
Hobbyist Programmer
 
melbolt's Avatar
 
Join Date: Feb 2005
Location: PA, USA
Posts: 242
Rep Power: 4 melbolt is on a distinguished road
Send a message via AIM to melbolt Send a message via Yahoo to melbolt
Re: Visual Basic pointers

Quote:
Originally Posted by Jabo View Post
In my VB class, it was said that by ref passes a reference into the function, allowing you direct access to that variable/object. I thought pointers were what made C and C++ so powerful, so if VB has them also, why do people not like VB or consider it a toy language?
In my opinion because some people:
-do not realize VB and VB .NET are very different.
-are scared of learning a somewhat unique syntax that doesn't quite stick as much to other langauge syntax (curly braces, dim, ordering of type declaration and variable name, etc)

VB .NET and C# are very close, most of the differences are syntactical, I switch back and forth at work constantly from one to the other and I have to say that in a lot of cases VB .NET is my preference, people struggle with the unique syntax of it but once you know it, it has a lot of very nice things like "isnumeric" and "my" that C# doesn't have. but these are just conveniences, there are usually always ways to do whatever you need to do even without these conveniences in the other langauge.

VB .NET or C# it all comes down to MSIL in the end.
C# is not faster than VB .NET as some people claim.
__________________
I have never let my schooling interfere with my education. -Mark Twain-

Xbox live gamertag: melbolt

Last edited by melbolt; Jul 16th, 2008 at 3:28 PM.
melbolt is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual Basic to java HELP! araujo2nd Visual Basic .NET 1 Feb 13th, 2008 9:36 AM
File Mapping in Visual Basic? bmad6 Visual Basic .NET 4 May 16th, 2006 9:37 PM
want to learn Visual Basic eax Visual Basic 14 May 1st, 2006 12:12 PM
visual basic pixel image comparison youngnoviceinneedofhelp Visual Basic 3 Mar 19th, 2006 1:57 PM
Enquiry About Visual Basic Project kbkhoo5053 Visual Basic 13 Feb 15th, 2005 2:20 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:20 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC