Solved

By-passing compile time object exists check

Posted on 2006-11-23
9
158 Views
Last Modified: 2010-04-23
Hey guys, hope someone can help me fairly urgently. I am writng code that will be re-used in various differing applications and basically I want whoever ends up developing software to be able to decide which information to have on their form.
I am simplyfying things by creating some code we can reuse, in this code I am making it write to an object on the form (a series of text boxes) of which some may not exist. I want to be able to skip the VB code-checking facility so that I can compile and run the code and just have an error checker that supresses when data is sent to an object that doesn't exist.

So, to re-word that a bit, I have say 20 pieces of data, when i call a function from my class file I want it to take a reference, look through an object I have already created, locate the record and attempt to write the data to 20 text boxes, whether the developer has put them on the form or not. If they don't appear on the form then I want the code to siply go to the next piece in the record and attempt to move that to a text box.

We all know VB throws a strop and says that if text1 doesn't exist on form1 it wont compile...I wanna supress this and then write code that supresses it at run-time.

Hope soemone can help!
cheers!


PS: I can't change my object that I access the data out of or the way I do that, i can just access it for read or write and I want to do the middle add-in between a form calling one of a small set of methods and the actual code writting out and in upto a hundred pieces of data per record (and some other data manipulation)

Oh, and if someone could tell me what the 'return' line is in code (i.e., insert 'new line' in a string' that would really rock too!)
0
Comment
Question by:kiranboi
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 39

Assisted Solution

by:appari
appari earned 75 total points
ID: 18006136
>>I want to be able to skip the VB code-checking facility
i think it is not possible, if you can post existing code and what you were trying to achieve we can try to do it in an alternative way.

>>tell me what the 'return' line is in code
use vbCrlf, as follows

dim testString as string = "insert " & vbcrlf & " in a string "
console.writeline(testString)
0
 
LVL 4

Expert Comment

by:plenderj
ID: 18006622
Surely something like iterating all available controls of type Textbox on the form would be a better approach?
0
 

Author Comment

by:kiranboi
ID: 18006710
I couldn't do that plenderj because I do not know which textboxes the programmer will eventually use nor in what order and so i will end up with text boxes with the wrong data in and some of the data is going in combo boxes, checkboxes etc.
I wondered if for the purposes of 'building' that there may be a way to remove all the debugger stuff and force a build with the errors in?
hope there is a way, else I'm writting things in a completely new way lol
0
 
LVL 4

Assisted Solution

by:plenderj
plenderj earned 200 total points
ID: 18006783
Well two ideas:

1) Change your code such that your procedure takes a list of parameters of type Textbox, which are the textboxes the developer wants you to put the data into. You can reference these textbox parameters in the body of your method. I recommend using this option

OR

2) Try using the code from this page below. You can still hardcode the names of the textboxes (which you shouldn't be doing btw!!!!) and just reference them as follows:
http://www.codeproject.com/Purgatory/getControlFromName.asp
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 34

Accepted Solution

by:
Sancler earned 225 total points
ID: 18006792
I'm far from sure that I've understood the setup here.  But try this

One form, one button, this code

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1 Is Nothing Then
        Else
            TextBox1.Text = "doh"
        End If
    End Sub

For me it complies and runs, no errors or warnings.  Now drag a textbox onto the form - leaving its default name of TextBox1.  For me, that complies and runs too, with the right result in the textbox.

Roger  
0
 
LVL 4

Expert Comment

by:plenderj
ID: 18006830
I believe that would only work if you explicitly set Option Explicit Off
0
 
LVL 34

Expert Comment

by:Sancler
ID: 18007021
plenderj.  Correct.  Sorry, I took that "as read", but you're probably right to make it explicit.

Roger
0
 

Author Comment

by:kiranboi
ID: 18011602
OK, thanks guys for all your help - going to get admin to split the points.
Cheers
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now