|
Ok, what do you need help with? We will not do your homework for you, you need to show some effort. We can help with specific pieces, but we aren't going to do the whole thing.
|
|
|
|
|
its work i already.
click here to see the result[^]
Public Class FrmDisplay
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub FrmDisplay_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.WindowState = FormWindowState.Maximized
End Sub
Private Sub BtnDisplayWord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDisplayWord.Click
Dim words() As String = IO.File.ReadAllLines("words.txt")
Dim query = From word In words
Order By VowelCount(word) Descending, word.Length Descending, word Ascending
Select VowelCount(word) & " " & word
For Each word In Words
ListResults.DataSource = query.ToList
Next
End Sub
Private Sub BtnRetour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnRetour.Click
Me.Hide()
frmMain.Show()
End Sub
End Class
|
|
|
|
|
And? You stated the homework assignment, something you are expected to do.
You then posted your code.
So.... is there a question here? Or are you simply asking people to review/comment on what you've done?
|
|
|
|
|
I am simply asking people to review my code
|
|
|
|
|
Your VowelCount method isn't present in that class. We can't comment on it if we can't see it.
|
|
|
|
|
i post my code and the subject, i just want somebody help to check if its correct.
|
|
|
|
|
You haven't posted all your code though. As I pointed out, you are missing your VowelCount method in the code. How can we review it if we can't see it?
|
|
|
|
|
Caveat: I'm not a trained programmer. Self-taught to accomplish particular tasks.
OS: Windows 7
.NET version: 3.5
VS version: 2008
Key references: Microsoft Excel 14.0 Object Library, Microsoft Office 14.0 Object Library, Microsoft Visual Basic for Applications Extensibility 5.3
I wrote a program a couple of years ago that takes text files full of numbers (data files from behavioral research projects), transforms the data in particular ways, and displays the results on a form in both text boxes and charts (Microsoft Chart Control). In addition, I have it so that I can click on a button, select what parameters I want to save, and the program will dump all of the transformed data into an Excel workbook (full of several worksheets). The user can select whether to keep Excel open or have Excel open in the background long enough to create and save the file.
Program works great on my office computer (Windows 7, Excel 2010). I now want it to work on a second computer in my research lab (Windows 7, Excel 2013). To accomplish this, I moved only two files: my compiled .exe and a .dll required by the program that has nothing to do with the Excel problem.
When I run the program on this second machine, every function works fine until I go to dump the data to Excel. Then I get an unhandled exception message:
"
System.Runtime.InteropServices.COMException (0x800A03EC): A workbook must contain at least one visible worksheet.
To hide, delete, or move the selected sheet(s), you must first insert a new sheet or unhide a sheet that is already hidden. "
Now, because I generally just write programs for my own use, I know very little about how to distribute them, so this problem may be completely due to my failure to move some file to this new machine.
But the error seems to indicate that Excel 2013 works differently than 2010 (i.e., that I should have programmatically set some visible property for new Excel). I don't want to have 2 versions of my program just to work with 2 versions of Excel. (It's not possible for me to downgrade to 2010 on the new machine because our IT dept. will want to re-image the machine which is a big headache for other reasons.)
I can post code later if need be; for now I just was hoping someone familiar with working with different versions of Excel could steer me in the right direction before I get too deep into it. I don't know if I should be going first to the code, first to Excel (I've not used 2013 at all), or first to making sure all of my files are correctly copied. Perhaps I should be creating a setup package rather than just trying to copy files?
**One other note. I have a different program that saves a report in Word, and this program has worked fine on the machine with Word 2013 as on the machine with Word 2010 (and it was programmed back when it was 2007). Apparently that time, though, I made a setup file for this. Maybe not doing that this time was the mistake? (When I make setup files, I have very little idea what I'm doing.)
|
|
|
|
|
Quote: I moved only two files: my compiled .exe and a .dll required by the program that has nothing to do with the Excel problem I suspect that you need to copy the two following files as well from your original program location.
Interop.Microsoft.Office.Core.dll
Interop.Microsoft.Office.Interop.Excel.dll
|
|
|
|
|
Thank you for this suggestion. I would appreciate a little handholding here.
I cannot find these files. I know they are found in the GAC, but the GAC folder appears in such a way that I cannot simply copy these dlls. I guess I had assumed that since these were in the GAC, I wouldn't have to move the DLLs at all (both machines have .NET 3.5).
I have been working out of my debug/bin folder on the working machine; I've never set up a "published" version. If I do that, will these .dlls appear in my program directory?
|
|
|
|
|
I must apologize for sending you down the wrong path.
When I wrote that, it did not even occur to me that you had the Office Primary Interop Assemblies (PIA) installed in the GAC. You would have gotten a reference not found or something like that if they were missing.
The error message is pretty clear about the circumstances; at some point your code must be trying to delete/hide the last visible worksheet. This is easy to reproduce by calling the Delete method on the Workbook.WorkSheets object.
You need to inspect your code and find what causes this condition to occur.
As to why does it work fine on your development machine, but not on another? This is hard to say without seeing your code, but perhaps you are deleting the default WorkSheets (Sheet1 thru Sheet3) as some type of cleanup in your code and no other visible worksheets were added prior to this action on the subject installation.
Edit: corrected typo's
modified 10-Jan-14 17:16pm.
|
|
|
|
|
Thank you and now I think I know what I have to do.
For a long time, starting a new workbook in Excel caused the creation of 3 blank worksheets. As you guessed, my code starts by deleting 2 of these blank sheets as part of a pre-cleanup, before it added the variable number of sheets the user needs.
Excel 2013 apparently starts you off with only 1 blank sheet. Thus, either when I try and delete a non-existent sheet, or when my program assumes 1 sheet exists when it doesn't, I get the error.
So I will programmatically count the number of active sheets before I do any clean up, and this should give me a program that behaves regardless of the Excel version.
Thank you for focusing me on the right thing. (Fingers crossed.)
|
|
|
|
|
Thank you TnTinMn. I can now report this problem is solved. Indeed, I had a loop to remove 2 blank worksheets; I rewrote the loop to count the number of worksheets (would be 3 for older versions of excel, 1 for newer), to subtract 1 from this count, and to loop from 1 to this count deleting worksheets. In practice, this loops from 1 to 2 for older excel (how I had it hard-coded) and 1 to 0 in new excel. Should have done that in the first place!
--Steve
|
|
|
|
|
good day everyone i need help to my project i'm newbie in programming.
i want to make an file downloader using visual basic 2012.
i have a code for file downloader but i need some button to add.
i only have download button1 for (download)to download file.
now i need to add another button2 for (cancel) to stop the download file.
here's the code
Imports System.Net
Public Class Form1
Private Sub downloadFile(ByVal srcPath As String, ByVal destPath As String)
Dim wClient As New System.Net.WebClient()
AddHandler wClient.DownloadProgressChanged, AddressOf downloadFile_ProgressChanged
wClient.DownloadFileAsync(New System.Uri(srcPath), destPath)
End Sub
Private Sub downloadFile_ProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
ProgressBar1.Maximum = e.TotalBytesToReceive
ProgressBar1.Value = e.BytesReceived
Label7.Text = e.ProgressPercentage.ToString + "%"
Application.DoEvents()
If e.ProgressPercentage = 100 Then
Label5.Text = "Download Complete :"
DownloadBtn1.Enabled = True
End If
end sub
Private Sub DownloadBtn1_Click(sender As Object, e As EventArgs) Handles DownloadBtn1.Click
If Pm1.SelectedItem = ("item") Then
downloadFile("http://", "Location")
ProgressBar1.Visible = True
Label5.Visible = True
Label7.Visible = True
DownloadBtn1.Enabled = False
End If
end Sub
end class
anybody can edit the code for me
thaks.
|
|
|
|
|
Have you seen the WebClient.CancelAsync() method??
In your case you would just drop a button on the form and in the Click event handler put:
wClient.CancelAsync()
Nobody is going to edit your code for you. Nobody is doing it for us, so why would we do it for anyone else??
|
|
|
|
|
Hi friends,
I have a question. In form, If we maximize the form, if all the controls in the form is to be centered, we give ANCHOR->NONE to all the controls. But, If I gave ANCHOR->NONE to any one of the controls, it should affect others also.. How can I acheive this??
|
|
|
|
|
Since no control knows about the existence of any other (exactly the way it should be!), you can't do that.
You'd have to write a method that sets/unsets the Anchor property of all your controls by iterating through all the affected controls and setting each control individually.
|
|
|
|
|
Im trying to get this if then statement to work, but I'm new to VB and programming in general and I'mnot sure what's wrong, or even if this is the best way to do what i want to do. I see there is a select case method, but I'm not sure the best way to do this. Thanks in advance. When strOwnerCode = "M", my strTitle is not getting populated correctly. I'm not sure where my flaw is(probably my whole statement).
strOwnerCode=sess0.screen.GetString(10, 78, 01)
If strOwnerCode = "C" then
sess0.screen.sendkeys("<PF2>")
strTitle=sess0.screen.GetString(10, 13, 01)’ check the code for officer title
if strTitle = "S" then
strTitle = "Secretary"
elseif strTitle = "P" then
strTitle = "President"
elseif strTitle = "T" then
strTitle = "Treasurer"
elseif strTitle = "V" then
strTitle = "Vice President"
end if
elseIf strOwnerCode = "D" then
sess0.screen.sendkeys("<PF2>")
strTitle=sess0.screen.GetString(10, 13, 01)’ check the code for officer title
if strTitle = "M" then
strTitle = "Member"
elseif strTitle = "G" then
strTitle = "Manager"
end if
elseif strOwnerCode = "M" then
sess0.screen.sendkeys("<PF2>")
strTitle=sess0.screen.GetString(10, 13, 01)’ check the code for officer title
if strTitle = "M" then
strTitle = "Owner Receiving Mail"
elseif strTitle = "O" then
strTitle = "Et Al"
end if
elseif strOwnerCode = "S" then
strTitle = "Owner"
end if
modified 7-Jan-14 18:21pm.
|
|
|
|
|
I'd suggest to remove the if-elseif-series and use a Select Case statement instead (see e.g. http://msdn.microsoft.com/en-us/library/cy37t14y.aspx[^]).
Furthermore, you should consider the possibility that none of your cases was found - in the if-elseif world, that means another else clause (without an if); with select-case, it is the Case Else clause.
|
|
|
|
|
Ok, thanks for the suggestion, I'll go ahead and do that.
|
|
|
|
|
Bear in mind that string comparisons are by default case sensitive so always convert both side of the comparison to upper or lowercase(ToUpper or ToLower).
If an "m" comes through your comparison will return a false with your current code.
Clickety for how I messed up on this[^]
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
I'm writing this for attachmate, and our interface only uses uppercase. But that is definetley a good suggestion to keep in mind.
|
|
|
|
|
Hi all,
My MySQL table structure is ...
(I am giving you from SQL Query)
DROP TABLE IF EXISTS `expenditure`;
CREATE TABLE IF NOT EXISTS `expenditure` (
`ExpId` int(11) NOT NULL AUTO_INCREMENT,
`ExpDate` date DEFAULT NULL,
`ExpPurpose` varchar(350) DEFAULT NULL,
`ExpRefNo` varchar(50) DEFAULT NULL,
`Expenditure` double(10,2) DEFAULT '0.00',
`ExpFlag` char(10) DEFAULT NULL,
PRIMARY KEY (`ExpId`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;
;
INSERT INTO `expenditure` (`ExpId`,`ExpDate`,`ExpPurpose`,`ExpRefNo`,`Expenditure`,`ExpFlag`) VALUES
(1,'2014-01-06','Purchase','ttyu76',15750,'P');
;
My Code is...
Private Sub Generate()
Dim DateFrom As Date = Convert.ToDateTime(DtpFrom.Value).ToString("yyyy-MM-dd")
Dim DateTo As Date = Convert.ToDateTime(DtpTo.Value).ToString("yyyy-MM-dd")
Try
OpenConnection()
Dim sb As New StringBuilder
sb.Append("SELECT ExpDate,ExpPurpose,Expenditure FROM expenditure WHERE ExpDate BETWEEN '" & DateFrom & "' AND '" & DateTo & "'")
Dim dbcommand As New MySqlCommand
Dim dbadapter As New MySqlDataAdapter
Dim stdata As New DataTable
dbcommand.Connection = conn
dbcommand.CommandText = sb.ToString
dbadapter.SelectCommand = dbcommand
dbadapter.Fill(stdata)
DgvExp.DataSource = stdata
Catch ex As Exception
MsgBox(ex.Message)
Finally
CloseConnection()
End Try
End Sub
After the execution of the code, my Datagridview is not displaying any Data.
What is wrong ?
|
|
|
|
|
Your query didn't return anything, so the datatable is empty and, therefore, your grid.
Do NOT user string concatenation to build your query, especially with dates. Google for, and use, "vb.net MySQL parameterized queries".
|
|
|
|
|
Try changing this:
Dim sb As New StringBuilder
sb.Append("SELECT ExpDate,ExpPurpose,Expenditure FROM expenditure WHERE ExpDate BETWEEN '" & DateFrom & "' AND '" & DateTo & "'")
Dim dbcommand As New MySqlCommand
Dim dbadapter As New MySqlDataAdapter
Dim stdata As New DataTable
dbcommand.Connection = conn
dbcommand.CommandText = sb.ToString
dbadapter.SelectCommand = dbcommand
To this:
String sb = "SELECT ExpDate,ExpPurpose,Expenditure FROM expenditure WHERE ExpDate BETWEEN @StartDate AND @EndDate")
Dim dbcommand As New MySqlCommand
Dim dbadapter As New MySqlDataAdapter
Dim stdata As New DataTable
dbcommand.Connection = conn
dbcommand.CommandText = sb;
dbcommand.Parameters.AddWithValue("@StartDate", DateFrom)
dbcommand.Parameters.AddWithValue("@EndDate", DateTo)
dbadapter.SelectCommand = dbcommand
The problem is that the date strings are not properly formatted to return the right data in your SQL, since you are using the default ToString method instead of an actual format like yyyy-MM-dd. Using parameters will force the underlying data adapter to insert the correct strings for the values without you having to worry about formatting them. Additionally, this is preferred to avoid SQL injection attacks and cleaner code.
|
|
|
|
|