Sorcerer14

Why can't I simply have a sub in one form (form1) enter text in a textbox (on form3) and then have a sub in a second form (form2) read that same text Do the two separate forms (form1 and form2) not speak the same language or is the value just not saved in memory accessible by both forms If this is the case, could I just use mysettings to save the values and access accross forms

thanks again!




Re: Visual Basic Express Edition Can someone explain why it is so complex to read text values in same textbox from different forms?

ReneeC

It's not the least bit complicated and there's a proper way to do it.

Friend ReadOnly Property GetTextbox1Contents() As String

Get

Return TextBox1.Text

End Get
End Property

Put this in form1 and call it from form2






Re: Visual Basic Express Edition Can someone explain why it is so complex to read text values in same textbox from different forms?

Sorcerer14

Thanks Renee, I think this will work. However, when I run my sub in the second form, which is trying to read the text input by the first form, it says that the value is "" and throws an exception, since I'm trying to use it as integer. It seems that the breakdown occurs when I perform the "click" ok button on the second form, which is trying to compare the textbox value input in first form to a threshold determined on first form. (I'm trying to create a password authentication routine). Could there be something simple I am missing Below is my passwork check sub. My first form loads values into textboxes 4 and 5 on the securitymain form, which can't seem to be read when my Dialog1 form tries to compare.

Public Class Dialog1

Public Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click

'why does textbox4 not have value here All values from Load sub no longer held

Dim password As String = My.Forms.SecurityMain.TextBox4.Text

'why does textbox5 not have value here All values from Load sub no longer held

Dim cycle1 As Integer = My.Forms.SecurityMain.TextBox5.Text

If Me.TextBox1.Text = password Then

My.Forms.SecurityMain.TextBox5.Text = cycle1 + 1

My.Settings.Save()

Me.DialogResult = System.Windows.Forms.DialogResult.OK

Me.Close()

My.Forms.UserInterfaceFrm.GroupBox1.Enabled = True

Else

MsgBox("Password is not correct! Try again.")

End If

End Sub

End Class






Re: Visual Basic Express Edition Can someone explain why it is so complex to read text values in same textbox from different forms?

ReneeC

ron,

Just out of curioisity, try this:

Dim f as SecurityMain = SecurityMain

then

dim a as string = f.textbox4.text






Re: Visual Basic Express Edition Can someone explain why it is so complex to read text values in same textbox from different forms?

Sorcerer14

Posted this before the first line and showed a msgbox to show the value and it was blank. Can you think of anything else to try I'm almost to the point where I might just use mysettings to hold the values since that is the only way I know of to be able to create and save values that can then be pulled from other forms. Any suggestions would be greatly appreciated!

Thx!

Eric






Re: Visual Basic Express Edition Can someone explain why it is so complex to read text values in same textbox from different forms?

ReneeC

Eric,

I don't understand why this is a problem at all.

*Sigh* I am trying to get some work done but zip up the project and send it to me at rmctwo<nospam>at<nospam>gmail dot com.






Re: Visual Basic Express Edition Can someone explain why it is so complex to read text values in same textbox from different forms?

Sorcerer14

I tried to zip, but the project is over 100 MB, so couldn't send through email (quite a bit more to the whole project than these three forms). Renee, can you see if the code below helps at all when you get a chance (or anyone else out there)

Figured to help clarify, I'd post all the code in addition to what I posted above. The code I posted earlier is in my Dialog1 form (a simple form with a textbox and "ok" and "cancel" buttons. When "ok" is clicked, it checks the password. Password and cycle and days elapsed are all kept in Security Main form. The primary user interface is userinterface form. When userinterface form loads, it runs the following code to determine whether a password prompt should appear based on info in the Security Main form. The error comes in my earlier posted code where it tries to read mainform.textboxes 4 and 5 and shows they have nothing. Thanks again for all your help!

Code Snippet

Public Sub Password()

Me.PasswordTableTableAdapter.Fill(Me.PasswordListDataSet.PasswordTable)

Dim currentdate As Date

currentdate = Format(Date.Now, "MM/dd/yyyy")

My.Forms.SecurityMain.TextBox3.Text = currentdate

'the following should populate SecurityMain only if first time program is opened

If My.Forms.SecurityMain.TextBox1.Text = "" Then

'this date is the basedate from which days elapsed are counted to trigger password

My.Forms.SecurityMain.TextBox1.Text = "07/15/2007"

'this is simply the first password that will be used

My.Forms.SecurityMain.TextBox4.Text = "223546"

'this is the cycle, when the cycle times # of days per cycle is exceeded, password is prompted

My.Forms.SecurityMain.TextBox5.Text = "1"

'below is the # of days per cycle, eg 5 days between each password prompt

My.Forms.SecurityMain.TextBox6.Text = "5"

End If

Dim basedate As Date = My.Forms.SecurityMain.TextBox1.Text

Dim cycle As Integer = My.Forms.SecurityMain.TextBox5.Text

Dim triggerperiod As Integer = My.Forms.SecurityMain.TextBox6.Text

Dim threshold As Integer = Math.BigMul(cycle, triggerperiod)

Dim dayselapsed As Integer = Math.Round(DateDiff(DateInterval.Day, basedate, currentdate))

If dayselapsed > threshold Then

'a datatable contains all the passwords that will be used each time a new one is prompted

