Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

is there a way to do this ??? what is the Dim statement for it ?

 

i am trying to call a function from form one to form two but i don't know they dim statement or if this is even possible

 

thanks in advance

 

leeland

  • *Experts*
Posted

First you have to make that method Public. Then you need an instance of that form to actually call its method.

Dim SomeForm As New FormType 'create a new instance of the form
SomeForm.DoSomething() 'call its method

If you already have an instance of a form and dont want to create a new one you can do it by creating a class with shared members that will hold the instances. Or by passing the instance between the forms using constructors. If you need examples on those two just say :)

Posted

examples are always good

 

here is what i am working on which is causing me problems

 

i have 3 forms, a main for with 2 buttons to go to the other forms

 

for 2

 

for entering data into a text file

here i open a file to write to and enter data and so forth..

 

form 3

for reading the file entries that i put in with form 2

the problem is when i have one form open i get an error because the file is already open and can't access the file to read when the second form is open still..

 

i have tried to close the form when i click the read button but it still gives me the error...so i am stumped as of right now

 

 

also on my enter info form (form 2) i have a mask edit button for a phone number....when i enter data and then submit it

 

then exit the enter form (close) and then try to enter the form 2 again from the main form i get an error as well

 

' object reference is not set to an instance of an object'

 

here is what it is highlighting

 

mskPhoneNumber.SelStart = 0

mskPhoneNumber.SelLength = mskPhoneNumber.Mask.Length

mskPhoneNumber.SelText = "( )- - "

 

i have this in the load statment of the enter form (form1)

 

any ideas ?

 

and thanks for the quick reply

  • *Experts*
Posted

You could do this the following way:

Create two variable that will hold instances of your two additional forms: (somewhere at the top of your form)

Dim formOne As FormType
Dim formTwo As FormTwoType
'just subsititute this with the names you are using : )

Then, each time you want to show the form you would do something like this:

formOne = New FormType
'now the variable will contain a new instance of the form
'and you will be able to access the form using that variable

This will prevent the error that you are getting. Using the Close() method also disposes of the from if its not shown as a dialog so the instance is no longer available. So next time you want to show it, it will create a new one. If you only want to have one instance of the form without creating new ones, you could always hide it instead of closing it.

Posted

got ya on the hide part

 

how do you go about making the form just go to theback, like still being visible but not active ?

 

another way to say it would be to have all three forms on the screen and being able to select each one instead of hiding the non active ones

 

 

thanks again

 

leeland

  • *Experts*
Posted

To send a form to back you would use its SendToBack method.

If you just want to make inactive you would set focus another one using Focus() method the form.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...