|
-
Jun 23rd, 2012, 08:09 AM
#1
Thread Starter
New Member
Copying text to another form
I am relatively new to Visual Basic; in the sense that I have had it for a while, but haven't used it enough to actual get good and confident with it.
I am trying to create a program for the 3D Space Simulator "Celestia". You can create stars through Notepad on it, but I wanted to see if I can create a 'Star builder'.
So I have 2 forms:
1# Where you put in all the information needed
2# Where it gets automatically copied and saved
I can't seem to get the text to copy though.
I have 7 textbox's on form 1, with a button named 'Build' which has the code 'Form2.Show()' on it's click event.
The 2nd form has a RichTextBox on it, which I have put the code:
Code:
Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.RichTextBox1.Text = Form1.TextBox1.Text & vbNewLine &
Me.RichTextBox1.Text = "{" & vbNewLine &
Me.RichTextBox1.Text = "RA " + Form1.TextBox2.Text & vbNewLine &
Me.RichTextBox1.Text = "Dec " + Form1.TextBox3.Text & vbNewLine &
Me.RichTextBox1.Text = "Spectral Type " + Form1.TextBox4.Text & vbNewLine &
Me.RichTextBox1.Text = "Distance " + Form1.TextBox5.Text & vbNewLine &
Me.RichTextBox1.Text = "AppMag " + Form1.TextBox6.Text & vbNewLine
If Form1.TextBox7.Text = "" Then
Me.RichTextBox1.Text = "}" & vbNewLine
End
Else
Me.RichTextBox1.Text = "Radius " + Form1.TextBox7.Text & vbNewLine &
Me.RichTextBox1.Text = "}"
End If
End Sub
I have a feeling the answer will be obvious..but I really can't figure it out for myself.
Thanks,
Dryda
-
Jun 23rd, 2012, 08:33 AM
#2
Re: Copying text to another form
I would use the following method in that you assign infor to RichTextBox1 in Form2 in the calling form.
Code:
Dim f As New Form2
Try
f.RichTextBox1.Text = TextBox1.Text & vbNewLine
'
' do the rest of your assigments
'
f.ShowDialog()
Finally
f.Dispose()
End Try
-
Jun 23rd, 2012, 08:59 AM
#3
Re: Copying text to another form
vb Code:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim Var_FromT1 As String = "Some value1" ' lets say these are the values Dim Var_FromT2 As String = "Some value2" ' from your text boxes Dim Var_FromT3 As String = "Some value3" ' in form 1 Dim Var_FromT4 As String = "Some value4" ' & u are passing these values on to Dim Var_FromT5 As String = "Some value5" ' form2 Dim Var_FromT6 As String = "Some value6" ' create a public sub in side the form2 ' as fillRTB Refer to Sub routine FillRTB() Dim StringCollector As New System.Text.StringBuilder With StringCollector .Append(Var_FromT1).AppendLine() .Append(Var_FromT2).AppendLine() .Append(Var_FromT3).AppendLine() .Append(Var_FromT4).AppendLine() .Append(Var_FromT5).AppendLine() .Append(Var_FromT6).AppendLine() End With Dim New_Form As New Form2 With New_Form .FillRTB(StringCollector.ToString()) .Show() End With End Sub
vb Code:
'This will be a sub routine in your another form 'on which you are having Ritch text box ' u can do the same even by creating some properties ' in form2 as well Public Sub FillRTB(ByVal Imported_Variables As String) Me.RichTextBox1.Text = Imported_Variables End Sub
-
Jun 23rd, 2012, 09:16 AM
#4
Thread Starter
New Member
Re: Copying text to another form
@Make me rain
Thank you so much That worked perfectly!
@Kevininstructor Thank you for the help Yours didn't seem to copy it all down, but that code did help neaten some things up.
-
Jun 23rd, 2012, 09:39 AM
#5
Thread Starter
New Member
Re: Copying text to another form
Thank you both Worked perfectly
-
Jun 23rd, 2012, 10:19 PM
#6
Re: Copying text to another form
 Originally Posted by Drydareelin
@Make me rain
Thank you so much  That worked perfectly!
@Kevininstructor Thank you for the help  Yours didn't seem to copy it all down, but that code did help neaten some things up.
I figured why take all the fun away from you of completing the code. Being a developer means you are expected to code not others. Any ways good to hear you have a solution now.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|