By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,632 Members | 1,425 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,632 IT Pros & Developers. It's quick & easy.

[2005] multiple form help!!!

P: 12
Hi

I must be missing something very straightforward.

I load data in Form1 and show 'Name', 'Abreviation', 'Value1', 'Value2' etc

In Form 2 i have to show by a Combo Box into a list box the 'Name' and calculation of 'Value1 and 'Value2.

However when i go into Form 2 i just get the info that i asked to look at on Form 1.
I must be brain dead or something.

Help Please
Mar 27 '07 #1
Share this Question
Share on Google+
8 Replies


SammyB
Expert 100+
P: 807
Hi

I must be missing something very straightforward.

I load data in Form1 and show 'Name', 'Abreviation', 'Value1', 'Value2' etc

In Form 2 i have to show by a Combo Box into a list box the 'Name' and calculation of 'Value1 and 'Value2.

However when i go into Form 2 i just get the info that i asked to look at on Form 1.
I must be brain dead or something.

Help Please
No, you're not brain dead: it's hard the first time and difficult the second time. :) You just need to do two things:
  1. Pass a Form1 reference to Form2 by overloading Form2's constructor.
  2. In the Forms Designer for Form1, set the Modifiers to Protected or Public.
Mar 27 '07 #2

P: 12
Hi
[quote]
No, you're not brain dead: it's hard the first time and difficult the second time. You just need to do two things:
Pass a Form1 reference to Form2 by overloading Form2's constructor.
In the Forms Designer for Form1, set the Modifiers to Protected or Public
[quote]

I have gone into Forms Designer for Form1 and their is no Modifier to set.
And what do you mean by overloading Form2's constructor.

Also will this still enable me in Form 2 for each 'Name' Selected from ComboBox i will be able to show each one in a List Box

Thanks
Mar 27 '07 #3

P: 12
:wave:
:wave:

:afrog:

I'm all goggle eyed

Trying to sort problem my self but just getting lost

HELP PLEASE

Thanks
Mar 27 '07 #4

SammyB
Expert 100+
P: 807
:wave:
:wave:

:afrog:

I'm all goggle eyed

Trying to sort problem my self but just getting lost

HELP PLEASE

Thanks
Sorry, I missed your eariler post, my spam filter removes post notifications. Your thread question title has 2005 in it and I assumed that you are using VB.NET 2005. But from your replies, it seems that you are not. What VB are you using? VBA, VB6, or VB.NET
Mar 27 '07 #5

P: 12
Hi

Am using 'Visual Studio 2005' v.8 with the MS .Net Framework v.2

Hope this helps

Thanks
Mar 27 '07 #6

SammyB
Expert 100+
P: 807
Hi

Am using 'Visual Studio 2005' v.8 with the MS .Net Framework v.2

Hope this helps

Thanks
OK. let's start again and just create a simple two form example in VB. Then, you can use the principles for your forms.
  1. Open VB.NET, create a new Win App and add another form
  2. Put a textbox and a button on form1
  3. Select the textbox and in the properties window change the Modifiers property from Friend to Public
  4. Open the form designer for form2 and double-click on the form to create a load event
  5. Add a property to Form2 that will hold the Form1 object. Now form2 code should look like:
Expand|Select|Wrap|Line Numbers
  1. Public Class Form2
  2.     Public FrmParent As Form1
  3.  
  4.     Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  5.         MsgBox(FrmParent.TextBox1.Text)
  6.     End Sub
  7. End Class
Finally, switch back to form1 and double click on the button. Add the following code so that form2 code looks like

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  3.         Dim frm As New Form2
  4.         frm.FrmParent = Me
  5.         frm.Show()
  6.     End Sub
  7. End Class
Running this, you can see how multiple forms can work together. In form1, the form1 object is called "me", and the form2 object is called frm, In form2, the form1 object is called FrmParent and the form2 object is called "me". Either form can access anthing in the other form that has been declared public: controls, properties, or even methods (Sub). So, now you need to decide how to communicate and how events on one form should affect the other form. --Sam
Mar 27 '07 #7

