spyrit Posted October 17, 2003 Posted October 17, 2003 Hi I have to design a program that takes as input one line of text in the format: SURNAME FIRSTNAME SUBJECT1 SUBJECT2 DOB Then the program needs to rearrange this input in textbox1.text into the format: FIRSTNAME SURNAME DOB SUBJECT1 SUBJECT2 into textbox2.text and then be able to copy the output to the clipboard. I am open to any suggestions in VB6 or .NET if you tell me which it is for as i find they are slightly different. I have thought of counting the ascii values of the whole string and adding a counter in the prog so when ascii for space is pressed it adds that as a word and puts it in the correct columns. This seems a long way to go about it and i am also not very sure on how to count the ascii values into memory and take them as one word. Could you please please help me ASAP. Thanks! Spyrit Quote
spyrit Posted October 17, 2003 Author Posted October 17, 2003 Here is my code so far but i need a try statement to do what i said above before it catches to return an error. Private Sub clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clear.Click 'This will clear the first text box of all data' TextBox1.Text = ("") 'This will clear the second text box of all data' TextBox2.Text = ("") End Sub Private Sub Format_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Format.Click 'This will try to execute the following statement' Try A TRY STATEMENT Is NEEDED HERE - I AM STUCK! 'If it was unable to format the text it will return 'catch' a message box' Catch 'The message box tells the user to recheck the data they wish to format' 'The Dim command tells vb to use msg for the following' Dim msg As String Dim title As String Dim style As MsgBoxStyle Dim response As MsgBoxResult msg = "An error occured during format, do you wish to retry?" 'The message in the box' ' Define message. style = MsgBoxStyle.Critical Or MsgBoxStyle.YesNo ' This show the style of the box' title = "Format Error" 'Title of the message box.' 'This displays the message.' response = MsgBox(msg, style, title) 'If the User chose Yes.' If response = MsgBoxResult.Yes Then 'Ignore Command' ElseIf response = MsgBoxResult.No Then 'Ignore any command' End If 'If the response is Yes then the program will return message box format successful.' If response = MsgBoxResult.Yes = True Then MsgBox("Format Successful", MsgBoxStyle.Information Or MsgBoxStyle.OKOnly, "Information!") End If End Try End Sub Private Sub Paste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Paste.Click 'We want the data to be in a text format to add in our textbox TextBox1.Text = Clipboard.GetDataObject.GetData(DataFormats.Text, True) End Sub Private Sub Copy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Copy.Click 'This will copy the text that is in text box 2 into the clipboard' 'Ready for output in the desired document.' Clipboard.SetDataObject(TextBox2.Text, False) End Sub Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click End Sub Private Sub Log_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Log.Click End End Sub Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click 'This label will be uneditable within the program and will not be copied to the clipboard' End Sub End Class Quote
Engine252 Posted October 17, 2003 Posted October 17, 2003 i think this can do it it's a theory you should work it out furder ok first read the string spit the string to a array and then rearrange the array print them in the good order in the textbox Quote
JumpsInLava Posted October 17, 2003 Posted October 17, 2003 Per Engine252's suggestion.... This should help with the rearrange: Private Sub Format_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Format.Click Dim s() As String 'If possible use something other than space to separate sections s = Split(TextBox1.Text, " ") If UBound(s) = 4 Then TextBox2.Text = s(1) & " " & s(0) & " " & s(4) & " " & s(2) & " " & s(3) Else MessageBox.Show("Wrong number of sections.") End If End Sub Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.