|
Another CPian wrote to me in a separate email, asking "...trying to have a form, that when you click on a command button, the main form comes up. The first one would be an opening form, and the second the main program" I thought I'd post the first solution that occurred to me here, and ask if anyone else has a brighter idea.
Here's what I did. I create two forms, one named StartupForm, and one named MainForm. The form StartupForm is set as the startup object in the project's properties.
StartupForm:
Public Class StartupForm
Inherits System.Windows.Forms.Form
' Windows Form Designer generated code omitted
Private Sub cmdStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStart.Click
Dim myForm As New MainForm(Me) ' MainForm's constructor New is overloaded
Me.Hide() ' Make me invisible
myForm.Show() ' Display MainForm
End Sub
End Class
MainForm:
Public Class MainForm
Inherits System.Windows.Forms.Form
Private _caller As Object
' Windows Form Designer generated code omitted
Public Sub New(ByVal caller As Form)
MyBase.New()
InitializeComponent()
_caller = caller
End Sub
Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click
CType(_caller, Form).Close()
Me.Close()
End Sub
End Class
This was pretty quick & dirty, so there are probably some obvious enhancements to be made. Suggestions, comments, questions and revisions are invited...
|
|
|
|
|
I just thought of another way to implement the splash form by showing the SplashForm on the Load() event of the MainForm and hiding the MainForm.
Public Class MainForm
Inherits System.Windows.Forms.Form
 Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim splashForm As New SplashForm()
splashForm.ShowDialog(Me)
Me.Hide()
End Sub
End Class
Public Class SplashForm
Inherits System.Windows.Forms.Form
 Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click
