Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Create a Form with the Vb code

Posted on 2003-02-26
Medium Priority
Last Modified: 2010-05-01
I have a form1 in which i have created a button , when u click the button in form1 it should generate a form2 getting few parameter from form1 and do few claculations .Apart from these the form2 also has two buttons ,few standard data and decorations.I need to create this form by writing Vb script .Since i've just started vb can anyone help me to proceed with this issue.
Thanks in Advance
Question by:vb_7

Expert Comment

ID: 8023784
you can create new forms by using "new" keyword. as follows:

dim frm2
set frm2=new form1
'you can use tag to distinguish form2 from form1 because the outlook and behavior of form2 is exactly same as form1

'show the newly created form

then in any sub, respond according to the tag value, e.g:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
if me.tag="form2" then
  'execute code for form2
  'execute code for form1
end if

good luck!

Expert Comment

ID: 8023834
you cited you need to use VBSCRIPT... but i assume you just mean VB code...

' ************ in form1 *****************
Private Sub Command1_Click

  'we will write in Caption of Form2 the sum of the passed parameters

  Dim frm as new Form2
  Dim i as Integer, j as Integer

  frm.Show vbModal

  set frm = nothing
End Sub

'******************in form2 **************

Public Sub A_Setup(Num1 as Integer, Num2 as Integer)

  Me.Caption = Cstr(Num1 + Num2)

end Sub

Expert Comment

ID: 8024566

In Vb You Want To Do Some Calcualtions in Form2 also, then There Is No Way Using the Above Comments. So In Design Time Itself You Just add One More Form. By default its Name is Form2.

Write Function in Form2 as Follows,
Function cal(i As Integer)
    MsgBox i
End Function

assume u have coomand1 in Form1

public sub command1_click()
   call cal(10)
end sub

I Hope This will be HelpFul

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Expert Comment

ID: 8029075
So you want to pass variables between forms...

I tried earlnoli's code ,.. couldn't get it to work...

the only way I've been able to do it is by loading
controls within form one with the data you want to preserve and then loading the new form modally (I think)  
and getting the values from the still open form.

form1, form2




Expert Comment

ID: 8901104
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
LVL 49

Expert Comment

ID: 8972916
vb_7, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Save as PAQ -- No Refund.

DanRollins -- EE database cleanup volunteer

Accepted Solution

Computer101 earned 0 total points
ID: 9668015
PAQed - no points refunded (of 50)

E-E Admin

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question