|
TwoFace you are the man
Thank you so much
I had to make a couple mods to your code becuase it was the request timing out that was slowing me down but all in all it was very helpful to this newbie and very much appreciated.
Did I mention U ROCK
Tony
|
|
|
|
|
Hi,i have 2 drop down list box, in that one i am display year
another one display month,
when i am selecting the year and month,
i want to know how many sundays on that month like,
plz anyone can help me.........,
i need that code........
Regards,
Magi
|
|
|
|
|
The basic calculation is this. What you want to do is shift the calander so it starts on the day you are looking for. For instance if there are 31 days in the month and Sunday is the 3rd day then we'll throw out the first 2 days. This leaves us will 29 days (the first of which is sunday). If we divide 29 by 7 and round up, we end up with 5 which will be the number of Sundays in that month. Anyway, that's the principal behind this function I made. It takes 3 parameters. A Year and Month as well as the Day you are looking for. I used the DayOfWeek enum for the day parameter. 0 = Sunday, 1 = monday, ... 6 = saturday.
Private Function GetDaysInMonth(ByVal year As Integer, ByVal month As Integer, ByVal day As System.DayOfWeek) As Integer
'Date object for the first day of the month
Dim myDate As New Date(year, month, 1)
'Number of Days from the start of the month until the day
'we are looking for.
Dim nextOccurance As Integer = day - myDate.DayOfWeek
If nextOccurance < 0 Then nextOccurance += 7
'Return number of occurances in month
Return Math.Ceiling((Date.DaysInMonth(year, month) - nextOccurance) / 7)
End Function
To use the function:
'Sundays in march 2007
Dim occurences = GetDaysInMonth(2007, 3, DayOfWeek.Sunday)
-- modified at 2:54 Tuesday 13th March, 2007
|
|
|
|
|
hi ur code is nice,
but see i am selecting year and month in dropdownlistbox,
how to pass that value in that function,
i am beginner in this,
so plz help me....
-- modified at 5:35 Tuesday 13th March, 2007
Magi
|
|
|
|
|
ya really nice i got the o/p,
thanks lot,
regards,
Magi
|
|
|
|
|
I am trying to develop a program to execute a .bat file as administrator through vb.net app. I know you need to authenticate and use the system.management class but I am lost on how to do this. Does anyone have an easy way of soing this. Or can someone help me write this way? I would really appreciate it.
Thanks,
Christian
|
|
|
|
|
You can do it under .NET 2.0 using the Process class' ProcessStartInfo[^] class and setting it's Username and Password properties to those of the admin account you want to use.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
thanks for the reply but I dont know how to use that either. I am a newbie when it comes to advance vb.net programming. I need more specific instructions. That code gives me an error, saying I need to use a get or set. and an instance is being used before it actually being assigned a value. What ever this means?
|
|
|
|
|
Post the code you're using.
I would also HIGHLY recommend pickly up a book on beginning VB.NET. From what you've described, you're missing the VB.NET 101 basic stuff.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I did find this code..
| Dim instance As ProcessStartInfo
| instance.Password "myPass" 'This is no good because its
System.Security.String
| instance.UserName = "myUser"
-- modified at 15:13 Wednesday 14th March, 2007
|
|
|
|
|
'need to authenticate admin privileges to execute file
'Public Property password() As SecureString
' Get
' End Get
' Set(ByVal value)
' End Set
'End Property
'Dim instance As ProcessStartInfo
'Dim value As SecureString
'value = value.Password
'instance.Password = value
_____________________________________________________________
'this part works but it is only if you have admin privilges
cmd = "\\misfs\public\DST Update\xpdstupdate.exe"
'logon as admin with password to get access to uninstall file
'executes file file on server
Dim startInfo As System.Diagnostics.ProcessStartInfo
Dim pStart As New System.Diagnostics.Process
startInfo = New System.Diagnostics.ProcessStartInfo("cmd")
pStart.StartInfo = startInfo
pStart.Start()
pStart.WaitForExit() 'Your code will halt until the exe file has executed.
|
|
|
|
|
VB.NET 2005:
I want a user to type their nam, then make it so my program recognises when the user presses the enter key (or they can click on the button), then acts as tho a button has been pressed, how would i do this, is it a press down event?
|
|
|
|
|
Well it is not complicated. You define the procedure as a sub or function what has to be handled when user pushes the enter key. Check this code please.
<code>
' Handle the KeyDown event to determine the type of character entered into the control.
Private Sub textBox1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) _
Handles textBox1.KeyDown
' Determine whether the keystroke is a number from the top of the keyboard.
If e.KeyCode = 13 Then
Call DoMyTask() ' That must be your procedure or function
End If
End Sub
</code>
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
How do i referance to something like a btn1_Click command?
|
|
|
|
|
Make sure you have a button click event attach to your button then use code some what like this to actuate it.
YourButton_Click(YourButton, New EventArgs)
|
|
|
|
|
Sorted, cheers for your help
|
|
|
|
|
I am new to Visual basic. I am taking an intro VB class in college and it is pretty basic. This question is not class related and my instructor wasn't sure how to do this. I was wondering how or if it is possible to call a windows application. I would like to call a command prompt so I could code something to work with a command promt running nmap. I haven't had much luck googling so anything to point me in the right direction would be appreciated. Thanks...
|
|
|
|
|
look into the documentation on Process and Process.StartInfo.
|
|
|
|
|
Hey everyone.
Can someone please inform me of a way to retrieve the filesize of the file to download before I download it using the My.Computer.Network.DownloadFile
method.
Your input is appreciated.
Tony
|
|
|
|
|
It depends on where the file is comming from. If you're downloading from an HTTP:// or FTP:// address, then no, you can't find out before you get it. If you're downloading from some local server using a drive letter or UNC path (\\server\share\filepath), then yes, you can use the normal File methods to find out how big the file is.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thank-you Dave
for your response I was afraid of that becuase it was an http download that I was trying to get a progress bar working for becuase the showui overload was kinda ugly. So I ended up changing it to a web request instead.
I hate being a newbie. Lol I don't know anything yet but I'm learning.
|
|
|
|
|
hello sir u have send me the solution of validating textboxes,given below its working absolutely fine ...
but if i have 100 textboxes then do i have to validate each and everyone by coding 12-15 lines..
i think it will be very tedious....
any shortcut..?
please tell in vb.net
i am working on VS2003.
code i am usung is
Private Sub Textbox1_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles TextBox1.TextChanged
If Val(TextBox1.Text) > 45 Then TextBox1.Text = CStr(0) : MsgBox("Please Enter A Number Between 0 to 45", MsgBoxStyle.Critical)
End Sub
Private Sub Text1_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
Select Case KeyAscii
Case 48 To 57 '0 To 9
Case 8 'Back Space
Case 13 'Enter
Case Else 'Other Keys
KeyAscii = 0
End Select
If KeyAscii = 0 Then
eventArgs.Handled = True
End If
End Sub
|
|
|
|
|
I didn't give you the code, but the same textChanged event can be assigned to all of your 100 textboxes. So I would suggest that you connect each of your textboxes with that one textChanged event.
The way to do this is:
At the end where you see the Handles key word you have the TextBox1.TextChanged
All you have to do is add:
,TextBox2.TextChanged, TextBox3.TextChanged, ... till you have added all 100 textboxes.
Hope that helps.
Ben
|
|
|
|
|
u want tosay like this....
Private Sub Textbox1_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged
what about the other places where textbox1.text is written like textbox1.keypress and if val(textbox1.text) and all such place where only textbox1.validated....
its highly confusing...
Private Sub Textbox1_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged
If Val(TextBox1.Text) > 45 Then TextBox1.Text = CStr(0) : MsgBox("Please Enter A Number Between 0 to 45", MsgBoxStyle.Critical)
End Sub
Private Sub Text1box_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
Select Case KeyAscii
Case 48 To 57 '0 To 9
Case 8 'Back Space
Case 13 'Enter
Case Else 'Other Keys
KeyAscii = 0
End Select
If KeyAscii = 0 Then
eventArgs.Handled = True
End If
End Sub
|
|
|
|
|
Your eventSender is the TextBox
So:
if Val(CType(eventSender, TextBox).Text) > 45 Then CType(eventSender, TextBox).Text = CStr(0) ...
Hope that helps.
Ben
|
|
|
|