473,789 Members | 2,495 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB.NET App: Evaluate a variable to use as a Control

Wing
28 New Member
I was wondering if it is possible to evaluate a variable to determine if the variable is a control on the current or other form?

Here is what I am currently looking at. I have two date fields that are using a calendar control. Depending upon which date field opened the Calendar Control, I want the date to be passed back to that control. I would prefer not to have two Calendar Controls. Here is what I have attempted so far.

Expand|Select|Wrap|Line Numbers
  1.     Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
  2.         calMain.Visible = True
  3.         lblControl.Text = "txtStartDate"
  4.     End Sub
  5.  
  6.     Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click
  7.         calMain.Visible = True
  8.         lblControl.Text = "txtEndDate"
  9.     End Sub
  10.  
  11.     Private Sub calMain_DateSelected(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles calMain.DateSelected
  12.         Dim frmText As New TextBox
  13.         frmText.Name = lblControl.Text
  14.         frmText.Text = e.Start.ToShortDateString
  15.         calMain.Visible = False
  16.     End Sub
Jun 22 '07 #1
7 2128
Wing
28 New Member
Found a work around for this but would still like to know if its possible to evaluate variables.

Work Around:
Expand|Select|Wrap|Line Numbers
  1.     Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
  2.         calMain.Visible = True
  3.         lblControl.Text = "Start"
  4.     End Sub
  5.  
  6.     Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click
  7.         calMain.Visible = True
  8.         lblControl.Text = "End"
  9.     End Sub
  10.  
  11.     Private Sub calMain_DateSelected(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles calMain.DateSelected
  12.         If lblControl.Text = "Start" Then
  13.             txtStartDate.Text = e.Start.ToShortDateString
  14.         Else
  15.             txtEndDate.Text = e.Start.ToShortDateString
  16.         End If
  17.         calMain.Visible = False
  18.     End Sub
Jun 22 '07 #2
Lokean
71 New Member
Found a work around for this but would still like to know if its possible to evaluate variables.

Work Around:
Expand|Select|Wrap|Line Numbers
  1.     Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
  2.         calMain.Visible = True
  3.         lblControl.Text = "Start"
  4.     End Sub
  5.  
  6.     Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click
  7.         calMain.Visible = True
  8.         lblControl.Text = "End"
  9.     End Sub
  10.  
  11.     Private Sub calMain_DateSelected(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles calMain.DateSelected
  12.         If lblControl.Text = "Start" Then
  13.             txtStartDate.Text = e.Start.ToShortDateString
  14.         Else
  15.             txtEndDate.Text = e.Start.ToShortDateString
  16.         End If
  17.         calMain.Visible = False
  18.     End Sub
Would this help you?

dim Hold as string
hold = sender.tostring
Jun 22 '07 #3
Wing
28 New Member
This did basically the same thing as the work around.

Expand|Select|Wrap|Line Numbers
  1. ---------------------------
  2. System.Windows.Forms.Label, Text: Promotion Start Date
  3. ---------------------------
  4. OK   
  5. ---------------------------
  6.  
  7. ---------------------------
  8. System.Windows.Forms.Label, Text: Promotion End Date
  9. ---------------------------
  10. OK   
  11. ---------------------------
This is with the following code within each click event
Expand|Select|Wrap|Line Numbers
  1.  Hold = sender.ToString
  2. MsgBox(Hold)
I was hoping to find something more along the lines of
Expand|Select|Wrap|Line Numbers
  1. Dim SentBox as TextBox
  2. SentBox.Name = lblControl.Text
Jun 23 '07 #4
Wing
28 New Member
Still looking for some help with this.
Jun 25 '07 #5
Lokean
71 New Member
Still looking for some help with this.
Could you post what you'd like the output to be?

ex:

Start end
1/2/03 1/2/04


I'm not quite clear on what you want
Jun 25 '07 #6
Wing
28 New Member
I have two labels with two corresponding text boxes (Start Date and End Date). When clicking on one label I would like to open a calendar control. When I click on a date on the calendar control, it will send the date selected to the correct text box. So basically, is it possible to pass a control name into a variable then evaluate it to verify that it is a control and use it as such.

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Private Sub lblStartDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblStartDate.Click
  3.         'Has corresponding txtStartDate
  4.         calMain.Visible = True
  5.     End Sub
  6.  
  7.     Private Sub lblEndDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblEndDate.Click
  8.         'Has corresponding txtEndDate
  9.         calMain.Visible = True
  10.     End Sub
  11.  
  12.     Private Sub calMain_DateSelected(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles calMain.DateSelected
  13.         'Which label was clicked to pass e.Start.ToShortDateString to it's textbox?
  14.     End Sub
  15. End Class
Jun 25 '07 #7
Wing
28 New Member
I worked it out and here is the code that I used to solve my dilema.
Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Dim tBox As TextBox
  3.     Private Sub lblStartDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblStartDate.Click
  4.         calMain.Visible = True
  5.         tBox = txtStartDate
  6.     End Sub
  7.  
  8.     Private Sub lblEndDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblEndDate.Click
  9.         calMain.Visible = True
  10.         tBox = txtEndDate
  11.     End Sub
  12.  
  13.     Private Sub calMain_DateSelected(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles calMain.DateSelected
  14.         tBox.Text = e.Start.ToShortDateString
  15.     End Sub
  16. End Class
Jun 25 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
21210
by: Son KwonNam | last post by:
In XSLT, is this possible to get value from xml using XPath which is in XSLT variable? I mean XPath strings can be dynamic while XSL Transforming. If possible, How?? Because I'm not a native English speaker, it's quite hard to make the problem clear. Please see the following example.
1
1923
by: Christoph Putz | last post by:
Hi! How can i do somewhat like saxon:evaluate in my xslt transformation? I tried to write an extension object, but in my case i need some context information (the value of an xslt-variable) to evaluate the xpath expression. Is there a way to get some context information into an extension object?
33
3052
by: MLH | last post by:
I've read some posts indicating that having tons of GV's in an Access app is a bad idea. Personally, I love GVs and I use them (possibly abuse them) all the time for everything imaginable - have been for years. If the machine has memory to spare and windows can use it - I'm thinking "Why not?" I was wondering what some of you have to say about that, particularly any severe "gotchas" you've had the unfortunate experience to contend with.
2
5819
by: Randall Arnold | last post by:
I'm creating a VB 2005 Express app that hosts the webbrowser control. Everything works well except one area: the Navigating event. In that event, I need to evaluate the URL property of the webbrowser object. The URL is set beforehand in the browser object. I'm using Webbrowser1.URL.ToString to check it. However, I get the following error when I try this: "A first chance exception of type 'System.NullReferenceException' occurred in (my...
4
6906
by: Dave Calkins | last post by:
I have a native Win32 C++ app built with Visual Studio 2005. I'd like to make use of a property grid control in this app. For an example of this, in Visual Studio, see the properties control (select something in a dialog from the dialog editor or a class from the class list and hit F4). I used Spy++, which revealed that the window class of the property grid control used by Visual Studio is "WindowsForms10.Window.8.app.0.378734a". So,...
1
2660
by: shellon | last post by:
Hi all: I met a problem when using document.evaluate() to get text content using XPath, my code is as follows: nodes = document.evaluate("/html/body/div/ul/li", document, null,XPathResult. UNORDERED_NODE_SNAPSHOT_TYPE , null); in the XPath expression "/html/body/div/ul/li", I need to traverse from li to li,
12
3557
by: Les Caudle | last post by:
I've got a .NET 2.0 app that works quite well on all of my test boxes. However, at the client's site, it crashes with 'has encounted a problem' basic dialog. No useful info. I've yet to see a .NET app crash like this, without the verbose dialog that will tell me the line # of the problem (the app was compiled in debug mode). What steps can I take to track this down?
0
4610
by: =?Utf-8?B?YW5rMmdv?= | last post by:
Hi, Thanks in advance for reading this. Not sure where to post this question, but I hope someone in here can help. Trying to write to Event Log in VS 2005 (.NET 2.0) using Enterprise Library 2.0 on a XP Pro SP2 Machine
1
1044
by: John | last post by:
Hi I have a string expression which is evaluated based on value of a variable like this; "MyTable.MyField = (" & MyVar.ToString & ")" I need to save this expression as app setting so I can change it without having to recompile and reinstall the app every time. How do I do this? Creating and app setting say X as "MyTable.MyField = (" & MyVar.ToString &
0
9663
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
9506
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
10404
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...
0
10193
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9979
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
9016
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...
0
5415
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...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4089
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.