|
Do you want to create a new workbook every time?
If not use an OleDb Connection to access the Excel Jet datasource and use a query to update the Workbook. This way formatting is handled by Excel and you build a list of "Registration rows"....
You will also need to add a reference to Microsoft Excel version you are using..
Dim fileName As String = "..." ' Valid filepath and filename
Dim cn As OleDbConnection
If cn Is Nothing Then
cn = New OleDb.OleDbConnection
End If
cn.ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;" & _
"Data Source=E:\" & filename & ";" & _
"Extended Properties=Excel 8.0;"
Try
Dim s As String = "INSERT INTO [SheetName$](" & _
"Psswrd, Conform, FName, MName, Gender, " & _
"DiscountAmount, InvoiceTotal) & _
"Values('" & Me.txtPwd.Text "','" & _
Me.txtConform.Text & "'," & _
Me.txtFName.Text & "','" & _
Me.txtMName.Text & "'," & _
Me.txtLName.Text & "','" & _
Me.ddlGender.SelectedItem & "','" & _
Me.txtDiscountAmount.Text & "','" & _
Me.txtInvoiceTotal.Text & "')"
cn.Open()
Dim cmd As New OleDbCommand(s,cn)
cmd.ExecuteNonQuery()
cn.Close
Catch ex As Exception
....
Finally
If cn.State <> ConnectionState.Closed Then cn.Close
End Try
....
Something like this is fast and easier on resources than your application object version...
Cheers
The Fanatical All Black Supporter - Kea Kaha
|
|
|
|
|
I am writing an application in VB.NET. I learned VB.NET in college, but have been coding PHP. So, I don't have much experience in VB.NET.
I have already built the interface to the program. I used panels to create each form on. What I would like to do is allow the user to click on button 1 which will then load panel 1. I also want panel 1 to come up when the user starts the program.
I also want the user to be able to click on button 2. Then once button 2 is clicked on I want panel 1 to dissapear and I want panel 2 to come up on the screen.
How do I do this?
|
|
|
|
|
Assuming that a panel is a control, it has a Visible property. If by panel you mean seperate windows, buy a book on Vb.NET and work through it. A form is just a class, you create an instance of it as you would any other class.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Could you tell me good tutorial site or good book learning VB.NNet windows application?
Thanks
Aniruth
|
|
|
|
|
You're better off starting with a good book, then you can download and read articles on ths site, plus MSDN is the Microsoft reference site - msdn2.microsoft.com[^]
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
This is a good tutorial which you can follow on the web or buy for a small price Click here
I found it to be concise, easy to follow and enjoyable.
It would also be worth reading the following Code Project article as it explains a bit about .NET itself Click here
Finally as a general tutorial on OOP I would recommend Click here
Enjoy the journey
You always pass failure on the way to success.
|
|
|
|
|
Hi,
Here's a good link:
http://visualbasic.about.com/od/learnvbnet/Learn_VBNET_Visual_Basic_for_the_new_millenium.htm
Lloyd J. Atkinson
|
|
|
|
|
Could you tell me good tutorial site or good book learning VB.NNet windows application?
Thanks
|
|
|
|
|
|
|
im working on a vb.net project of 5 forms. 2 forms of these when loaded has a radiobutton that it is checked eventhough they are not selected and also they checked property is set to false,please help me to uncheck these radio button,btw i tried to write the code 'radiobutton.checked=false' at form load and it didnt work.
this problem arised after i ordered the tab from menu/view order tab.
thanks alot.
|
|
|
|
|
zamzoum wrote: 2 forms of these when loaded has a radiobutton that it is checked eventhough they are not selecte
That's because Radiobuttons work by selecting one option out of a list of options. There is not a "no option selected" way for Radiobuttons to work. No matter what you do, the first RadioButton will always be selected by default.
|
|
|
|
|
10x dave for replying,but the default for radio buttons is to be unchecked and the user select his option from the list of radio buttons and that is not my case,i have checked radio buttons on form loading even that their property is set to false,btw in the other forms of my project i do not have this problem.so what can u advise me?
10x alot
|
|
|
|
|
What Dave is saying is not entirely true (at least in vb.net, I don't know about vb6). When you create a form, and add radiobuttons, they will be unchecked by default. When the form is loaded, the radiobuttons will all be unchecked until you make a choice.
The better question however is, why would you want to use radiobuttons and then have them all be unchecked? The basic idea of the radiobutton is to force the user to make a choice. Otherwise you really should consider using checkboxes instead.
Good luck,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
Johan Hakkesteegt wrote: When the form is loaded, the radiobuttons will all be unchecked until you make a choice.
Not true. I thought the same thing until I threw a test project together to verify it.
Dropped a GroupBox, or a Panel, it doesn't matter which, on a Form and dropped 5 RadioButtons on the form. Didn't change anything and verified all the Checked properties on all RB's were set to false. I also verified that no funky code showed up in the Designer generated code setting one of them to True. Then I ran the code and watched the first RadioButton get checked automatically.
|
|
|
|
|
Hi Dave,
This might be some sort of version issue, because I tested it myself, first by putting radiobuttons directly onto the form, and after your reply, I tried it with a panel, and I get no checked radiobuttons whatsoever... I tested with VS.NET 2003, .net 1.1, on win XP.
Best Regards,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
I think you may be right. I did this in 2005 and got a checked RadioButton every time.
I'll make up the same exact project in 2003 and see what happens, then convert it to 2005 and see.
|
|
|
|
|
Confirmed it's a version issue.
Under 2003 and .NET 1.1, the RadioButtons do not pick a default selection. They ALL stay unselected with the default configuration.
Under 2005 and .NET 2.0, the first RadioButton gets selected automatically.
|
|
|
|
|
thanks john for replying,i go with u that what dave said is not true,but i guess u didnt understand my problem.
as u said ,radio buttons by default should be unselected,and that is not my case ,when loading my forms some of the radio buttons are checked eventhough i didnt yet make the selection,so i checked the 'checked' property and it is set to false,that what doesnt make sense. as for why not using checkboxes cuz i want to force the client to give 1 choice only.
so what can u advise me to do?
10x alot.
|
|
|
|
|
Why it is behaving like it is, I have no clue. You said it yourself however, the radiobutton's idea is to force the user to make a single choice. I understand from your message that you don't want to have a default choice though.
One possible solution to your dilemma could be to fake it: add an extra radiobutton to the groupbox or panel or whatever, make it the default selected one, and .Visible = False . As an additional advantage you can then also check this radiobutton's checkstate to see if the user remembered to make a choice.
Hope this helps,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
Hi all,
I am trying to extract messages from outlook express on a server and file them in a folder. - contact, subject and text
Does anyone know if this is possible or can direct me to a place where I can get help on this.
Many thanks in advance
|
|
|
|
|
Outlook exposes a COM interface so you can manipulate it - not sure about VB.NET but VBA (yuck) allows this very simply http://www.outlookcode.com/.
I am sure VB.NET allows you to use COM objects so look that up and you will be off to a good start.
Dan
|
|
|
|
|
i want to make crystal report in my windows form project,
i want a report on a table in sqlexpress database
but in the crystal report standard wizard , when i choose new connection ,
i choose OLE DB SQL server
i enter the server's name as "servername\sqlexpress"
and use windows authentication,
i got the following error:
Failed in logon
source: microsoft OLE DB provider for SQL server
Description: Invalid authorization specification
while i enabled all the protocols (via, tcp/ip, pipes,...) in the sql server
|
|
|
|
|
mostafaelfeky wrote: while i enabled all the protocols (via, tcp/ip, pipes,...) in the sql server
Well, you have to enable TCP/IP and remote connections, but you also have to enable Integrated Security.
Other than that, we'd have to see the connection string you're using.
|
|
|
|
|
I'm reading a series of images from a MS SQL table and saving them to directory. As part of the process, I'm resizing the image and changing its resolution from 96 to 72 ppi. The resizing works without a hitch, but I cannot figure out how to reduce the resolution. All of the output files continue to be 96 ppi. Any help would be greatly appreciated.
Here's the code
<snip...>
Dim bytImage() As Byte
bytImage = .ItemArray(4)
bytImage = ChangeImageResolution(bytImage, 72)
bytImage = ResizeImage(bytImage, 150)
Dim fs As New FileStream(strFileName, FileMode.OpenOrCreate, FileAccess.Write)
fs.Write(bytImage, 0, UBound(bytImage))
fs.Close()
fs = Nothing
<snip...>
Private Function ChangeImageResolution(ByVal bytInput As Byte(), ByVal intOutputResolution As Int16) As Byte()
Dim strmInput As New System.IO.MemoryStream(bytInput)
Dim strmOutput As New System.IO.MemoryStream
Dim imgInput As System.Drawing.Image
Dim imgOutput As System.Drawing.Image
Dim bmapTemp As Bitmap
' Create a temporary bitmap and set to output resolution
imgInput = System.Drawing.Image.FromStream(strmInput)
bmapTemp = imgInput
bmapTemp.SetResolution(intOutputResolution, intOutputResolution)
imgOutput = New Bitmap(bmapTemp)
imgOutput.Save(strmOutput, System.Drawing.Imaging.ImageFormat.Jpeg)
' Return the output image in a byte array
ChangeImageResolution = strmOutput.ToArray
End Function
Private Function ResizeImage(ByVal bytInput As Byte(), ByVal intFinalMaxDim As Int16) As Byte()
Dim strmInput As New System.IO.MemoryStream(bytInput)
Dim strmOutput As New System.IO.MemoryStream
Dim imgInput As System.Drawing.Image
Dim imgOutput As System.Drawing.Image
Dim intMaxDim As Int16 = 0
Dim intResizePercentage As Double = 0
Dim sizResize As New Size
' Determine the resizing percentage based on current image dimensions
imgInput = System.Drawing.Image.FromStream(strmInput)
If imgInput.Height >= imgInput.Width Then
intMaxDim = imgInput.Height
Else
intMaxDim = imgInput.Width
End If
intResizePercentage = (intFinalMaxDim / intMaxDim)
With sizResize
.Width = CInt(imgInput.Width * intResizePercentage)
.Height = CInt(imgInput.Height * intResizePercentage)
End With
' Create a new resized version of the image
imgOutput = New Bitmap(imgInput, sizResize.Width, sizResize.Height)
imgOutput.Save(strmOutput, System.Drawing.Imaging.ImageFormat.Jpeg)
' Return the output image in a byte array
ResizeImage = strmOutput.ToArray
End Function
|
|
|
|