My.Forms.SecurityMain.TextBox4.Text = Me.PasswordListDataSet.PasswordTable.Rows(cycle - 1).Item(0)

'this is where my userinterface is disabled until the correct password is entered

Me.GroupBox1.Enabled = False

'this shows the prompt for a password to be entered

My.Forms.Dialog1.Show()

End If

End Sub






Re: Visual Basic Express Edition Can someone explain why it is so complex to read text values in same textbox from different forms?

ReneeC

I have not been able to get this to fail however i notice you are going the other way...let me try that

Public Class Form1

Private Sub cbGo_Click(ByVal sender As Object, _

ByVal e As System.EventArgs) _

Handles cbGo.Click

Form2.Show()

End Sub

End Class

Public Class Form2

Private Sub Form2_Load(ByVal sender As Object, _

ByVal e As System.EventArgs) Handles Me.Load

TextBox1.Text = My.Forms.Form1.TextBox1.Text

End Sub

End Class

what kind of class or module does this subroutine of your sit in That's important.






Re: Visual Basic Express Edition Can someone explain why it is so complex to read text values in same textbox from different forms?

ReneeC

Please post the whole class that that subroutine is in......






Re: Visual Basic Express Edition Can someone explain why it is so complex to read text values in same textbox from different forms?

Sorcerer14

Both subs are just in the "Public Class UserInterfaceFrm" and "Public Class Dialog1" forms. Here is the Dialog 1 form class. The UserInterfaceFrm is over 5000 lines and is mostly stuff that shouldn't have any impact. Hope this helps! Maybe I could email you the UserinterfaceFrm code in text file

Public Class Dialog1

Public Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click

Dim password As String = My.Forms.SecurityMain.TextBox4.Text

'why does textbox5 not have value here All values from Load sub no longer held

Dim cycle1 As Integer = My.Forms.SecurityMain.TextBox5.Text

If Me.TextBox1.Text = password Then

My.Forms.SecurityMain.TextBox5.Text = cycle1 + 1

My.Settings.Save()

Me.DialogResult = System.Windows.Forms.DialogResult.OK

Me.Close()

My.Forms.UserInterfaceFrm.GroupBox1.Enabled = True

Else

MsgBox("Password is not correct! Try again.")

End If

End Sub

Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click

Me.DialogResult = System.Windows.Forms.DialogResult.Cancel

Me.Close()

Application.Exit()

End Sub

Private Sub PasswordTableBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

Me.Validate()

Me.PasswordTableBindingSource.EndEdit()

Me.PasswordTableTableAdapter.Update(Me.PasswordListDataSet.PasswordTable)

End Sub

Private Sub Dialog1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'TODO: This line of code loads data into the 'PasswordListDataSet.PasswordTable' table. You can move, or remove it, as needed.

Me.PasswordTableTableAdapter.Fill(Me.PasswordListDataSet.PasswordTable)

End Sub

End Class






Re: Visual Basic Express Edition Can someone explain why it is so complex to read text values in same textbox from different forms?

ReneeC

I have a hypotheses.... I can't get anything to fail here.

Are anyof these textboxes in containers such a groupboxes or panels or any kind of container That would do it.






Re: Visual Basic Express Edition Can someone explain why it is so complex to read text values in same textbox from different forms?

ReneeC

Source....

I'm willing to bet those controls are in containers.

The cure is rather strange. Here's an example illustrating how to deal with this if the texbox is in a groupbox

Dim Foo as textbox

For each c as control in form1.goupbox1.controls

If control.Name = "textbox4" then

foo = c

exit for

endif

Next

Foo.text = "Hello World"

That should do it. If it's contained in layers of controls... well we can deal with that too.






Re: Visual Basic Express Edition Can someone explain why it is so complex to read text values in same textbox from different forms?

ReneeC

Source....

I'm willing to bet those controls are in containers.

The cure is rather strange. Here's an example illustrating how to deal with this if the texbox is in a groupbox

Dim Foo as textbox

For each c as control in form1.goupbox1.controls

If control.Name = "textbox4" then

foo = c

exit for

endif

Next

Foo.text = "Hello World"

That should do it. If it's contained in layers of controls... well we can deal with that too.

brw... I am not a sourcerer ... I am a witch !






Re: Visual Basic Express Edition Can someone explain why it is so complex to read text values in same textbox from different forms?

Spidermans_DarkSide - MSP, VSIP

Hi,

Get the latest edition here.>>

http://msdn.microsoft.com/vstudio/express/future/default.aspx

or here for image file download links.>>

http://msdn.microsoft.com/vstudio/express/future/downloads/default.aspx

This works in the latest "Orcas" FREE VB.Net express edition OR the team edition community technology preview CTP edition.

I am not sure if it will work in earlier versions as i have not tested it yet. >>>>

Public Class Form1

'The next two lines should be one line of code in your code window.>>>>

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

TextBox1.Text = "Hello there!!"

Form2.Show()

End Sub

End Class

'Form2 code.>>

Public Class Form2

'The next two lines should be one line of code in your code window.>>>>

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'This will put in the titleBar of Form2

'whatever is in the textbox1 on Form1

Me.Text = Form1.TextBox1.Text

End Sub

End Class

Regards,

S_DS






Re: Visual Basic Express Edition Can someone explain why it is so complex to read text values in same textbox from different forms?

ReneeC

It may help if you read the thread before you rush in DS.