Literal Substitution - Instantiate Form Objects Using Variables As Literals
Oct 23, 2008
What I need to do is create comboboxes populated with values from a CSV for each class object selected from an Active Directory schema.
So lets say twelve classes are selected, the next form will display the class names in a checkedlistbox and will require twelve comboboxes for associating AD classes to CSV fields. Since the number of AD classes selected will always vary, is there a practical way to code it so that the objects can be instantiated from values stored in a variable?
Other languages support macro substitution, where the variable's value is interpreted as a literal at runtime. Developing in Visual Studio 2005, VB version 8 .netFramework 2.0xxx
View 2 Replies
ADVERTISEMENT
Jan 20, 2010
I am having some real issues with this one. I have a class which contains two other objects...but I cannot seem to instantiate those sub objects. Here is the code for my class:
Code:
Option Explicit On
Public Class Boot
[code]......
View 1 Replies
Jan 14, 2010
I have a program that uses two forms. The program opens to the Main form, and the user can navigate to the other form from the Main form through use of a button. Here's the way I've currently written it: When the Main form loads, it declares and instantiates the other form during the load procedure. When the user presses a button, the second form is displayed by means of the ShowDialog method. On the second form, there is a Return to Main Screen button which closes the second form, bringing the user back to the Main form.
So, here's the structure of the code:
Code:
Public Class frmMainForm
Dim frmSecondForm As New SecondForm
Private Sub btnSecondForm_Click(blah, blah, blah) Handles blah, blah, blah
[CODE]...
Here's my reasoning: Originally, I wrote the code so that a new instance of the second form was created every time the button was pressed. The problem was that whatever data was displayed on the second form, previously, was lost when the user returned to it a second time. Since the user would be switching back and forth between these forms, frequently, I needed that data to persist.
What is the best practice for accomplishing this:
1) Declare and instantiate the second form on program start, as I have done, and use the button simply to show the form?
2) Declare and instantiate the second form each time the button is pressed but maintain the variables on the Main form and pass them ByRef to a custom constructor for the second form? Is this even possible?
3) Something else?
View 5 Replies
Dec 18, 2009
why I need to instantiate a form instead of form.show?
View 20 Replies
Feb 25, 2010
when using variables in object names.I have a Public class which is called "Tank".In that class, there is a public property called "direction" of an integer type.I keep getting the error:
"Tank is a type and cannot be used as an expression"What I'm doing wrong here ?
Public Class mainroutines()
Create Instances of tank
Private Tank1 As New Tank()[code]....
View 3 Replies
Oct 15, 2011
In a program I've been working on I would like to start a process and save it in a variable of type Process. This is so I can kill it later, if needed, and change the window type.
View 2 Replies
Dec 21, 2011
I have a small class of Object CellValue
Friend Class CellValue
Public CellColor As Color = Color.White
Public CellShape As Shape = Shape.Blank
Public CellName As String = ""
End Class
Then in my main I make an array of CellValue but I want to know if the values are also being passed down with the array.
Dim Plan(SizeW - 1, SizeH - 1) As CellValue
Dim CellW As Integer = PictureBox1.Width \ SizeW
Dim CellH As Integer = PictureBox1.Height \ SizeH
[Code].....
Are CellName, CellShape and CellColor being tied to each element in the array?. The reason is because I need to use these properties to tie certain functions to them. The CellName should have a MachineID which I would have to use to pull some info from a Database.
The Array should also be serialized and deserialized to XML as customer needs to create/edit and delete certain values in the array. And in order to save the array has to be in XML
So the Questions are does it save the CellName, CellShape and CellColor for each element, will it be affected if I serialize and deserialize using XML. If possible, how can I call up the Cellname p.e for a specific array element.
View 5 Replies
Feb 7, 2010
I have a user control that inherits the FW ListView and I need to dispose of two objects when the form's disposing of it's objects. Here's what I've concluded already, am I on the right track?
[Code]...
View 3 Replies
Jul 30, 2011
I have not tested this, but I am fairly certain it would not work.When my program installs, I want to ensure that the default SaveFile directory is into a directory under the program's directory.For example, if the program installs to C:Program FilesConcept VisionsWorldFileMaker, I want the SaveFile dialog to default to C:Program FilesConcept VisionsWorldFileMakerWorldFiles.I can see in the File System of the setup project, under the property 'DefaultLocation', it's value is:
[ProgramFilesFolder][Manufacturer][ProductName]With Manufacturer = Concept Visions and ProductName = WorldFileMaker, am I correct in assuming this would be C:Program FilesConcept VisionsWorldFileMaker on a default Windows machine?
Below is the code I use to open the SaveFileDialog to save the file. The line in bold is the line I have my question about. How do I get the saveFileDialog1.InitialDirectory = "C:Program FilesConcept VisionsWorldFileMakerWorldFiles" without actually hard-coding it as "C:Program FilesConcept VisionsWorldFileMakerWorldFiles"? I want to use a substitution variable similar to "[ProgramFilesFolder][Manufacturer][ProductName]".
Eventually, I want to learn how to allow the user to install in a folder of choice. If I am correct, I would need such a substitution variable.
[Code]...
View 4 Replies
May 20, 2011
have the following code and would like to know how I can substitute the filename (i.e.,test.rtf) with the name of a Textbox. For example, I have several Textboxes that I want to add and associate individual comments to. That is, once the comment is created I will SaveFile with the TextBox name. Each of these Textboxes will have their own comment
Private Sub btnOpenFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenFile.Click
[code]......
View 6 Replies
Aug 20, 2010
I'm trying to get a VB.net (express 2010) app to connect to a socket server (keeping the connection open), how would I go about this? Right now it works using flash XMLsocket, I'm trying to build a new client without flash, using the existing server.Currently I'm just using a simple window displaying messages, and a place to send messages.
It says I'm connected, but it displays no messages, and sent messages appear to have no effect, when I telnet to the server using the same IP and port, I can see messages coming in to me, so i know i can connect to the server. Here is my code:
Imports System.Text
Imports System.Net.Sockets
Public Class Form1[code].......
View 1 Replies
Jun 3, 2009
In re-engineering a windows forms application, I find that a lot of code-behind in the various form classes is duplicative and I'm trying to centralize as many procedures as possible into a base class which can be inherited and used by the subclassed forms.
This process seems to be going well and is making the code in my subclasses much simpler and hopefully easier to maintain, but I'm not sure where to draw the line between leaving code in the subclasses and engineering for generic resusability and moving it to the base class.
Specifically, in some subclasses I have code which manipulates variables and objects specific to the subclass, and although I could move the code-behind into the base class, the base class code references specific objects which are needed to compile. For example, each subclass manipulates a databound datagridview and form detail controls which allows the user to select between multi-record and detailed single-record views of a datatable.
In Visual Basic 2008 do I need to declare dummy data objects in the base class so that the base class will compile? Or is there a way to indicate that the data objects will be provided by the subclass?
View 13 Replies
Nov 22, 2011
I'm trying to get the ATM Class to Instantiate on the Form class.
[code]...
ISSUE = " 'ThisATM' is used before it has been assigned a value. A Null reference exception could result at runtime"
The Other problem i am having is with a class in the program called CardReader. What am i supposed to type to let the code below be able to "read" the read function on the Form1?
[code]...
View 7 Replies
Aug 13, 2011
I have an array of variables called VolumeArray(12) which is declared as publlic shared in the main form1.I have a second form2 which allows the user to input various values. When this form2 is closed, I need the data the user has entered to update the values for VolumeArray(12) within Form1.
View 3 Replies
Jul 28, 2009
I have a class called Profile that has some simple properties and then it can have a collection of ProfileItem that again has some simple properties and then it can have a collection of ProfileItem (RECURSION). Now I am trying to generated a very simple save function using XML Literals that come with VB.NET (3.5).
[Code]....
View 1 Replies
Sep 2, 2009
is there a way to enable IntelliSense for XML literals in VB9 (VS 2008)?The ideal source of IntelliSense is an XSD document, but I can use anything else format to do it.
View 2 Replies
Oct 2, 2010
Is it possible to use variables like <%=person.LastName %> in XML string this way?
XElement letters = new XElement("Letters");
XElement xperson = XElement.Parse("<Table><Row><Cell><Text>
<Segment>Dear <%=person.Title%> <%=person.FirstName%> <%=person.LastName%>,
[Code]....
If it's possible, it would be a lifesaver since I can't use XElement and XAttribute to add the nodes manually. We have multiple templates and they frequently change (edit on the fly).
If this is not doable, can you think of another way so that I can use templates for the XML?
[URL]
View 1 Replies
Feb 26, 2012
How do I use character literals in VB?I get error for following code:
op as Char
op = '+'
[code].....
View 1 Replies
Aug 30, 2010
I am using XML Literals and Linq to XML to read/write data to an external system.[code]The client now wants to put the url in a parameter table so the table can change to point to a test server or a real server. I assume that I cannot put a variable in my Imports statement.So how to I access the correct URL from a variable?url...
View 13 Replies
Dec 7, 2009
I'm using the following function to brighten up color values (it's a lambda in my code, but that shouldn't make a differende):
Function ReduceDistanceTo255(ByVal i As Byte) As Byte
Return i + (255 - i) 2
End Function
It won't compile, since the compiler interprets 255 and 2 as integers rather than bytes, making the result of type Integer. Unfortunately, there is no Byte type character, so I cannot just write 255B or something like that.There are a few obvious workarounds to the problem:
Function ReduceDistanceTo255(ByVal i As Byte) As Byte
Return i + (CByte(255) - i) CByte(2)
End Function
and
Function ReduceDistanceTo255(ByVal i As Byte) As Byte
Return CByte(i + (255 - i) 2)
End Function
[code]....
The first one is just plain ugly and hard to read, because every literal needs to be CByted. The second one performs calculations in integers and then converts the result to Byte, which is OK, but not as elegant as a pure-Byte operation. The third workaround doesn't require CBytes, but it's drawbacks are obvious.
View 3 Replies
Jul 26, 2010
In VB.NET I can easily embed strings into XML literals using <xml><%= "my string" %></xml>. How can I embed an XElement instance? I know I can use methods on the XElement, XNode, etc classes, but I'd like to do it in the XML literals if possible.
View 2 Replies
Nov 6, 2009
I am constructing some XML using XML literals. I have a function which returns an XElement.
Function RootElementFormattingFunction() as XElement
Return <Root Data="foo"/>
End Function
In reality it is a bit more complicated than that, but it is called from several places. Now I have linq sequence which generates a set of nodes which I want to make children of the XElement returns
[Code]...
View 1 Replies
May 3, 2011
I'm trying to use the builtin XML literals feature to create/read xml files using my own schemas, but I don't see a way to cast an abstract XElement from a base type to a more derived type.The schema/xml below shows in general what I'm working with, but using XML literals only allows me to use the base type in the IDE, so the xml below is treated as a collection of elements of the base type, instead one of the base type and one of the derived type.
<schema targetNamespace="Test" xmlns="Test">
<xs:complexType name="Base" abstract="true">
<xs:attribute name="Id" type="xs:int">
[code]....
View 1 Replies
Jul 16, 2009
Is there any other way of removing a specific tag other than looping through every tag and checking a certain value? I would assume this could become of timely process if there are many tags.
[Code]...
View 3 Replies
Jun 5, 2009
As basic as this is, it took me a few minutes to figure out, so wanted to share with the rest of the community to avoid anyone else from wasting their time.
I am attempting to generate the following XML string using VB.NET XML Literals
<Books>
<Book Name="The First Book" />
<Book Name="The Second Book" />
</Books>
[Code]....
But the compiler is complaining about the quotes that are supposed to surround the attribute value. I tried using single quotes, two double quotes, nothing works.
View 1 Replies
May 4, 2009
My problem is that I want to include control structures in the embedded XML. Specifically, I want to include or exclude an entire element (not just its contents) based on a boolean expression. The question extends to other control structures as well though.
I'd expect the <% %> syntax to support inling of code but that doesn't seem to function in VB.net's implementation (as opposed to the <%= %> for inlining the result of an evaluated expression, which does).
Here's some very simple code by way of example only.
Public Class Foo
Private bar As String = Nothing
Private baz As String = Nothing
[code]....
I'd much prefer to use the format of getXMLBad() if possible. In this short example it doesn't seem critical, but in much larger examples, the inlining of the logic is more readable and maintainable than the "assembly" style in getXML(). This especially true when the logic is in the middle of large block of static XML and when coding to a very strict or complex schemas.I'd be interested in the capability to extend this to Looping constructs as well.
View 1 Replies
Mar 23, 2012
Currently am working on a project that requires me to create some XML for use with a graphing plugin. I'm using XML literals and LINQ to SQL as follows
Dim x As XElement = _
<chart caption='Aantal aanvragen' xAxisName='Dag' yAxisName='Aantal'>
<%= From d In dailies Select _
[code].....
View 1 Replies
Nov 22, 2011
Dim task As XElement = <task>
<body>body</body>
<optional><%= myVar %></optional>
[code].....
View 1 Replies
Sep 2, 2009
I have a masked textbox on my form for a phone number. I want to store its value in my Database without the literals as the database field for that phone is only 10 characters long. How do I store this value in the database field without any literals.
View 3 Replies
Apr 22, 2009
been working on a large scale project and Iow looking into the document print engine for the application. been a while since Ie built an app that retrieves data from the database and outputs to Word. I generally always used the mail merge feature of Word but after reading the link above this seems far easier.
View 2 Replies