473,606 Members | 2,381 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

a few noob vb.net questions

Three noob questions. Please help.

1. Is there a way to have arguments on subroutine that are optional?


2. Say I need to convert datetime to string..in this format :
2006-09-07 23:00:00.000

datef.tostring( )

produces:

'1/1/0001 12:00:00 AM'

I need it to produce something like this:

2006-09-07 23:00:00.000

I know you can do something like this:

..datef.ToStrin g("MM\-dd\-yy")


3. I want to pass a subroutine an argument that might be type string or
might be type datetime.. how can I do this and then use it's value
accordingingly? type Object maybe?

as a bad example to demonstrate the problem.

say..

Public Sub UpdateJob(ByVal field as string, ByVal Value As Object)

will I be able to call UpdateJob

like this

Update(datetime f) (where datetimef is type datetime)
and like this
Update(stringf) (where stringf type string)
and then inside UpdateJob

SQL = "Update job set " + field + "='" + Value

The above of course does not work.

Thank you in advance for any help or information.

Jan 23 '07 #1
4 1208
"jobs" <jo**@webdos.co mwrote in message
news:11******** **************@ a75g2000cwd.goo glegroups.com.. .
Three noob questions. Please help.

1. Is there a way to have arguments on subroutine that are optional?
Use the optional keyword I believe.
2. Say I need to convert datetime to string..in this format :
2006-09-07 23:00:00.000

datef.tostring( )

produces:

'1/1/0001 12:00:00 AM'

I need it to produce something like this:

2006-09-07 23:00:00.000

I know you can do something like this:

.datef.ToString ("MM\-dd\-yy")
Yes.
3. I want to pass a subroutine an argument that might be type string or
might be type datetime.. how can I do this and then use it's value
accordingingly? type Object maybe?
Either object or define the function twice with each parameter type. This is
called overloading.

Michael
Jan 24 '07 #2
"jobs" <jo**@webdos.co mschrieb
Three noob questions. Please help.

1. Is there a way to have arguments on subroutine that are optional?
See "Optional" keyword and "procedure overloading" in VB documentation.

2. Say I need to convert datetime to string..in this format :
2006-09-07 23:00:00.000

datef.tostring( )

produces:

'1/1/0001 12:00:00 AM'

I need it to produce something like this:

2006-09-07 23:00:00.000

I know you can do something like this:

.datef.ToString ("MM\-dd\-yy")

Use the format string that you need. See ToString documentation for details.
In your code, put the cursor on 'ToString' and press F1.
3. I want to pass a subroutine an argument that might be type string
or might be type datetime.. how can I do this and then use it's
value accordingingly? type Object maybe?

Write two procedures: Same name but different data types (different
signature). This is called overloading.

sub bla(byval x as string)
end sub

sub bla(byval x as date)
end sub
Armin

Jan 24 '07 #3
On 2007-01-23, jobs <jo**@webdos.co mwrote:
Three noob questions. Please help.

1. Is there a way to have arguments on subroutine that are optional?
Yes - using the Optional keyword. But, may I suggest that you NOT use this
technique in any publicly accessible methods. In those cases, you should
really use the ability of VB.NET to allow overloading... Ex:

Public Class ExampleClass
Public Sub DoCoolStuff ()
' Do Cool Stuff With No Arguments
' A lot of times, you would just call one
' of the other overloads with a default value
Me.DoCoolStuff (100)
End Sub

Public Sub DoCoolStuff (ByVal i As Integer)
' Do Cool Stuff to i
End Sub
End Class

>

2. Say I need to convert datetime to string..in this format :
2006-09-07 23:00:00.000

datef.tostring( )

produces:

'1/1/0001 12:00:00 AM'

I need it to produce something like this:

2006-09-07 23:00:00.000

I know you can do something like this:

.datef.ToString ("MM\-dd\-yy")
Look up format strings in the documentation. Yes, you can do lot's of
different formats.
>
3. I want to pass a subroutine an argument that might be type string or
might be type datetime.. how can I do this and then use it's value
accordingingly? type Object maybe?

as a bad example to demonstrate the problem.

say..

Public Sub UpdateJob(ByVal field as string, ByVal Value As Object)

I would overload it :)

Public Sub UpdateJob (ByVal field As String, ByVal Value As DateTime)
Public Sub UpdateJob (ByVal field As String, ByVal Value As String)

Now you don't have to worry - the compiler will call the right one.

--
Tom Shelton
Jan 24 '07 #4


Thank you for all responses. Very good!

Jan 24 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1721
by: administrata | last post by:
Hi! I'm programming maths programs. And I got some questions about mathematical signs. 1. Inputing suqare like a * a, It's too long when I do time-consuming things. Can it be simplified? 2. Inputing fractions like (a / b) + (c / d), It's tiring work too. Can it be simplified? 3. How can i input root?
7
1742
by: administrata | last post by:
Is it possible? I tried... I = "John" print \ """ I used to love pizza"""
3
1607
by: Rob Allen | last post by:
Hey fellas I am a web designer/developer with little in the way of formal training. I took some lower level programming courses to familiarize myself with structured programming and then taught myself (through books as well as trial and error) new web technologies like ASP and PHP on an as-needed basis. I have yet to come across a project that requires XML, but to tell you the truth, I wouldn't know one when I saw it. So my questions...
8
2137
by: Ivan Shevanski | last post by:
Alright heres another noob question for everyone. Alright, say I have a menu like this. print "1. . .Start" print "2. . .End" choice1 = raw_input("> ") and then I had this to determine what option.
2
1903
by: Dan McCollick | last post by:
Hi All, Noob question that I can not seem to figure out: I am trying to implement a screenscraper to pull data from two seperate websites, here is some test code so far: public static void Main(string args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false);
0
1197
by: webmaster | last post by:
I've been playing around with asp.net 2.0/vs.net 2005/C# 2005 - I had a few noob questions. 1. Is there a setting that sets all current and future controls on a page to position absolutely automatically so that I don't have to set this sytle every time? 2. I'd like to code have a "New" button, that when selected makes visible a detailview in insert mode and with only the insert command available. I would imagine I'd be adding an...
0
1292
by: webmaster | last post by:
I've been playing around with asp.net 2.0/vs.net 2005/C# 2005 - I had a few noob questions. 1. Is there a setting that sets all current and future controls on a page to position absolutely automatically so that I don't have to set this sytle every time? 2. I'd like to code have a "New" button, that when selected makes visible a detailview in insert mode and with only the insert command available. I would imagine I'd be adding an...
5
1192
by: Omar | last post by:
Hi all...this is a good group so I'm sure you'll tolerate some more noobish questions... 1) I'm also learning to program flash movies while I learn to do python. How can one implement flash movies into their python code? 2) besides Chieh's tutorials on the python.org site, anyone know of any other video tutorials for python? this style of learning suites me well.
5
1608
by: Milan Krejci | last post by:
the thing is that descentant branches i dont want to expand do expand. $id variable contains an array of branches i want the program to go through (alcohol's id -beer id etc) function tree_list($parent, $level,$id) { // retrieve all children of $parent $result = mysql_query('SELECT cname,cid FROM kategorie '. 'WHERE parent="'.$parent.'";'); while ($row = mysql_fetch_array($result)) {
0
7955
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
8431
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
6773
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...
1
5966
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5466
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3937
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
3980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2448
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
1
1557
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.