JessieErin

Hi,

I have some code I'm updating from VB6 to VB .NET and am having an annoying problem. I'm trying to assign a public variable to a string coming from a text box. The first time through the sub there is no problem but when the sub is called again the variable is assign a zero length string, even though there is still text in the text box. I can get the correct string if I assign an intermediate variable in another sub then assing that to the first variable but this hardly seems efficient. Any ideas why this may be happening

Thanks!



Re: Windows Forms General Getting string from Text Box

DeborahK

Could you post the code that is not working



Re: Windows Forms General Getting string from Text Box

JessieErin

sure. Everything is declared as Public strings in a module and pick2(i) is declared as a public instance of a structure.

sub usetext

With pick2(i)

.Conveyor = txtconveyor.text

.Reference = txtReference.Text

'More like this

End With

end sub

The second time through the sub I get txtconveyor.text = "" and same with all the similiar lines.

If I do this:

sub gettext

conveyortext=txtconveyor.text

referencetext=txtreference.text

end sub

sub usetext

With pick2(i)

.Conveyor = conveyortext

.Reference = ReferenceText

'More like this

End With

end sub

Then it works and the string is assinged properly.

Hope that helps, I'm sort of new at this!





Re: Windows Forms General Getting string from Text Box

DeborahK

Don't know if you are interested, but if you truly want to move to .NET, you should *not* be using modules OR public variables.

That said, where is this code Is it in the form Or in the module





Re: Windows Forms General Getting string from Text Box

JessieErin

the code is in the form.





Re: Windows Forms General Getting string from Text Box

DeborahK

So if you put a break point here:

sub usetext

With pick2(i)

.Conveyor = txtconveyor.text <-

.Reference = txtReference.Text

'More like this

End With

end sub

The first time through txtConveyor.Text has a valid value, but the second time through it is empty

Is there any code anywhere else that is initializing the txtConveyor.Text property





Re: Windows Forms General Getting string from Text Box

JessieErin

That's right.

Do you mean code like this

Private Sub InitializeComponent()

Me.txtConveyor = New System.Windows.Forms.TextBox

If that's what you were asking about then yes, otherwise I don't think so. (Like I said, I'm a little new to all this )





Re: Windows Forms General Getting string from Text Box

ZW2

Agree with Deborahk. Is there anywhere else changed Text properties of TextBox txtConveyor and txtReference

If applicable, could you provide us with the codes where sub GetText and UseText are called