|
|
Message Closed
modified 5-Jan-17 22:39pm.
|
|
|
|
|
But javascript is only scripting language. It can,t create desktop or android applications. I mean it is not equal to vb.net because in vb.net we can develop in desktop,web and cell phone also.
|
|
|
|
|
Hello !
I have a vb.net program , where I want to save on a database several things , and the actual time.
The problem is that the local pc clock may have problems.
Is there any way that if internet connection is present , to get the real date and time ( for my time zone ) from internet and to save to a variable ?
Thank you !
|
|
|
|
|
A Google search will find all you need to know about NTP servers.
|
|
|
|
|
In a VB.net 2010 desktop application, reports obtain their values to execute by users selecting values from the various vb.net controls. In 2 columns where there are date pickers, the default value of the date pickers is to use today's date.
The application passes values from the controls using the following code:
Private Sub dtEnddate_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtEnddate.ValueChanged
Variables.g_strEndDate = dtEnddate.Text
End Sub
Private Sub dtEnddate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtEnddate.Click
Variables.g_strEndDate = dtEnddate.Text
End Sub
The problem is if the user keeps todays date, and does not change the date, the variables.g_strEndDate never gets a value. These variables I am referring to are in a Public Class Variables and the variable is define as Public Shared g_strEndDate As String.
Thus can you tell me the best way to give this column default values of today's date? What code would you use and where would you place the code?
|
|
|
|
|
classy_dog wrote: Thus can you tell me the best way to give this column default values of today's
date? You could initialize it with a value when the application starts.
classy_dog wrote: What code would you use I would recommend removing the global variable altogether. If it is a dialog, then the values should be returned upon closing the dialog and passed to the method that needs them.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Is there some reason that you cannot simply give the variables default values when you declare them?
You can lead a developer to CodeProject, but you can't make them think.
The Theory of Gravity was invented for the sole purpose of distracting you from investigating the scientific fact that the Earth sucks.
|
|
|
|
|
Wrong approach!
Store dates as dates, not string! String represenation may differ in different localization/culture.
Always initialize variables! It can save you from stress
|
|
|
|
|
In a VB.NET 2010 desktop application, I am using the following new logic to load values into a combo box.
Public dirAccessFiles As String() = Directory.GetFiles("H:\FilesTest", "*.accdb")
Try
Dim dir As String
For Each dir In dirAccessFiles
cboAccessFile.Items.Add(Path.GetFileNameWithoutExtension(dir))
Next
Catch except As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try
The user wants the file names to be in descending order in the combo box. Thus, can you tell me how to modify the code list above and/or would you show me code on how I can load file names into the combo box in descending order?
|
|
|
|
|
That means you need to set the Sorted property to False , and sort the names manually before adding them to the Combo.
|
|
|
|
|
WHat Richard MacCutchan said - but personally I wouldn't bother with any "manual" sorting method / algorithm. Instead, add a listbox, set its Visible property to false, and Sort = True. Then load the items into that and let tt take of sorting them. Then, to get reverse order, just read the items in reverse and load them into your combo box.
|
|
|
|
|
Would you show me how to write the code you suggested here," Instead, add a listbox, set its Visible property to false, and Sort = True. Then load the items into that and let tt take of sorting them. Then, to get reverse order, just read the items in reverse and load them into your combo box."? Could you give me at least a start on how to set this up?
|
|
|
|
|
Well...
Add ListBox1 to form
set
ListBox1.Visible = False
ListBox1.Sorted = True
Public dirAccessFiles As String() = Directory.GetFiles("H:\FilesTest", "*.accdb")
...
For Each dir In dirAccessFiles
ListBox1.Items.Add(Path.GetFileNameWithoutExtension(dir))
Next
Dim I as integer
For I = ListBox1.Items.Count - 1 To 0 Step -1
cboAccessFile.Items.Add(ListBox1.Items(I))
Next
|
|
|
|
|
That's a toe-curling suggestion.. please see my answer below
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Bah - only to purists! Technically, you are quite right of course, but I suspect Linq is a bit beyond our OP at present. Then it depends on one's motivation; there's nothing wrong with "cheating" if getting a working result is what matters. Even if this isn't the best place to use it, this "cheat" is a useful way of sorting items without resorting to complex methods, which our OP could use elsewhere. But without a knowledge of Linq, your answer would be used "by rote" and the OP would learn nothing - other, perhaps, than that maybe he should learn about Linq.
I am not really trying to say I'm right and you're not - of course you are; just that there can be a place for the quick (because it doesn't require learning new methods) and dirty solutions sometimes.
|
|
|
|
|
Wombaticus wrote: but I suspect Linq is a bit beyond our OP at present You're probably right there but it can also be done without Linq:
Dim dirAccessFiles As String() = Directory.GetFiles("H:\FilesTest", "*.accdb")
Dim list As New List(Of String)()
For Each dir As String In dirAccessFiles
list.Add(Path.GetFileNameWithoutExtension(dir))
Next
list.Sort()
For i As Integer = list.Count - 1 To 0 Step -1
comboBox1.Items.Add(list(i))
Next
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
This is true - and I have to admit that this obvious solution only occurred to me belatedly. Still, my "trick" has many applications! (I'm not giving up on it that easily! )
|
|
|
|
|
Wombaticus wrote: Still, my "trick" has many applications! (I'm not giving up on it that easily! )
I didn't yet have to resort to some such trick - do you have an example where it can't be easily replaced with some non-control-using code?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Well, it could be used in many places in lieu of a sorting algorithm. If what you’re saying is anything that can be read into a ListBox and sorted that way could be read into a List collection, ok fair enough. I guess this old trick goes back before the days of such things... (If they existed in VB3 I wasn’t aware of them!) I don’t really want to labour the point – it is a “dirty” trick, so probably shouldn’t be encouraged, but it’s quick and as easy to implement as a “proper” solution. Otherwise, OK, I give in! </grovels>
|
|
|
|
|
Wombaticus wrote: I guess this old trick goes back before the days of such things... Fair enough.. old habits
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
It's a very useful tip when creating a TreeView which lists the items in sorted order. You can also add a prefix character to each item so that directories appear before files.
|
|
|
|
|
That's a trick I used many times in VB3, 5 and 6 (and some obscure VB derivatives that I'd rather forget about).
I agree with the others that there are (arguably) better "dotnetty" ways of doing it, but it's always worth having something like this up your sleeve (especially if you end up supporting any legacy systems)
The only thing I would say is that (when possible) I created the listbox dynamically in code only so it was never part of the forms control collection.
|
|
|
|
|
Thanks for your helpful answers!
|
|
|
|
|
You're welcome!
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|