Me.Close();
Me.Owner.Show();
End Sub
End Class
I have tested it and it seems to be working fine.
Edbert P.
Sydney, Australia.
|
|
|
|
|
I like it. My only thought is that the other fellow was asking about two forms, neither of which sounded like a splash form when he described them to me.
Does Form1 flash on the screen at all before it hides itself?
|
|
|
|
|
When I tested it Form1 didn't flash at all.
I suppose since I implemented the code in the Form_Load event it hadn't showed the form itself before the code got triggered.
Edbert P.
Sydney, Australia.
|
|
|
|
|
That thought didn't dawn on me as soon as it should have...
|
|
|
|
|
Hai,
I've a component registed in my system. When i call the component from the ASP page it works fine. When I create an instance of the same component in VB Application, I get the error, object variable or with block variable not set. The error comes in the 3rd line of my code which i have specified below:
Dim Con_Getcon As New JBHRCom.GetConnection
Dim Con_ObjDB As New ADODB.Connection
Set Con_ObjDB = Con_Getcon.Connection
Could anyone help me out as soon as possible.
Thank you,
Regards,
K. Sripriya
|
|
|
|
|
It's pretty hard to give you a correct answer without knowing what kind of object JBHRCom is, but assuming that you stick to "talking" naming convention, GetConnection method returns an object of ADODB.Connection type. I would try something like this instead:
Dim Con_Getcon As New JBHRCom
Dim Con_ObjDB As New ADODB.Connection
Set Con_ObjDB = Con_Getcon.Connection
|
|
|
|
|
I want the text that we key in in the vb form must in Uppercase.What is the method's?Help....................help............
Hi, i have create a program using VB6.The purpose of this program are for sales department person key in the data and then review by manager.Now, my problem is manager want me to create a command button to export the data from microsoft access to excel.What is the command button code and the step? Another Question,this program must set up in the office and all the staff can see and use this program at their own PC's!Thank for ur help!
|
|
|
|
|
Upper case is : Ucase$(string)
Access to Excel: Add a reference to Microsoft Excel Object.
Public Class clsXL
Dim xl as Excel.Application
Private Sub Class_Initialize()
On Error Resume Next
Set xl = CreateObject("Excel.Application")
xl.DisplayAlerts = False
End Sub
Private Sub Class_Terminate()
' If IsLaunched Then xl.Application.Quit
Set xl = Nothing
End Sub
Public Function Export(rs As Recordset) as Boolean
dim ws as Worksheet
dim c as integer 'column
dim i as integer 'row counter
If Not xl Is Nothing Then
xl.Workbooks.Add
Set ws = xl.ActiveSheet
'Set the column headers
'....
'Now loop through the rows & columns of the recordset to add the values
i = 2
do while not rs.eof
for c = rs.fields.count
w.Cells(i, c) = .Fields(c).Value & vbNullString
i = i + 1
rs.movenext
next
loop
'Format work sheet further
'now print preview the sheet
xl.DisplayAlerts = False
xl.Visible = True
xl.ActiveWorkbook.Worksheets.PrintOut , , , True
xl.Visible = False
xl.Application.Quit
end if
End Function
By doing this he can do what ever he wants with the excel spreadsheet Save, Sent To or Print.
Hope this helps.
Michael
|
|
|
|
|
I want the text that we key in in the vb form must in Uppercase.What is the method's?Help....................help............
Hi, i have create a program using VB6.The purpose of this program are for sales department person key in the data and then review by manager.Now, my problem is manager want me to create a command button to export the data from microsoft access to excel.What is the command button code and the step? Another Question,this program must set up in the office and all the staff can see and use this program at their own PC's!Thank for ur help!
|
|
|
|
|
hint :
use SetWindowLong API passing the window handle of the text box and ES_UPPERCASE
|
|
|
|
|
Why not just do it the simple way:
in the keydown event just do a .toupper for the char and handle the event.
|
|
|
|
|
Hi
Which property shud i set to make button a default button, so that when it is clicked the event fires automatically.
Thanks
Tasnim
|
|
|
|
|
I believe what you are asking is which property sets a button to the button that is the default action for a form, such that press "Enter" causes the click event of that button.
That property is the AcceptButton property of the Form.
|
|
|
|
|
i am trying to open the default email client with attachment.
i have successfully opened the default client, but i am not able to have it with attachment.
How can i do this ?
Looking for Help.
Regards,
Asim
|
|
|
|
|
as topic, anyone can provide some codes that enable a scroll bar to a picturebox when the picture expand?
|
|
|
|
|
Drop 2 PictureBoxes on your form, so that Picture1 is Picture2's Container. Drop horizontal and vertical ScrollBar controls on proper positions around Picture1. Set Picture1.AutoSize = False and Picture2.AutoSize = True. As you load picture(s) into Picture2, execute the following code:
If Picture2.Width > Picture1.Width Then
ScrollBarH.Enabled = True
Else
ScrollBarH.Enabled = False
End If
If Picture2.Height > Picture1.Height Then
ScrollBarV.Enabled = True
Else
ScrollBarV.Enabled = False
End If
Hope, it helps.
|
|
|
|
|
In my previous posting I forgot to mention that you control the position of Picture2 relative to Picture1 (which is a Container, remember?) with your scrollbars. The code to do that seems trivial enough: the horizontal scrollbar has to increment/decrement the Picture.Left, while the vertical one controls Picture2.Top properties.
|
|
|
|
|
Okay, here's the deal. Let's just say I have a variable, amtChange, which is a single floating point number. Let's say that it's 1.23 in this example. If I subtract amtDol, which is an integer with a value of 1, I end up with .2299995 as a difference. I find that this happens often.
How can I prevent and/or fix this? Oh, here's my code:
Private amtOwed, amtPaid, amtChange As Single<br />
Private amtDol, amtQuar, amtDime, amtNick, amtPen As Integer<br />
<br />
***<br />
<br />
amtOwed = Val(txtOwed.Text)<br />
amtPaid = Val(txtPaid.Text)<br />
amtChange = amtPaid - amtOwed<br />
amtDol = Int(amtChange)<br />
amtChange = amtChange - amtDol<br />
MsgBox(amtChange)<br />
And the Message Box gives me .2299995!
|
|
|
|
|
i'm not expert in this but try to change the data type into double
|
|
|
|
|
Hi,
You can try this.
Define all the variables as double or type cast it into double and then subtract it. Take the
result into a variable which is double.
Tasnim
|
|
|
|
|
As a matter of fact, it turns out the Decimal variable type doesn't generate ambiguous errors. Thanks for the input, though. I really appreciate it!
|
|
|
|
|
For starters, I am coming from a C/C++ background and I am trying to format a string with String.Format() but the options are somewhat different than that of the conventional printf and its derivatives.
Essentially what I want to have happen is I want to print out a numeric value in currency format but I want the number of spaces "before" the decimal place to be fixed. For instance, in the following example I show what I want the output to look like:
WHAT I WANT!
Name: Amount Due:
Jack Rolley $1,234.56
Jane Polley $ 843.76
WHAT I HAVE BEEN GETTING!
Name: Amount Due:
Jack Rolley $1,234.56
Jane Polley $843.76
I have tried using a variety of option with the String.Format() method and I can't seem to find a way to get what I want. Is there a common method (option) that I can use to get the hanging dollar sign?
I am using Visual Studio .NET at the student labs here at my university. Any insight into the string formatting issue would be greatly appreciated.
Thanks in advance,
Luke Martell
Kelsen_@hotmail.com
|
|
|
|
|
Hello Luke,
iv checked out this problem and here is exactly what you want. hope it helps.
Module Module1
Sub Main()
Dim amtDue(1) As Double
Dim myString(1) As String
amtDue(0) = 1234.56
amtDue(1) = 843.76
myString(0) = Format(amtDue(0), "n")
myString(1) = Format(amtDue(1), "n")
Console.WriteLine("$" & myString(0).PadLeft(8, " "))
Console.WriteLine("$" & myString(1).PadLeft(8, " "))
Console.ReadLine()
End Sub
End Module
this will display:
$1,234.56
$ 843.76
Jordan.
III
|
|
|
|
|
me again
Hmm..
here is a much more portable way to implement this code, using a function i made:
Module Module1
Sub Main()
Dim amtDue(1) As Double
amtDue(0) = 1234.56
amtDue(1) = 843.76
Console.WriteLine(PadAmt(amtDue(0)))
Console.WriteLine(PadAmt(amtDue(1)))
Console.ReadLine()
End Sub
Function PadAmt(ByVal amt As Double)
Dim mystring As String
mystring = Format(amt, "n")
Return "$" & mystring.PadLeft(8, " ")
End Function
End Module
again, this will display EXACTLY what you wanted, as in my other reply.
Please lemme know how it goes, thx.
Jordan.
III
|
|
|
|