|
Hi Gufa
See the code below
For I = Now.Year To Now.Year - 20 Step -1
Me.ComboBox1.Items.Add(CStr(I))
Next
I am not posting to show you my answer, but to ask you some question
I am still learning VB.Net so I am searching for answers
#1 You mention above in previous reply that using Now recursively is not best practice,
Can i know why.
#2 Is using .net convert function such as x.ToString is better than CStr(x) ? and why.
TIA
Samir R. Ibrahim
|
|
|
|
|
Thecaptin wrote: #1 You mention above in previous reply that using Now recursively is not best practice,
Can i know why.
The value returned from Now changes, so it could for example be 2008-12-31 23:59:59 when you call it the first time and 2009-01-01 00:00:00 the next. In your case there is a very low risk for this to happen, and it would only result in the wrong number of items in the list, but there are situations where this is much more likely to happen, and where it will have a much more serious result. That is why it's a bad practice to call the Now method repeatedly.
Thecaptin wrote: #2 Is using .net convert function such as x.ToString is better than CStr(x) ? and why.
The CStr function only does some type checking and then it calls the ToString method, so the difference it quite small.
Some will say that you should use the functions in VB, some will say that you should use the function in the framework. I lean towards the later. VB is now an object oriented language, so the Integer type has a method for converting it to a string. You don't need another function that in the end just calls the method in the Integer class anyway.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi,
Sorry for getting late to answer, I was in vacation.
Guffa wrote: The value returned from Now changes, so it could for example be 2008-12-31 23:59:59 when you call it the first time and 2009-01-01 00:00:00 the next.
That is a clever remark from your side, but my answer is "No Comment" because there is to many variables required which is necessary to use the new or old "Now" Value.
Guffa wrote: You don't need another function that in the end just calls the method in the Integer class anyway.
I had make some tests.
-As you said above, thet CStr is a wrapping function to .net ToString function. and from my test result, that is not true.
-I had made a 2 loop
Dim TimeStart, TimeElapse
TimeStart = Now.TimeOfDay
For I = 1 to 10000000
strTemp = CStr(I)
Next I
TimeElapse = Now.TimeOfDay - TimeStart
MessageBox.Show(TimeElapse)
TimeStart = Now.TimeOfDay
For I = 1 to 10000000
strTemp = I.ToString
Next I
TimeElapse = Now.TimeOfDay - TimeStart
MessageBox.Show(TimeElapse)
- I compare the execution time of both codes
- The result was they are in the same speed until counter "I" is over 1000000 when I is over, CStr is 17 to 30% faster than .ToString
Can you confirm?
if that so, then CStr is a VB Function and not in .net framework?
TIA
Samir R. Ibrahim
|
|
|
|
|
Samir Ibrahim wrote: That is a clever remark from your side
In what way do you think that it's clever?
Samir Ibrahim wrote: but my answer is "No Comment"
As in "I'm in to it up to my ears, and in that situation it's best keep your mouth shut"?
Samir Ibrahim wrote: because there is to many variables required which is necessary to use the new or old "Now" Value.
That doesn't make sense... What variables are you talking about?
Samir Ibrahim wrote: - I compare the execution time of both codes
- The result was they are in the same speed until counter "I" is over 1000000 when I is over, CStr is 17 to 30% faster than .ToString
Can you confirm?
Of course not. With as few iterations as you used, you are way below the resolution of the system clock. you should use something that gives a better resolution:
Dim w1 As New Stopwatch, w2 As New Stopwatch
Dim strTemp As String
w1.Start()
For i = 1 To 100000000
strTemp = CStr(i)
Next i
w1.Stop()
w2.Start()
For i = 1 To 100000000
strTemp = i.ToString
Next i
w2.Stop()
TextBox1.Text = String.Format("CStr: {0} ms., ToString: {1} ms.", w1.ElapsedMilliseconds, w2.ElapsedMilliseconds)
Result of my test run:
CStr: 12487 ms., ToString: 11406 ms.
According to your test, CStr should be 17-30% faster, but instead ToString is about 9% faster. This is consistent with the code that is generated. If you take a look at the code in .Net Reflector, you see that this statement:
strTemp = CStr(i)
actually compiles into this code:
strTemp = Conversions.ToString(i)
If you look at the Conversions.ToString(Int32) method, it looks like this:
Public Shared Function ToString(ByVal Value As Integer) As String
Return Value.ToString(Nothing, Nothing)
End Function
If that's not a plain wrapper for the Int32.ToString method, I don't know what is...
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: In what way do you think that it's clever?
You take care of the possibility that the date could change during this time of period "31/12/2008 11:59:00" when using Now() in a function.
Guffa wrote: hat doesn't make sense... What variables are you talking about?
I mean Variation and demands to this application if it need to use the new Now() Value or still using the old Now() value. In some situation you need the New Now() value to be presented in the function you are creating and in sometime that is not important.
Guffa wrote: Dim w1 As New Stopwatch
Thank you for this new Info
Guffa wrote: CStr: 12487 ms., ToString: 11406 ms.
With your code, I had the same result but, with different numbers
Guffa wrote: If you take a look at the code in .Net Reflector,
I heard about .Net Reflector, never use it or know what is this used for.
Do you notice that all my question ends with ? because I am not sure. I am still learning vb.net 2 Month old ,so don't be hard on me
Thank you very much for your time and enplaning. very appreciated.
Samir R. Ibrahim
|
|
|
|
|
If my 2 group boxes are next to each other on the form, all is well.
If the 2 group boxes are one on top of each other, however, the button2 code doesn't work. Groupbox1 is hidden, but Groupbox2 never shows.
Anyone had this problem? Is there a way to put the groupboxes on top of each other and show/hide them properly?
Thanks
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
GroupBox1.Show()
GroupBox2.Hide()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'GroupBox1.SendToBack()
GroupBox1.Hide()
GroupBox2.Show()
'GroupBox2.BringToFront()
End Sub
|
|
|
|
|
hi
have you try to use GroupBox1.Visible = True/False
instead of Hide()/Show()?
regards
|
|
|
|
|
Yes, tried that too. There's something odd about groupboxes. Even in the form editor, if you drag them on top of each other they tend to disappear. Other controls don't do that. I'm thinking it's a bug perhaps, but I can't find a workaround.
|
|
|
|
|
I am trying to create an "options" screen for my program in which i have a treeview on the left and a when you select a node in the treeview the corresponding groupbox will show on the right with the settings for that category. The problem I am running into is the groupboxes embed themselves into one another when you put them on top of one another. I need like 10 of them on top of each other and this is really frustrating me.
I have tried locking the groupboxes, but that does not work. I noticed you have to place them just right (just offset of the one below it) or they embed. Of course the groupbox has border lines you can't get rid of so you see them moving as you make your way thru the treeview. Not good!
Like you state above, the groupbox will not appear. I am guessing this is because it is now embedded into the groupbox below where it was placed.
modified on Sunday, January 3, 2010 8:38 PM
|
|
|
|
|
Hi All,
I am working with Vb 6 and I want a Crystal Report that should include Page Wise total amount, and in Final Page it should display the Grand total amount.
Anybody can suggest how to get it.
Thanks in advance.
|
|
|
|
|
if anyone know about file recovery?
i need file recovery project in vb.net
|
|
|
|
|
|
EliottA wrote: where did you start?
in the recycle bin of course, that's where those lost files have been seen last.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Unless you know how the NT File System works internally, you're going to find this project impossible.
|
|
|
|
|
If you're targeting the FAT32 file system, then I think (but don't call me on this) that there's some form of backup built in to the file system. Alternatively, start from sector 0 of the disk, and walk the clusters until you find a file which isn't in the file system's list of file pointers
Either way, this is too advanced for VB.Net alone. You would need a hook of some sort into C++, and use the windows api from there
|
|
|
|
|
Hi,
I have DataGridView control inside a tab in a TabControl container. I have set the Selection BackColor of the grid to transparent because I don't want the rows to be coloured when selected. Now, the problem I have is that when after populating the grid, the selected cell, which I have specified, is transparent but it is showing the contents of another tab, i.e. not only is the cell row selection color transparent but the grid and current tab are also transparent. When I click out of that cell and then return, it displays correctly.
Anyone else have a similar experience?
|
|
|
|
|
pls i need anyone who can assist in getting the codes and understand the concept behind finger print security door using VB. Net programming language
|
|
|
|
|
Never heared of Google? Took me only 3 seconds to type in what i was searching for and 0.17 seconds for google to find.
try this[^]
the word is "please", by the way, not "pls"
|
|
|
|
|
Hi all.
I'm beating my head against the wall here, and I know there is a simple solution. I apparently can't find it no matter what I try.
I need a combo box that I can place some ghost text on that says "enter your search here" that will disappear when the user begins to type.
I've found how to do it in WPF, but I need a version for Net 2.5 also.
a simple owner draw won't work, as it looks like heck in Vista....
Thanks,
Tom
|
|
|
|
|
shoorrock wrote: but I need a version for Net 2.5 also.
No such thing.
shoorrock wrote: a simple owner draw won't work, as it looks like heck in Vista....
Just set the initial text, handle the focus event, and clear the text if that's what it is.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
|
I'm not sure what you're asking - how to change what textbox is getting the input ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
I am sorry i didnot explain proply. Problem is only 1 textbox is workig. The other textbox didnot get the fouce. I am talking about virtual keyboard on screen. I can make only one textbox can get a focus. the other textbox did not get fouce. how to make the other textbox is making focus by enter button on screen after 1 textbox input done.
thank you for your concern.
|
|
|
|
|
Try the KeyPress event of your first textbox:
If e.KeyChar = Chr(13) Then
TextBox2.Focus
End If
and if that works, use the same trick with the others.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Thank You for your advise
I did it your advise, but It did not working
do you have another idea..?
Thank you your Reply
|
|
|
|