Create A Global Function?
Jul 12, 2009If there's a way to have a function, that i can call from any code-behind on my website.
for example, i want to be on any page of my website, and be able to call this function[code]...
If there's a way to have a function, that i can call from any code-behind on my website.
for example, i want to be on any page of my website, and be able to call this function[code]...
I want to create a global function to use throughout my application. Let say it's about the connection to the database.My code that i plan to use in my global function is:
myConnection = New SqlConnection("...........")
myConnection.Open()
So that I can call it to use in every form throughout my application. This can make me easy to edit the connection later.how to define this global function and how to call this function in the form.
I have some existing code that looks something like this:
[tag:cb cbid="12345" cbwidth="200" cbclassname="calloutbox" cbposition="left"] Lorem ipsum dolor sit amet, consectetur adipiscing elit.
[tag:cb cbid="123" cbwidth="200" cbclass="calloutbox2" cbposition="left"] Suspendisse eleifend enim a magna pretium porttitor.
I need to write a VB .Net global function that will match these [tag:cb] and take the optional parameters and rewrite the string with Html tags.
<div id="12345" width="200" class="calloutbox" position="left">content (based on id)</div>
I am trying to add a new global function
I am doing it like that:
Function MessageYNC() As String
{
return "dd";
}
[Code].....
But i am getting error -> Statement is not valid in a namespace. on the first line
m using a public variable called globalquery & a global function retriveToDataGrid() it works perfectly fine under same class /form ..... but when i try to access it from a different form , it gives no error and nothing happens
Public Sub retriveDataToDataGrid()
Try
Dim connStr As String = "Database=shahopticals;" & _
"Data Source=localhost;" & _
[code]....
Can't seem to figure out how to use a function return variable in global Dims[code]...
I have also tried adding "FixPath()" under Sub On_load() but got same result. Also the reason I have to have these global is because I have around 30 Subs that refer to "Path" Variable.
I want to create a new instance of a class when I click on a button, but I need to interact with members of that class using other controls on the form, so I need the class to have a global scope. I know I could call the new class in formload, but the class creates certain variables that need to be current. If it is done on formload, the variables wouldn't be current, because if the class is created at formload, it would have different info at that time. Surely, there must be a way to create an instance of the myClass from within a sub that is accessible from other subs of the same class.
[Code]...
I want to create a dataset that I can access from any form. I already created the tables and columns using the dataset designer. I read that I can declare the dataset as public in a module, but when I try to access a table I have to put the name of the module in front otherwise I get a "Reference to a non-shared member requires an object reference" error. When I declare a variable as public in a module I never have to specify the name of the module to access the variable, so why do I need to do it for a dataset? The code in my module is:
[Code]....
How Can I create a Global Varibale for my vb.net project. When I LongIn I want to keep the user Id in a varible and I will Use it in deferent Forms. And The User name will be saver in the varible untill I close the Software.
View 1 RepliesI'm trying to build a language dictionary in VB NET in order to be able to have several languages in the application.This dictionary has a init method that loads from database the entire dictionary and stores it in memory.In the rest of the classes of the project, I added the reference and I can use directly the object without create a new instance because their methods are shared.
how i have to load the dictionary content in order that the rest of classes only accessing to Language.GetWord method obtains the properly record of the collection, same way as My.Settings class.When My.Settings is used from any class the values are loaded. I'm looking for the same effect.This is the code of the class:
Public Class LanguageProvider
Private Shared CurrentLanguage As Collection
Public Shared ReadOnly Property GetWord(ByVal Label As String)
[code]....
Function LoadLanguage must be called when the application loads, in order to access once to database. After that property GetWord must access to the collection with the words and return the result. The problem is that the instances are not the same and the dictionary is not loaded when a class uses it.
I want to add this to my visual studio. [URL]. I understand I should ad it like normal custom dll. but how do i get the dll file from the zipped source.
View 2 RepliesWhere and how do i create a global variable for a combobox? I need to use it on different forms.
View 6 RepliesOkay, Im a newbie to VB, so how do you create a Global variable inside a sub.
View 6 Replieshow to create a global variable for this situation: I would like to store who logs in to a system (like, who is currently logged in, when he logged in) and then use that info for a transaction form, which will look like this: which admin made the transaction).
If I were to use a global variable, it would mean having to pass it onto several forms right (eg: from login form to the forms that will use the log information). I'm also thinking of just having a config file that will store the said login info that will be changed everytime a user logs in.
evrytime i add new controls to a form in vb.net the designer regenerates code and asks me to make corrections, so i have to keep on changing the object declarations to global using the 'global' keyword evertime it regenarates code,especialy dataset objects.how can i prevent this?
View 1 Repliesi could use Global x as string in vb6 in a module to declare it with global privelages, how can i do this in vb2008? how to declare a global variable in vb2008? so that i could use it anywhere i want. i know global variables are not recommended in programming but i need one.
View 4 RepliesI have create a CMS to upload all image to a folder using ed all my images to a folder using,
file.SaveAs(Server.MapPath("../images/") + advertID.ToString + "_" + i.ToString + fileExt)
Now, all images are saved and i forgot it create thumbnails. :(
I need to read all images at once and create thumbnails,
myimg = System.Drawing.Image.FromFile(imgFileName)
myimg = myimg.GetThumbnailImage(154, 94, Nothing, IntPtr.Zero)
myimg.Save(Server.MapPath("../Content/") + "Thumb_" + imgFileName, myimg.RawFormat)
I need this to function fast. I don't seems to know how to read these image names one by one.
I have an object that is defined as a global variable based on custom class. Within that class I have an event that gets fired a certain intervals. These events are fired on the same thread as where the object is declared. How do I create a global object, but have the events within that object fire on a separate thread?
View 2 RepliesI have a Public Class named UserData which consists of Login and Password properties, as well as various permissions related properties.
I declare an instance of this class in a Public Module (named DatabaseFunctions) as
Public User As New UserData Functions in that module are able to access the instance as expected. How do I access said instance from outside of the module?
Until now, I've only needed to utilize the information within that instance from within the module, so I didn't realize that I wasn't able to access it externally. Now, I need to display data contained in that instance on a form.
I had assumed I would be able to use User.Login outside of the function in which it was declared, since everything was declared as Public, but it seems I was mistaken.
I have a snip of coding I need to use 4 or 5 times on my windows form and rather than coping and pasting the same code how do I create a public function where I define the code once and then just call the function name?
View 17 Repliesshow me how to create a function from the following code?
[Code]...
Given the following, what is the best way to create this function (I think the function declaration should make clear the purpose of the function...)
[code]...
Can I create 2 users and they have different function??Database base using is MS Access.For example I have "staff" and "admin".Staff can insert,edit and delete data only.Admin can check the total sales of the day.Can I do that in VB.Net and can somebody give me some idea or example??
View 3 RepliesI remember that C# editor has a powerful option that when we are developing in code and type a new method (operation) name for a class, we can create its body by clicking on ALT+Shift+F10 and immediately, it will be created for it's own class.
what about in VB.NET 2008 editor?
how to create a print function ....
View 3 RepliesTheir is a alfanumeric value of any lenght (string) and i want to replace its all characters with 'X' except right four characters.[code]I have created a function but got stuck:[code]please tell me a better fuction to perform such a operation
View 4 RepliesI'm working on my graduation project and within it i need a function gives me random ID numbers and random dates since 2008,01,01 untill now .. I'm done with the ID numbers but i couldnt find a solution for the dates
View 5 Replieshow to create a function.I've seen recently that creating functions is pretty easy and useful, rather than using each time plenty of code . However, now I want to create a function with two variables , BUT in some case I'd like to able to omit the second one..[code](that is by supplying only the 1st variable in the argument) I'd like it to round the value to its integer value .
View 2 RepliesI have a MustInherit class with some MustOveride Methods in it. When i inherit form that class, I automatically get the MustOveride Methods or properties. My question is, I want to be able, to inherit from a class, get my MustOveride functions and methods, but then with some code already in it. I've once seen a .net class that did it, when I inherited from that class, I got the methods, with some comments in it.
View 4 RepliesI am attempting to create a generic function that the students in my introductory VB .NET course can use to search a single dimension array of a structure.[code]...
My question is: Is there a way to reference the individual structure fields in the array from inside the function? I was trying to make it generic so that the student could simply pass their array into the function - their structure may be named differently than mine and the field names may be different.
I suspect there are other ways to deal with this situation, but I was trying to keep it to just a simple single-dimension array of a structure. I don't think it is possible to do what I want, but I wondered what others thought.