Sorry to be a pain but I keep missing out on these code snippets you often post.
When I download them and try to run them I get messages saying they can't be found. Do I have to download them to a specific location?
Many thanks,
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
Sorry to be a pain but I keep missing out on these code snippets you often post.
When I download them and try to run them I get messages saying they can't be found. Do I have to download them to a specific location?
Many thanks,
If you have any problems while unpacking the file , use winrar . This project was created by VS.NET 2003 . If you don't have this version , use the converter under my sig to get it converted to VS.NET 2002 . No other issues with this sample .
I guess I did not realise that I had to unpack them to the directory containing my other VB.NET solutions. Now I've done that, I'm OK.
I do have VB.NET 2003.
Many thanks, now I can experiment with Pilate's gems.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
I am having difficulty in following what you are doing.Please tell me if I have misunderstood.
You have started the project from Form1. So form1 is instantiated from the beginning. Therefore, why in form2 do you use the code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f1 As New Form1
Me.Label1.Text = Me.Fm1TxtBox.Text
End Sub
Arnt you creating a new instance of form1, in a separate workspace, every time this event occurs? If so, why? I realise that only one form1 will be visible, but the others are still in existance, taking up resources.
Also, in the form2 code'
Public Sub New(ByVal hostct As TextBox)
InitializeComponent()
Me.Fm1TxtBox = hostct
End Sub
you seem to be creating a new instance of a form1.textbox1 (albeit invisible) and then again passing the entire properties thereof to that new instance (Fm1TxtBox).
Whilst your code does work, it seems a long way round - or is their a reason for this approach?
Many thanks,
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
I am having difficulty in following what you are doing.Please tell me if I have misunderstood.
You have started the project from Form1. So form1 is instantiated from the beginning. Therefore, why in form2 do you use the code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f1 As New Form1
Me.Label1.Text = Me.Fm1TxtBox.Text
End Sub
Arnt you creating a new instance of form1, in a separate workspace, every time this event occurs? If so, why? I realise that only one form1 will be visible, but the others are still in existance, taking up resources.
Also, in the form2 code'
Public Sub New(ByVal hostct As TextBox)
InitializeComponent()
Me.Fm1TxtBox = hostct
End Sub
you seem to be creating a new instance of a form1.textbox1 (albeit invisible) and then again passing the entire properties thereof to that new instance (Fm1TxtBox).
Whilst your code does work, it seems a long way round - or is their a reason for this approach?
Many thanks,
Forms in .NET are classes and classes are passed ByrRef by default . So When I do this
Dim f1 As New Form1
It means , f1 points to the address of Form1 , so anything is changed in f1 obj would reflect in Form1 .
The other issue with the constructor , I created a paramter to be passed from Form1 to and referenced to Form2 . In Form2 , I stored it in local variable of the same type , then I can use my local var like this
Me.Label1.Text = Me.Fm1TxtBox.Text
You need to read more about passing byref and OOP in .NET if this doesn't make sense to you
clear ?
"You need to read more about passing byref and OOP in .NET if this doesn't make sense to you
clear ?"
Yes, I am aware of this and I see that your code is one method of passing data between forms. But you are not answering my questions.
I see the quicker way, and tying up less resources, as :
Create an instance of form1 in a module:
public frm1 as new form1
Start the project from an Application.Run in a Sub Main in the module.
In form1:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f2 As New Form2
f2.Show()
End Sub
In form2:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Label1.Text = frm1.TextBox1.Text
End Sub
Is there a reason why you prefer your way?
Last edited by taxes; Feb 23rd, 2004 at 04:25 AM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
No. When I compiled my remarks I was thinking that somewhere it was necessary to see if f2 had previously been instanced and put that in as a reminder for me to see what code could be used. I then forgot to alter my post before submitting.
My apologies. I have amended it.
Any views on the main point?
I have also just noticed your remarks
"Dim f1 As New Form1
It means , f1 points to the address of Form1 , so anything is changed in f1 obj would reflect in Form1 . "
Surely F1 is simply an instance of Form1 and nothing you do to F1 will affect the class from which it is instanced?
Do you mean:
so anything is changed in Form1 would reflect in F1 . "
If you meant to use the variable F1 as a reference to Form1, then shouldn't the declaration omit the "NEW" keyword?
Last edited by taxes; Feb 23rd, 2004 at 04:41 AM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
hehe , I understand what all this confusing about . .
I just forgot to delete this unnecessary line in the click event of Form2 (where I'm trying to get reference of what's been typed in the textbox of Form1) :
VB Code:
Dim f1 As New Form1
Though , it's working fine even with that line , but it really makes no big sense .
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f1 As New Form1
Me.Label1.Text = Me.Fm1TxtBox.Text
End Sub
I didn't look at the sample so I'm probably missing something but in this code here f1 is never used and could be deleted without effecting the code. Since its declared in the method it only has scope for the life of the method and it is never referenced again in the method once its created.
As a side note the Form object has a property named 'Owner' which can be used to assign a parent/child relationship to the form. It can be referenced in the child via the Owner property and in the Parent via the OwnedForms collection property. If you want to access controls on the forms then you'll need to cast them to the strong type that they are instead of the generic form type. An example of this can be found here.
EDIT: Sorry Pirate didn't see your last post. I must be typing slow tonight.
Last edited by Edneeis; Feb 23rd, 2004 at 04:42 AM.
I didn't look at the sample so I'm probably missing something but in this code here f1 is never used and could be deleted without effecting the code. Since its declared in the method it only has scope for the life of the method and it is never referenced again in the method once its created.
Yeah , exactly . I just forgot to delete this line . It's my first time I review this sample , so .
I'm afraid I have edited my last post while you were making your posts.
Please check my last post again.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
Originally posted by taxes If you meant to use the variable F1 as a reference to Form1, then shouldn't the declaration omit the "NEW" keyword?
VB Code:
Dim Frm As Form
This creates enough space(that fits Form Class) on the stack for Frm variable .
VB Code:
Frm =New Form1
Here , we instantiated (created the actual object that holds reference to Form1) .
This rule depends on the type of class you're working with . For example :
String Class is sealed (don't know what's called in VB) , which is not inheritable so can't be instantiated .
I'm afraid you are losing me. I will give up and stick with the little I know.
Thanks for trying.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
"I know I told you I did not mind you making a mistake once, but I did not expect you to make EVERY mistake in the book once!!"
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.