P: 12
Hi
This is part of the code in Form2 that requires the info from Form1

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmbSpecies_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSpecies.SelectedIndexChanged
  2.         Dim Perc As Decimal
  3.  
  4.         'cmbSpecies.Items.Add(Form1.txbSpecies.Text)
  5.         Select Case CStr(cmbSpecies.SelectedItem)
  6.             Case "Brown argus"
  7.                 If CDbl(Form1.txb2000.Text) <= 0 Then
  8.                     MsgBox("This is New Data for " & Form1.txbSpecies.Text)
  9.                 End If
  10.                 Perc = CDec(CInt(CStr(CDbl(Form1.txb2005.Text) - CDbl(Form1.txb2000.Text))) / (CInt(CStr(CDbl(Form1.txb2000.Text))))) * 100
  11.             Case "Glanville fritillary"
  12.                 If CDbl(Form1.txb2000.Text) <= 0 Then
  13.                     MsgBox("This is New Data for " & Form1.txbSpecies.Text)
  14.                 End If
  15.                 Perc = CDec(CInt(CStr(CDbl(Form1.txb2005.Text) - CDbl(Form1.txb2000.Text))) / (CInt(CStr(CDbl(Form1.txb2000.Text))))) * 100
  16.             Case "Purple hairstreak"
  17.                 If CDbl(Form1.txb2000.Text) <= 0 Then
  18.                     MsgBox("This is New Data for " & Form1.txbSpecies.Text)
  19.                 End If
  20.                 Perc = CDec(CInt(CStr(CDbl(Form1.txb2005.Text) - CDbl(Form1.txb2000.Text))) / (CInt(CStr(CDbl(Form1.txb2000.Text))))) * 100
  21.             Case "Silver studded blue"
  22.                 If CDbl(Form1.txb2000.Text) <= 0 Then
  23.                     MsgBox("This is New Data for " & Form1.txbSpecies.Text)
  24.                 End If
  25.                 Perc = CDec(CInt(CStr(CDbl(Form1.txb2005.Text) - CDbl(Form1.txb2000.Text))) / (CInt(CStr(CDbl(Form1.txb2000.Text))))) * 100
  26.             Case "Chalkhill blue"
  27.                 If CDbl(Form1.txb2000.Text) <= 0 Then
  28.                     MsgBox("This is New Data for " & Form1.txbSpecies.Text)
  29.                 End If
  30.                 Perc = CDec(CInt(CStr(CDbl(Form1.txb2005.Text) - CDbl(Form1.txb2000.Text))) / (CInt(CStr(CDbl(Form1.txb2000.Text))))) * 100
  31.             Case "Large blue"
  32.                 If CDbl(Form1.txb2000.Text) <= 0 Then
  33.                     MsgBox("This is New Data for " & Form1.txbSpecies.Text)
  34.                 End If
  35.                 Perc = CDec(CInt(CStr(CDbl(Form1.txb2005.Text) - CDbl(Form1.txb2000.Text))) / (CInt(CStr(CDbl(Form1.txb2000.Text))))) * 100
  36.             Case "Common blue"
  37.                 If CDbl(Form1.txb2000.Text) <= 0 Then
  38.                     MsgBox("This is New Data for " & Form1.txbSpecies.Text)
  39.                 End If
  40.                 Perc = CDec(CInt(CStr(CDbl(Form1.txb2005.Text) - CDbl(Form1.txb2000.Text))) / (CInt(CStr(CDbl(Form1.txb2000.Text))))) * 100
  41.             Case "Grizzled skipper"
  42.                 If CDbl(Form1.txb2000.Text) <= 0 Then
  43.                     MsgBox("This is New Data for " & Form1.txbSpecies.Text)
  44.                 End If
  45.                 Perc = CDec(CInt(CStr(CDbl(Form1.txb2005.Text) - CDbl(Form1.txb2000.Text))) / (CInt(CStr(CDbl(Form1.txb2000.Text))))) * 100
  46.             Case "Silver washed fritillary"
  47.                 If CDbl(Form1.txb2000.Text) <= 0 Then
  48.                     MsgBox("This is New Data for " & Form1.txbSpecies.Text)
  49.                 End If
  50.                 Perc = CDec(CInt(CStr(CDbl(Form1.txb2005.Text) - CDbl(Form1.txb2000.Text))) / (CInt(CStr(CDbl(Form1.txb2000.Text))))) * 100
  51.  
  52.         End Select
  53.  
  54.         'Cannot seem to make this Format work 
  55.         Format(Perc, "0.00%")
  56.         'This does not seem to be working. Trying to make sure that
  57.         'a Species is selected
  58.         If cmbSpecies.SelectedIndex <> -1 Then
  59.  
  60.             lbxButter.Items.Add((cmbSpecies.Text) & "                   " & CDbl((CInt(FormatCurrency(Perc)))))
  61.         End If
  62.  
  63.     End Sub

This is part of the code in Form1
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnForm2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForm2.Click
  2.  
  3.  
  4.  
  5.         Dim frmForm2 As New Form2
  6.  
  7.         frmForm2.Show()
  8.  
  9.  
  10.     End Sub
  11.  
I have now made the Text boxes in Form1 Public (in Modifier) and the btnForm in Form 1 also Public.

ann.jenkins1606@btinternet.com
I still have the problem that when i select from the Combo box in Form2 i only obtain info that is showing on Form1, i could have both forms open and display from Form1 and select on Form2.
I hope i have not sent too much info.

My brain is almost dead, but i am determined

Thanks
Mar 27 '07 #8

P: 12
Hi

Sorry to be a nusiance any help out there

Thanks
Mar 28 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.