
JumpsInLava
Avatar/Signature-
Posts
55 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by JumpsInLava
-
Hi All, Is there a way to get System.DateTime.Now, and covert the time in to the different Time Zones?
-
Doh! Thanks all. I guess I learned the hard way, and the easy way. :D
-
Logic check. Is this correct? Dim iMltryHour As Integer = 14 Dim iMltryMinute As Integer = 23 Dim iCvlnHour As Integer = 12 Dim iCvlnMinute As Integer = iMltryMinute Dim strCvlnAMPM As String = "AM" If iMltryHour = 0 Then iCvlnHour = "12" strCvlnAMPM = "AM" ElseIf iMltryHour < 12 Then iCvlnHour = iMltryHour strCvlnAMPM = "AM" ElseIf iMltryHour = 12 Then iCvlnHour= "12" strCvlnAMPM = "PM" Else iCvlnHour = iMltryHour - 12 strCvlnAMPM = "PM" End If
-
Dim proka As New Operatie
-
I guess that wouldn't be worth it for just a few additions. Oh well, back to regular old functions and subs in a library module. Thanks all.
-
I understand most of the overloading concept, and was wondering how far I could take it. Could I overload the String.Replace method? Example: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim s As String = "this that this that this that" Dim ht As New Hashtable ht.Add("this", "was") ht.Add("that", "there") 'Pass a hashtable into my own overloaded replace. s = s.Replace(ht) End Sub 'How would I declare this? Public Overloads Function Replace(ByVal ht As Hashtable) As String Dim strReturn As String 'strReturn = ? 'Loop through replacing keys w/values Dim o As DictionaryEntry For Each o In ht strReturn = strReturn.Replace(o.Key, o.Value) Next Return strReturn End Function [/Code] I wouldn't really have a use for this, its just an example I came up with to show the type of overloading I am talking about. Is this possible? ...
-
Woops, shouldn't Dim in the Try block.... Dim MyConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\ares\mis\data.mdb") MyConnection.Open() Dim MyCommand As New OleDbCommand("SELECT * FROM MyTable WHERE ID = 1", MyConnection) Dim MyReader As OleDbDataReader Try MyReader = MyCommand.ExecuteReader() Catch ex1 As System.Data.OleDb.OleDbException MessageBox.Show(ex1.Message) Catch ex2 As Exception MessageBox.Show(ex2.Message) End Try While MyReader.Read Lastname.Text = MyReader("MyFName") FirstName.Text = MyReader("MyLName") Address.Text = MyReader("MyAddress") End While MyConnection.Close() MyReader.Close() MyCommand.Dispose() [/Code] Sorry....
-
Do this, and see what it tells you. Dim MyConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\ares\mis\data.mdb") MyConnection.Open() Dim MyCommand As New OleDbCommand("SELECT * FROM MyTable WHERE ID = 1", MyConnection) Try Dim MyReader As OleDbDataReader = MyCommand.ExecuteReader() Catch ex1 As System.Data.OleDb.OleDbException MessageBox.Show(ex1.Message) Catch ex2 As Exception MessageBox.Show(ex2.Message) End Try While MyReader.Read Lastname.Text = MyReader("MyFName") FirstName.Text = MyReader("MyLName") Address.Text = MyReader("MyAddress") End While MyConnection.Close() MyReader.Close() MyCommand.Dispose() [/Code]
-
Remove lines from a text file
JumpsInLava replied to Max_Payne's topic in Directory / File IO / Registry
I'm bored again today.... Dim strFileName As String = "C:\File.txt" Dim strFileData As String = String.Empty Dim iStart As Integer = 0 Dim iReadLen As Integer = 0 'Read the file data Dim tr As System.IO.TextReader tr = IO.File.OpenText(strFileName) strFileData = tr.ReadToEnd tr.Close() 'I like trim strFileData = strFileData.Trim 'You have two line breaks (CrLf) between the header and the body. 'Look for them, and set the start position right after them. iStart = strFileData.IndexOf(vbCrLf & vbCrLf) + 4 'This is how much data you want to read after the start position. iReadLen = strFileData.Length - iStart 'Read from position iStart for iReadLen positions. strFileData = strFileData.Substring(iStart, iReadLen) 'Write the file back out. Dim tw As System.IO.TextWriter tw = IO.File.CreateText(strFileName) tw.Write(strFileData) tw.Flush() tw.Close() [code=visualbasic] -
Your original code didn't work, because you were using the plus instead of the ampersand. Dim iDowStart As Integer iDowStart = DateTime.Parse(Now.Year & "/" & Now.Month & "/01").DayOfWeek Note: Sunday = 0 If you want to be one based then: iDowStart += 1
-
This seems like it should be pretty simple, but I can't figure it out for some reason. I have two tables. One is a history table (local Access DB), and one is a lookup table (Stored in a SQL server). tHistory .....DateTime .....HistDescription .....PageID tPageLookup .....PageID .....PageDescription I have them both in a DateSet, and I've set up a DataRelation on the PageID. Now, how do I relate/join/view them together in the dataset so I can display them in a DataGrid that would look like this: DateTime | HistDescription | PageDescription ..........or is it a function of the DataGrid?
-
Hmmmmm. Interesting. Thank you for the response.
-
May be an better question would be: In ASP.NET, is each client session its own "application" on the server, or is each client session multi-threading from the same code on the server?
-
I have an asp.net module that does stuff kind of like this: Module Stuff Dim strHold As String = String.Empty Public Sub subDoStuff(ByVal strString As String) 'Added SyncLock do to paranoia SyncLock GetType(Stuff) 'Clears strHold strHold = String.Empty 'Calls subProcess that does some stuff with strHold subProcess() 'Does some more stuff with strHold strHold &= strString 'Writes strHold somewhere End SyncLock End Sub Private Sub subProcess() 'Adds some stuff to strHold strHold = "This and that" End Sub End Module I saw some samples that used SyncLock, got paranoid, and added it to all of my modules that use any type of globals. (I know global variables are the root of all evil, and will cause nations to collapse, but they sure are handy some times.) Question 1: Do I need to use SyncLock? Question 2: If so, should I use "SyncLock GetType(strHold)" instead?
-
Works here.... New Project. Add a textbox (Textbox1) to the form (Form1). Add a button (Button1) to the form (Form1). Double click the Button1, add the Button1_Click code. Add the "Dim f" statement. Add the "Sub whatever" sub. Add a New Windows Form (Form2). Add a textbox (Textbox1) to Form2. Run.
-
Oh, woops you did say C#. Translation anyone?
-
There's probably a better way but... ' Dim f As New Form2 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click f.Show() AddHandler f.TextBox1.TextChanged, AddressOf Me.whatever End Sub Private Sub whatever(ByVal sender As System.Object, ByVal e As System.EventArgs) TextBox1.Text = f.TextBox1.Text End Sub
-
I think you should use the CType. If you turn "Option Strict" on. ("Project" -> [project] Properties -> Build) and you aren't using the CType, then you will get these type of errors when you build: "Option Strict On disallows implicit conversions from 'System.Object' to 'Excel.Application'."
-
' Dim words() As String words = Split(TextBox1.Text, " ") 'If the last eight chars is numeric... If IsNumeric(Microsoft.VisualBasic.Right(TextBox1.Text, 8)) = True Then 'If the length of "words()" is eight... If words.Length = 8 Then 'If each of the words except the last are three chars long... If Len(words(2)) = 3 And Len(words(3)) = 3 And Len(words(4)) = 3 And Len(words(5)) = 3 And Len(words(6)) = 3 Then TextBox2.Text = words(1) + " " + words(0) + " " + words(7) + " " + words(2) + " " + words(3) + " " + words(4) + " " + words(5) + " " + words(6) End If ElseIf words.Length = 7 Then If Len(words(2)) = 3 And Len(words(3)) = 3 And Len(words(4)) = 3 And Len(words(5)) = 3 Then TextBox2.Text = words(1) + " " + words(0) + " " + words(6) + " " + words(2) + " " + words(3) + " " + words(4) + " " + words(5) End If ElseIf words.Length = 6 Then If Len(words(2)) = 3 And Len(words(3)) = 3 And Len(words(4)) = 3 Then TextBox2.Text = words(1) + " " + words(0) + " " + words(5) + " " + words(2) + " " + words(3) + " " + words(4) End If ElseIf words.Length = 5 Then If Len(words(2)) = 3 And Len(words(3)) = 3 Then TextBox2.Text = words(1) + " " + words(0) + " " + words(4) + " " + words(3) + " " + words(2) End If ElseIf words.Length = 4 Then If Len(words(2)) = 3 Then TextBox2.Text = words(1) + " " + words(0) + " " + words(3) + " " + words(2) End If ElseIf words.Length = 3 Then If Len(words(2)) = 3 Then TextBox2.Text = words(1) + " " + words(0) + " " + words(2) End If End If Else 'No date on the end... 'If the length of "words()" is seven (one less because no date)... If words.Length = 7 Then 'If each of the words are three chars long... If Len(words(2)) = 3 And Len(words(3)) = 3 And Len(words(4)) = 3 And Len(words(5)) = 3 Then TextBox2.Text = words(1) + " " + words(0) + " " + words(2) + " " + words(3) + " " + words(4) + " " + words(5) + " " + words(6) End If ElseIf words.Length = 6 Then If Len(words(2)) = 3 And Len(words(3)) = 3 And Len(words(4)) = 3 Then TextBox2.Text = words(1) + " " + words(0) + " " + words(2) + " " + words(3) + " " + words(4) + " " + words(5) End If ElseIf words.Length = 5 Then If Len(words(2)) = 3 And Len(words(3)) = 3 Then TextBox2.Text = words(1) + " " + words(0) + " " + words(2) + " " + words(3) + " " + words(4) End If ElseIf words.Length = 4 Then If Len(words(2)) = 3 Then TextBox2.Text = words(1) + " " + words(0) + " " + words(2) + " " + words(3) End If ElseIf words.Length = 3 Then If Len(words(2)) = 3 Then TextBox2.Text = words(1) + " " + words(0) + " " + words(2) End If End If End If '
-
So.....I take it you are working with field size. Can you give me an example of what you want the following inputs to look like after processing (with space padding): "sName sName abc def ghi jkl mno" "sName fName abc def ghi jkl mno 11282003" (What if the name is longer than the field?) "sNameNameNameName fNameNameNameName abc def ghi jkl mno" "sNameNameNameName fNameNameNameName abc def ghi jkl mno 11282003"
-
I see things that are wrong with it, but I can't see an easy way to get it to work: 1. You can't access items in an array that don't exist. This would return an error if there aren't seven or more items in the array: Len(words(6)) = 3 (That is the main problem with it programmatically, because to keep it in the same multiple "If" structure you would have to evaluate if each item exists before testing for the length.) 2. "If" "Then" statments require something that can be evaluated as True or False. I don't know what this should do: If Microsoft.VisualBasic.Right(TextBox1.Text, 8) Then "Microsoft.VisualBasic.Right(TextBox1.Text, 8)" doesn't return True or False, it returns the first eight characters of TextBox1.Text. 3. You aren't declaring "words" ("Dim words() As String"?) 4. The code doesn�t account for the last word to be a non three character DOB.
-
Change: strFName = words(1) to strFName = words(1).PadRight(15, " ") Change: TextBox2.Text = words(words.Length - 1) & " " & TextBox2.Text to TextBox2.Text = words(words.Length - 1) & " " & TextBox2.Text Note: It only gets the DOB if it finds a word that is not three characters at the end of the word list. If you need the DOB position in TextBox2 to always be the same length regardless of it's existence in the word list, then you would hold it in a variable, and pad it when you added it to TextBox2.
-
I changed how some of it works, to make it friendlier. Note, this code makes assumptions (which we all know what that can mean): 1. Firstname and Surname WON'T have spaces in them. If they do, then you would have to split on something else, or find a different way to do it. 2. All subjects are exactly three characters. 3. The DOB (if it exists at the end) is NOT three characters. ' 'Get the words in a string array Dim words() As String = Split(TextBox1.Text, " ") '"For" loop counter Dim x As Integer = 0 'To hold Firstname and Surname Dim strFName As String = String.Empty Dim strSName As String = String.Empty 'If we have more than one item in "words()" If words.Length > 1 Then 'Clear "TextBox2" TextBox2.Text = String.Empty 'Hold the Surname and the Firstname. strSName = words(0) strFName = words(1) 'If we have more than two items in "words()" then... If words.Length > 2 Then 'For each item in "words()" starting with the 3rd word... 'Note: arrays are 0 based, so position 2 is actually the 3rd 'word, and "words.Length - 1" is the last item.) For x = 2 To words.Length - 1 'If the length of the word is exactly three then it is a subject... If words(x).Length = 3 Then 'Add "[space] & [word]" to TextBox2 TextBox2.Text &= " " & words(x) End If Next 'Because the "For" loop above will always add "[space] & [word]" we have 'an extra space at the front. Use .Trim to remove spaces from the 'front and back of TextBox2. TextBox2.Text = TextBox2.Text.Trim 'If the last word's length is NOT 3 assume it is the DOB... If words(words.Length - 1).Length <> 3 Then 'Add "[last word] & [space]" to the front of TextBox2 TextBox2.Text = words(words.Length - 1) & " " & TextBox2.Text End If End If 'Add the Firstname and Surname to the front of "TextBox2" TextBox2.Text = strFName & " " & strSName & " " & TextBox2.Text Else 'We didn't have more than one item in "words()" so the data must be bad. MessageBox.Show("Bad Data") End If
-
I'm kind of bored today.... ' Dim words() As String = Split(TextBox1.Text, " ") Dim x As Integer = 0 Dim strDOB As String = String.Empty Dim strFName As String = String.Empty Dim strSName As String = String.Empty If words.Length > 2 Then TextBox2.Text = "" strSName = words(0) strFName = words(1) If words.Length > 3 Then If words(words.Length - 1).Length > 3 Then strDOB = words(words.Length - 1) End If For x = 2 To words.Length - 1 If words(x).Length = 3 Then TextBox2.Text &= " " & words(x) End If Next TextBox2.Text = TextBox2.Text.Trim If strDOB <> String.Empty Then TextBox2.Text = strDOB & " " & TextBox2.Text TextBox2.Text = strFName & " " & strSName & " " & TextBox2.Text Else MessageBox.Show("Bad Data") End If