473,612 Members | 2,331 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

passing class level variable byref

Cc
hi,
how do I pass byref a variable at class level? , something like how dataset
work,event if declare at class level but it always pass as ref.
Nov 20 '05 #1
5 6216
Hi Cc,

I'm afraid that I don't understand your query. Could you give a few more
details, please?

Regards,
Fergus
Nov 20 '05 #2
Cc
for example
I have form call form1.vb and class call class1.vb . on class1.vb you have
function A and B . if for example u need to pass a variable byref from
form1 to class1 what we usually do is declare function with parameter
passing byref. this is allright if for 1 or 2 function, but if all function
in class1 required the variable tobe pass as ref this could be tedious when
everytime calling the function in class1. that why i ask is there better
solution in this.


"Fergus Cooney" <fi******@tesco .net> wrote in message
news:uk******** ******@TK2MSFTN GP12.phx.gbl...
Hi Cc,

I'm afraid that I don't understand your query. Could you give a few more details, please?

Regards,
Fergus

Nov 20 '05 #3
"Cc" <ko*****@singne t.com.sg> schrieb
for example
I have form call form1.vb and class call class1.vb . on class1.vb
you have function A and B . if for example u need to pass a
variable byref from form1 to class1 what we usually do is declare
function with parameter passing byref. this is allright if for 1 or 2
function, but if all function in class1 required the variable tobe
pass as ref this could be tedious when everytime calling the function
in class1. that why i ask is there better solution in this.


I hope I understood you right. First, you only need to pass the Form "ByRef"
if you want to create a *new* Form in class1. If you don't create a new Form
in Class1, pass the Form ByVal. Second, why don't you write the code in
Form1?
--
Armin

Nov 20 '05 #4
"Cc" <ko*****@singne t.com.sg> schrieb:
I have form call form1.vb and class call class1.vb .
on class1.vb you have function A and B . if for example
u need to pass a variable byref from form1 to class1 what
we usually do is declare function with parameter
passing byref.


Make sure you understand the difference between 'ByVal' and 'ByRef' for
reference types:

\\\
Public Sub Main()
Dim sb As New StringBuilder(" BBB")
changeit1(sb)
MsgBox(sb.ToStr ing())
sb = New StringBuilder(" BBB")
changeit2(sb)
MsgBox(sb.ToStr ing())
System.Console. ReadLine()
End Sub

Private Sub changeit1(ByVal s As StringBuilder)
s = New StringBuilder()
s.Append("Bla")
End Sub

Private Sub changeit2(ByRef s As StringBuilder)
s = New StringBuilder()
s.Append("Bla")
End Sub
///

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #5
Hi Cc,

|| but if all function in class1 required the variable
|| to be pass as ref this could be tedious when
|| everytime calling the function in class1.

I'm not sure what's tedious about it? Is it too much to type ByRef in your
parameter list ?

However, if the variable that you are passing is an object of any sort, it
is <already> a reference variable and wouldn't need ByRef.

Have I understood your query ?

Regards,
Fergus
Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
16831
by: Andy Read | last post by:
Dear all, I thought I understood passing parameters ByVal and ByRef but I clearly don't! If I define a simple class of: Public Class Person Public Name as String Public Age as Integer End Class
2
5301
by: Ryan Malone | last post by:
Passing Dictionary object byref Ive created an ASP class that uses a dictionary object which is filled from a recordset. It passes the object to the propterty of another ASP class byref: Public Property Let dicReplaceVars(byref vdicReplaceVars) set p_ReplaceVars = vdicReplaceVars End Property
39
7630
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down indicate: a) That I don't know enough b) Passing arguments by ref is bad
7
1828
by: Rik | last post by:
Hi, I have an Multithreaded application in VB.NET. I inherited a Sub Class and which define an Array variable of string in that Sub Class. Now I want to Carry that Sub Class Array back to the Calling Class?? without using Function Return. Can any one Help me in this regard.
2
10264
by: Witold Iwaniec via .NET 247 | last post by:
It seems that when you pass an object to a function it is always passed by reference even if it is explicitly declared ByVal. Is it the behavior of VB.Net? Here is sample code from sample Asp.Net application. The sub loadValueByVal takes the argument by value so after returning to calling method, the object should be unchanged but it is not Public Class ITest Private MyName As String Public TestId As String Public Sub New()
11
8114
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line number) which is the last line of the following sub routine: ' procedure modifies elements of array and assigns ' new reference (note ByVal) Sub FirstDouble(ByVal array As Integer()) Dim i As Integer
8
1473
by: Peter | last post by:
I will excute the code below to get MethodName array. These codes are edited under VS2003. Now I want to upgrade it to VS2005,but VS2005 gives me a varning message: The varible "sSourceMethodName" may throw a Null reference exception because it passes using "Byref" before being assigned. Although it's just a warning I still want to let ift fit the VS2005's recommended mode. Any suggestions will be appreciated,
2
2845
by: Phoenix | last post by:
Hi Friends , Could anyone please help me to resolve the following issue : I pass an array of structures to a dll written in VC++ 6.0 whih fills it with data . The following works well for VB 6.0 but when I wrote the same piece of code in VB 2005 the array of structures remained empty even after the API call : I have a structure as follows :
0
1525
by: VaBa | last post by:
Hi, Need some help.. I have a VBA class module in MS ACCESS. In the same MS ACCESS app, I am calling a .NET DLL (which i have exposed as COM-visible) and passing BYREF an instance of the VBA class module as an argument to one of the .NET DLL method. Step by step, here's what i am doing: 1. Create vba class module in MS ACCESS Option Compare Database Option Explicit ... Public Function DoSomething(ByVal S as String, ByRef RetVal as...
0
8173
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8115
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8617
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8254
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8422
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6082
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4047
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2555
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.