473,396 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.ToString("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(datetimef) (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 1200
"jobs" <jo**@webdos.comwrote in message
news:11**********************@a75g2000cwd.googlegr oups.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.comschrieb
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.comwrote:
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
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....
7
by: administrata | last post by:
Is it possible? I tried... I = "John" print \ """ I used to love pizza"""
3
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...
8
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...
2
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...
0
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...
0
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...
5
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...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.