Declaring Object Variable - Inactive During Initialization Of Module?
Feb 16, 2012
Got a question regarding declaring a variable. Basically I have a module that writes to a text file using textwriter which is declared for the whole module to use at the top of the code. But what I want to do is clear the contents of the text file when the program is executed (using file.writealltext). The problem I have is that the file is obviously already in use as a result of the textwriter and the file cannot be modified because of this.
My question is: is there any way of declaring the textWriter object later on (not during the initial initialization of the module) without passing the object between functions? Setting the variable as inactive or something along those lines during initialization would be ideal.
View 1 Replies
ADVERTISEMENT
Oct 19, 2010
what is the difference between declaring a variable in this way
ByVal
List As IEnumerable as
a parametre in a function
Dim
[Code]....
View 1 Replies
Feb 11, 2009
I am new to the forum and new to the visual studio set up and have been working at a practical at home and have ran into some difficulty. The notes say that I am to declare several module variables below the section entitledI have the rest of the form complete but have been unable to locate where I am to place this code
View 1 Replies
Feb 4, 2009
I am experiencing some trouble with the autogenerated initializecomponent function. Visual Studio insists on initializing a variable like the following, when I drag a usercontrol onto a form:
Dim HierarchyTreeNode1 As NewDelfiLib.HierarchyTreeNode = CType(New System.Windows.Forms.TreeNode(""), ND.HierarchyTreeNode)
View 1 Replies
Jul 19, 2011
I create a form2.vb which have a report viewr and modifier set to public. In reportviewer properties i add the Report1.rdlc Now i want to pass the vlue in the textbox at report1.rdlc i use following steps and code to do it butnot sucessful yet i need ur guidelines first from menu click report ___ report parameter and set the parameter name like conparm. Then i frm2 load event i write following
[Code]...
View 1 Replies
Dec 27, 2009
I am Visual Foxpro Programmer and moved to Vb.Net.
In Foxpro for each control I add to the form, there is a method called Init where this is executed only once when the form run.
I am doing the code for a control in the Form_Load and things working fine.
View 4 Replies
May 27, 2011
I am Visual Foxpro Programmer and moved to Vb.Net. In Foxpro for each control I add to the form, there is a method called Init where this is executed only once when the form run.
View 2 Replies
Aug 2, 2011
why is this code not working?
Dim tcplistener As New System.Net.Sockets.TcpListener
This does not compile with the error "Overload resolution failed because no accessible 'New' accepts this number of arguments." The thing is, I have to declare it as New because otherwise I will get a null-reference exception...
View 1 Replies
Feb 22, 2010
The last line in the code below throws the error. Is it because I haven't intialized the size of the byte array?
Public Class Form1
Private toSocket_IPP As Byte()
Public Sub New()
[code].....
View 3 Replies
Apr 26, 2011
Trying to declare some arrays. I haven't worked with them that I remember. I always took the long road, of declaring each and every variable, but would like to learn this method. The problem is I'm having trouble with the methods I'm finding on the net..[code]for some reason there is a squiggly under each MonsterName except in the declaration that says "declaration expected"
View 16 Replies
May 30, 2012
We can declare a byte variable like this, for hex '88'
Dim bytes = New Byte() { &H88 } My case, 88 is assigned to a variable, hexvalue
How to declare the byte with the variable hex value?
Dim bytes = New Byte() { &H & hexvalue }the above throws syntax error.
View 2 Replies
Feb 19, 2011
I'm trying out a program which I found on the net. Why is it necessary to put to curly braces at the end of the statement? It gives an error: "Byte has no constructors". Dim data As Byte() = New Byte(1023) {} I can't put the code like this either, it produces the error "byte cannot be a 1-dimensional array".
[Code]...
View 2 Replies
Mar 29, 2012
if this silly but I am trying to declare a string variable by the following line
[Code]...
View 2 Replies
Feb 8, 2010
I have declared this variable in a module : Public GenericForm As System.Windows.Forms.Form
and then through code I can asign to that variable a specific form .For example GenericForm = Form1. Then I can use that variable to handle that specific form , for example :
GenericForm.Show
My problem begins when I want to handle a control on that form , for example :
GenericForm.TextBox1.Text = "aaa"
This code creates an error reading :TextBox1 is not a member of System.Windows.Forms.Form.I have been using code like this in VB6 and was quite useful ,but now in VB .NET I cannot .You see I have many forms on which there are some text boxes with the same name,so I declare a generic variable as Form and accordingly insert the code the desired text box conform the form I wish each time . Can I do this in VB .NET too ?
View 23 Replies
Dec 21, 2011
I have started using the builder class to create my connection strings for the sole purpose of making more generic connectivity code. However, I am stumped on this issue. The MS eConnect product apparently expects to receive integrated security=SSPI in its connection string if you want to use integrated security, (vs Integrated Secturity=True). I thought I would just pass "Trusted_Connection"="SSPI" to the builder class.
as it turns out, the item for Integrated Security is boolean and despite what the documentation says, will not give me SSPI in my connection string. Has anybody else found this issue and is there a simple fix for it? as for now, I'll simply strip out the item and replace it in my string.
View 3 Replies
Nov 4, 2010
I'm having a problem declaring a variable and setting it correctly.
BEGIN WORKING CODE:
private sub doSomething
Dim tokenHandle As New IntPtr(0)
Dim dupeTokenHandle As New IntPtr(0)
[Code].....
View 1 Replies
Apr 26, 2010
I am new to VB.NET but used to write a lot of code in VB 6.
How do i declare a variable length array in VB.NET?
In VB6, i would just put:
Dim sArrayList() As String
But when I do that in VB.NET, it highlights my array name and says "unused local variable". What do I need to do to get it to work without an error?
View 2 Replies
Aug 15, 2011
I am building a generic search form in my application. This will allow the user to search for various records throughout the application. The one thing I cannot seem to figure out is how to allow the declaration of the TableAdapter to change at run-time. Each part of the app will be passing a variable to the search form to specify which table should be loaded. In the form class I have the following:
FRIEND WITHEVENTS tbaSearchData AS database.databaseTableAdapters.TableOneTableAdapter This is great for TableOne. But, I have about a hundred tables that could be searched through. To load the data I'm using a DataGridView and populating it via a private method.
View 2 Replies
Apr 5, 2011
I have a class that I would like to link at construction to a given control (say a textbox)
I know I can put a variable into a subroutine referentially but is there a way to store it in the same capacity?
View 1 Replies
Apr 18, 2010
I've got
Option strict ON
Option explicit ON
How should I declare the variable:-
Dim bounds as? = (From item In xml...<bounds>
[Code]
View 7 Replies
Nov 5, 2009
These two snippets do the same thing - is there one that's better than the other, or is it just a matter of preference?
Using context As MyDatabaseDataContext = New MyDatabaseDataContext()
Dim test = context.Employees.Count
End Using
vs.
Dim context As MyDatabaseDataContext = New MyDatabaseDataContext()
Dim test = context.Employees.Count
View 6 Replies
Jul 7, 2011
After many many years of using Classic ASP, I am attempting to delve into the world of ASP.Net using VB. I have gotten way to use to being able to declare variables on a page, inlclude that file and use it everywhere. I am struggling to declare a global variable. I just need
[Code]...
View 2 Replies
Sep 28, 2009
I come from C# (use VS 2005, .NET 2) and I know that when I declare a private variable I can "extract" from it the corresponding "property". In VB.NET I've declared a lot of properties (in the diagram class designer). Now am I forced manually adding the corresponding private fields?
View 4 Replies
Oct 5, 2009
If you want a instance of an object to be created when a form loads or another class is created, you have two options:
Public class example
private IAmAObject As IAmAObject
public sub new()
[CODE]...
Or like this:
public class example
private IAmAObject as new IAmAObject
public sub new()
[CODE]...
I always use the first one. It's more type work but I think it's neater. How about you people and is there any real difference between the two?
View 4 Replies
Mar 30, 2011
I'm trying to develop a class in VB .NET in order to manage a language globalization stored in a database and editable by the user.What I need is to know what kind of class I need to declare in order to use it without declaring a new object. For example, the way My.Settings is used.
One of the goals is that in some project the developer imports the reference and after that access directly to a property. For example: My.CustomLanguage.GetWord("Hello") without declaring objects.
Is this possible? And if it's what is the best way to aproach it?
View 3 Replies
May 25, 2012
How do I declare a fixed length variable arra
Structure MyInformation
<VBFixedString(4),System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr,SizeConst:=4)> Public ReturnStatus As String
[code]....
View 2 Replies
Oct 28, 2010
What's best practice (in VB.Net):
Function GetSomething() as String
GetSomething = "Here's your string"
End Function
or
Function GetSomething() as String
Dim returnString as String = "Here's your string"
Return returnString
End Function
Obviously, neither of these implementations make any sense, but they're just meant to illustrate my point. Is there anything to be gained by using GetSomething itself to store the return value instead of declaring returnString locally and then returning that (does it avoid having an extra string allocated/instantiated - and if so, are there any performance/memory benefits)?
View 6 Replies
Jun 2, 2011
I'm declaring a line at the top of my code window. Dim sTemp as String = textbox1.text
I tried commenting a few things related to the code but none of it makes it work.
View 2 Replies
Oct 2, 2009
I've been working in .NET for some time now, but occasionally I still get confused by a disparity between the framework and my prior experience in C++.In .NET, all objects are either value types or reference types. Reference types are allocated on the heap while value types are allocated on the stack (in the current CLR implementation, anyway). I get that. However, at least in VB.NET, you can still define a constructor on a value type.
Public Structure Coordinates
Public x As Integer
Public y As Integer
[code]....
View 3 Replies
Mar 31, 2010
I have two forms A and B. B is a child of A - i.e. I have a button on A that pops up form B. I want B to be able to access and change data (e.g. an instance of an object etc.) in A and also to call some function in A. At the same time I'd like to preserve the right to alter the data in A without opening B. I've achieved this using the following (i.e. by declaring the object and method as Friend):
Public Class frmA
Friend _data as Hashtable
Friend Sub GetData()
If _data IsNot Nothing Then
_data As New Hashtable
Is there anything inherently wrong with the what I've done and if so how can I achieve a similar result? (It seems to work - I can read, add to and change the values in the _data Hashtable from within form B and when B is closed the values persist i.e. I can access the changed values from within form A. I just dont know if its a horrible fudge).
View 2 Replies