|
Your welcome, glad you got it working now.
|
|
|
|
|
What environment are you using? If VB.NET, then you should have a lot of compiler errors anyway...
- You declare a workbook named "xlwbook" and refer to it as "xlbook"
- Declare your i integer inside the procedure
- You declared xl twice (7 instances of Excel running!). If you Dim xl as New Excel.Application that's enough. You shouldn't create a new instance of the Excel object every time your loop runs.
- In .NET you wouldn't need a conversion class. ExcelNword = CStr(i) is enough.
- You should also rather use good old Try... Catch instead of OnError
I gave it a test in VB.NET with then enclosed changed code. Good luck with your further experiments
Michael
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Dim xl As New Excel.Application
Dim xlwbook As Excel.Workbook
Dim ExcelFile As String
Dim ExcelPassword As String
Dim ExcelNword As String
Private Sub btnStart_Click() Handles btnStart.Click
xl.Visible = False
ExcelFile = "D:\" + "text.xls"
For i = 1 To 6
Try
ExcelNword = CStr(i)
ExcelPassword = "ABC" + ExcelNword
xlwbook = xl.Workbooks.Open(Filename:=ExcelFile, Password:=ExcelPassword)
MsgBox(String.Format("Workbook could be opened with password {0}", ExcelPassword))
Catch ex As Exception
If Err.Number = 1004 Then
MsgBox(String.Format("'{0}' is the wrong password!", ExcelPassword), , "Error")
Else
MsgBox(String.Format("Fehler {0}: {1}", Err.Number.ToString, Err.Description), , "Error")
End If
End Try
Next i
xl.Quit()
xlwbook = Nothing
xl = Nothing
End Sub
End Class
modified on Monday, May 17, 2010 7:06 AM
|
|
|
|
|
I'd say the problem in this code is that you don't increment the name of the file. You set it to "D:\Users\Test\Desktop" + "\test1.xls"
So, it would work the first time, but on the second iteration, it would be comparing the password for workbook 2 with workbook 1.
Did you mean to write:
ExcelFile = "D:\Users\Test\Desktop\test" & i &".xls"
|
|
|
|
|
I don't think he was wanting to increment the file name, but test a sequential number of passwords against the file to find the correct one.
Going by his other post in response to my code listing, the problem is now fixed, so he is a happy bunny.
Cheers,
|
|
|
|
|
Well if that's what he was trying to do, it sure wasn't clear. Why would you open it and if it didn't open, just display the error message? Why display a message at all if it didn't open? You only need to know the correct password, not the incorrect ones. That was very strange code to try to break a password.
|
|
|
|
|
agree, but he's happy!
|
|
|
|
|
Hey Guys,
to first: Sorry for my bad english !!
I have found nothing suitable, despite gegoogle. But maybe someone knows of you the problem.
I have run a VB.Net 3.5 - App with Interbase 6.1. As ADO driver do I use "Firebird ADO.NET Data provider for. NET and Mono 1.7" from
Sean Leyne. (This driver also works with Interbase.)
Now I wanted to switch to Firebird 2.1. The change in the database has
even if folded. All domains, triggers, etc. run from DB.
With my SQL-Console (IB-Expert) can also easily edit the database.
The Connection String is also true:
<Password = masterkey; Database = C: \ XYZ \ DB.FDB; Dialect = 3; User Id = SYSDBA; Data Source = localhost; charset = ISO8859_1>
<br />
...<br />
Public myDataConn As New FbConnection<br />
Public myDataConnString As New FbConnectionStringBuilder<br />
myDataConn.ConnectionString = "Password = masterkey; Database = C:\XYZ\DB.FDB; Dialect = 3; User ID = SYSDBA; Data Source = localhost; charset = ISO8859_1"<br />
myDataConn.Open()<br />
...<br />
But I get the Open() an error message that I do not
can understand .
Error message
"Offset and length of the array are out of range, or
the number is greater than the number of elements from index to end of
Source collection. "(Error Target: Void BlockCopy (System.Array, Int32,
System.Array, Int32, Int32)
With Interbase 6.1 is full working and no problems.
Does anyone know of the problem or you have a tip for the solution?
Thank you in advance for your help
Frank
|
|
|
|
|
You shouldn't post in more than one forum, it is bad form.
You will be answered quicker and better in Quick Answers as it is a specific question.
Thanks.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|
|
if im being honest never used firebird before but i always double check my connection strings on this site connection strings i've looked and they have a firebird section too
Marc Clifton wrote: That has nothing to do with VB. - Oh crap. I just defended VB!
|
|
|
|
|
Hi,everyone!I need some help about "find" in excel with vb.net.I want to find a text like "name" in each sheet's range(j5:l5),if it found "name" in such range,then exports data from range(J5:Q12) to other sheet.I don't know whether the function "find" could do this,or I need wrote function myself?
Please give me suggestion and help me !THX!
|
|
|
|
|
Try this[^] link. Might help.
|
|
|
|
|
Good Link
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|
|
hey guys..i want to make a vb.net program to let users control a machine arm to draw on a paper based on what he draw in the program form.
basically i want to design a control form with small dots on it(grid)
and every dot represent a coordiantion point of my machine
and a drawing function provide to user to draw anything on the dots,after that the machine can move to specified location based on the dots being link/draw by user.
so first..how can i make small dots on a vb.net form?
second...how can i provide a control button for user to draw line or input text on that form?do i need shape powerpack or something??
third...how can i detect the dots(which represent the coordinates) that had been link/draw by users?
|
|
|
|
|
If you are a beginner then this as a starting project is way too much.
I would suggest you start by searching the CodeProject articles relating to vb.net graphics winforms.
|
|
|
|
|
ok maybe i redim my question.
i know how to draw line and other shape by using code or just on the form.
but i can only provide the drawing function to user by means of point input(means users have to type in the shape points ).
but now i wan to know how to make a function for user to draw without input the points,they can just draw anything they want on the form just like wat we do in the window paint program.i had search the forum but no luck to me...
thx for the reply....
|
|
|
|
|
|
wao...thx so much!!!
i think i can solve the text and shape input problem now.
just another question..
lets say if user alredi draw on the form..
after he finish his drawing..how can i detect on which coordinations he draw on?
(for example:user draw a line at start point(1,1) to (10,10)..is that a way to detect the coordinations of the line where it pass through(smallest coordiantion is 1)??)
|
|
|
|
|
i can only found the starting point and end point...
anyway to get the whole coordination points??
|
|
|
|
|
yes, start with something simpler. And I would suggest you buy and study a book on VB.NET; it will teach you a lot you need, a lot you don't even know you need, and some good practices.
And to draw a dot, you probably want Graphics.DrawEllipse() .
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hi,
I have a program converted to VB.NET 2005 from VB6.
I uses control arrays extensively.
I am having a problem the the dtpicker control (AxMSComCtl2.AxPickter)
I frequently get 'not legal oledate' and other errors when accessing the control (reading or writing). We have controls just for short date and time i.e.
dtpFromLast and dtpFromLastTime
using
s = cstr(frm.dtpFromLast).value
or _value
or
frm.dtpFromLast.value = today
or
frm.dtpFromLast.time = now
Sometimes it works sometimes not.
The form in question is not always in focus and may not be visible (sometimes fails even when visible). It is a settings screen and not the screen where the work is being done.
Please just do not tell me to use another control as the windows date time control without some background explanation.
Thanks
modified on Monday, May 17, 2010 3:32 PM
|
|
|
|
|
By the sound of it, you are using a third party date time picker, are you, or is AxMSComCtl2.AxPickter simply what you named it?
If it is .Net's regular DateTimePicker control. Without seeing more specific code, I would guess the problem can be found in the conversion from a date value to a string value and back. Especially converting a string to a date value is always risky.
You could try the following things:
1. enclose the relevant code in Try Catch blocks with MsgBox(ex.ToString), and/or set a break point and walk through the code line by line, to see what value is actually being passed to whatever it is that is expecting a datetime value. You may see yyyy/MM/dd in your GUI, but the code may try to pass yyyy/dd/MM (for example)
2. do not use cstr(frm.dtpFromLast.value) , but rather frm.dtpFromLast.value.ToShortDate .
3. look into IFormatProvider. (Example: Public Finn As IFormatProvider = New Globalization.CultureInfo("fi-FI") ). Your Windows regional settings determine the format of the date in your dtp control (yyyy/MM/dd or dd-MM-yyyy or yyyy/dd/MM, etc.). When you convert it to string, and then back to a date, it may not necessarily translate correctly.
4. "oledate" suggests that this app is sending these dates to a database. Databases are notoriously sensitive to all kinds of date format problems. You may have to check what format your database is expecting, and form your date accordingly. Also sticking with pure datetime values, instead of converting to string and back, will prevent a lot, if not all, of your problems.
5. If you insist on converting dates to strings and back, use frm.dtpFromLast.value.ToShortDate and cDate(frm.dtpFromLast.value.ToShortDate).Date
My advice is free, and you may get what you paid for.
|
|
|
|
|
Thanks Johan
It is NOT a 3rd party control. It is in VB.NET 2005. Part of VB6 compatibility I believe.
The tostring will not work. I have tried that in Immediate mode.
These settings are written to a file which is why strings a being used.
The control is not linked to a database.
Since the code sometimes works sometimes not putting the code in would not be very helpful but here is some that fails.
With frmWebDownLoad
.dtpFromLastTime(0)._Value = CDate(Ss)
or
.dtpFromLastTime(0).Value = CDate(Ss)
end with
.
.
.
frmWebDownLoad.dtpFromLast(ThisStoreNdx)._Value = Today
Even doing a Add Watch shows has it Not a legal date in the watch window.
We are in the US so using mm/dd/yyyy.
But the problem occurs on the time control .dtpFromLastTime(0) (Format=Time) also when doing
.dtpFromLastTime(0).Value = cdate("00:00:00")
I believe it has more to do with the form that it is in and the form life cycle but just don't have enough to go on.
And it does not always fail.
I will try to get more info.
|
|
|
|
|
Everything you have told me so far (also in your additional post), makes me suspect something. In old VB6 cross form actions were simple, but .NET uses threads in a totally different way. Am I correct in my suspicion that the Ss string has been declared in either form's code ? If so, you could try the Global module method. In other words, add a module to your project and move the Ss string (and all other similar ones) here, and remember to make it Public.
Also, again, as this error only happens some of the time, I suggest that you put your code in a Try Catch block, with MsgBox(Ss) in the Catch. Then try to recreate the problem by testing with ambiguous dates like for example 10/13/2009. And, again, look into cultureinfo, it will solve a lot of headaches with things like PM and AM and such. This link[^] will come in handy.
Another method to ensure correct values, which takes a little more coding, is to use the dtpFromLastTime.Value.Day / .Month / .Year / .Minutes / .etc properties. With these you can more securely parse the date into the string for your settings.
As for the time issue, I seem to remember having had similar problems once. I found that adding a date (any date) solved it all, as sometimes, for reasons unknown to me, a string like "00:00:00" will get parsed into an impossible date instead of into a time.
Finally, if you need to save settings in a Windows forms app, I warmly suggest to switch to .NET's built in settings handling. They are laughably easy to use (see this article[^] on how easy. Added bonus, you can actually save dates, fonts, colors, and pretty much all other types, instead of only strings.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Ss is a local variable (Dim Ss as string)
But I do not understand your point. Why would having Ss be a public variable make any difference. I would believe it has something more with the forms and that if it goes through form.terminating (and we do a c.cancel=true:hide) it fails but a plan hide does not.
EACH function or sub has a Dim Ss as string. These are work strings that are used and cannot be made global.
Again, "00:00:00" sometimes works sometimes not depending on the 'state' of the form in which the dtPicker is located.
Changing to the .Net settings handling would be a major change.
The program has about 15 forms and 20 modules with hundreds of functions and subs. Each form has entries in an ini file that are in exact relations to a control on the form. 1 ReadIni and 1 SaveIni work for all the forms.
|
|
|
|
|
QBTeKcom wrote: These are work strings that are used and cannot be made global
Yes they can, and they should be.
This e.Cancel, hide trick you are using is bad news. I am surprised that you are not being flooded with all kinds of errors, sending values directly from form to form.
Trust me, you can either pull out your hair for the remainder of this project, or spend one or two hours to bring this old vb6 code a little bit up to .net standards.
Create a global module, move all your Ss strings there, renaming them of course to something like Ss_Form1, Ss_Form2, etc. Then when a date is altered on a form, store this value in the relevant public string, and just let the form be closed after that. If nothing else, you are really putting a burden on memory, by keeping a whole form alive, just to make sure that a single value can be accessed from elsewhere. If you have any other such variables that are used across forms, I warmly recommend moving them to the same global module as well.
As for porting the settings system from an ini file to .net's setting solution, .net uses an xml file to store all settings, and you can even determine the type (string, integer, date, etc). These settings are then directly available in the intellisense of your editor (My.Settings.SomeSettingName ). This will speed up future development, and cut down on lines of code looking for the correct text in the ini file, and validating / parsing it.
Just as a suggestion, you could create a single dummy setting, then take a look at the xml file (it will be called app.config in your project explorer tree), and just write a little program to convert the ini file to an xml one (you might even be able to do it quick and dirty with Excel).
My advice is free, and you may get what you paid for.
|
|
|
|
|