|
Hi,
If you want to add a icon to a menu item simply put the MenuStrip component on the form, and click where it says "Type here", type something, and then go to the properties window and click the part that says "Image", or you could use this code: FileToolStripMenuItem.Image(ImageName or path goes here) you will have to change the names accordingly.
Hope it was useful.
Lloyd A.
Lloyd J. Atkinson
"Logic will get you from A to B, but imagination will take you everywhere" -ALbert Einstein
|
|
|
|
|
Iam just begining of proggraming
I wan Study vb2005 proggraming
But I so Confiuse from where I must strart!
and If you have e-book pleace give me!
Thanks So much to you ALLS!
|
|
|
|
|
First step - buy a beginners book. A paper one. One you pay for, instead of stealing it ( most 'e-books' are not free ). Work through that, first.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Ok, this one is driving me nuts, can someone tell me what I am doing wrong?
I have a few MDI child forms open within a parent.
I need to run a sub on one of the child forms when an event occurs on another.
For example one of the child forms is created in the Load event of the MDIParent with the following:
Dim ChildForm2 As New GraphFrm<br />
ChildForm2.MdiPrent = Me<br />
ChildForm2.Show()
The GraphFrm contains a Sub UpdageGraphs() but when I attempt to call ChildForm2.UpdateGraphs() from the parent or any of the other MDI child forms I get an error that ChildForm2 is not declaired.
How do I make this instance of the child form accessible to the Parent and other child forms?
David Wilkes
|
|
|
|
|
Use delegates to call methods between forms.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks for the suggestion.
I am still not completely clear on how to accomplish this.
I am guessing I would have to define the delegate in the parent but not entirely sure when to assign the address of the function to the delegate.
David Wilkes
|
|
|
|
|
Paul you helped me complete the mission using the excel spreadsheet as a linked server and a single sql query run on the sql server but I would like to know how to do this in VB now too. I feel I need to be able to do things like this in VB quickly and easily and I'm just not there yet. I'm hoping someone can help me understand how this can be done in VB.
I've loaded the excel spreadsheet via oledb into a datatable. Every record in this sheet needs name and address info added to it (the fields are there but are blank). I'm looping through the datatable and looking up required data in a sql server database. I need some help reading in the values returned by the query. I assume I have only 3 options ExecuteReader to return a DataReader object, ExecuteScalar to return a single value, and ExecuteNonQuery which returns nothing. I've never worked with ExecuteReader before. Is this the simpliest way to retrieve a couple pieces of data from a database query? See code below.
If MyOpenFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim filename As String = MyOpenFileDialog.FileName
Dim myExcelDt As New System.Data.DataTable
Dim myExcelConnection As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & filename & "; Extended Properties=""Excel 8.0""")
Dim myExcelSqlCommand As String = "SELECT * FROM [all ANIs$]"
Dim myExcelAdapter = New System.Data.OleDb.OleDbDataAdapter(myExcelSqlCommand, myExcelConnection)
myExcelAdapter.fill(myExcelDt)
Dim mySqlDt As New System.Data.DataTable
Dim Sql2000Connection As New System.Data.SqlClient.SqlConnection(Sql2000ConnectionString)
Dim Sql2000Command As New SqlClient.SqlCommand
Sql2000Command.Connection = Sql2000Connection
For Each excelrow As DataRow In myExcelDt.Rows
Sql2000Command.CommandText = "select fullname, address, city, state, zip from addresslist where phone = '" & excelrow("phone") & "'"
**** need help here ****
Next
End If
|
|
|
|
|
Hi there.
The syntax for retrieving data using a DataReader would be something like this:
For Each excelrow As DataRow In myExcelDt.Rows
Sql2000Command.CommandText = "select fullname, address, city, state, zip from addresslist where phone = '" & excelrow("phone") & "'"
Using reader As SqlDataReader = Sql2000Command.ExecuteReader()
While reader.Read()
Dim fullname As String = reader.GetString(0)
Dim address As String = reader.GetString(1)
' And so on...
End While
End Using
Next
As an aside, what are you trying to achieve with your code? Do you want to check whether a phone number in the Excel file is valid? If so, it would be better to write a stored procedure that takes a phone number as a parameter, does a lookup on the addresslist table to check whether the phone number exists and returns a boolean value indicating whether it is valid. This method is more efficient than doing the validation in your VB code.
One other thing. Whilst it is nice to be asked personally for help, it is probably better to address questions generally to the forum rather than to specific people. I have to fit my CodeProject excursions round a day job/commute and I may not be able to answer a question.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Thanks for the code. I'll play with it.
The object of yesterdays question was to add the name and address associated with each of the phone numbers in that excel spreadsheet to the spreadsheet for our accountant.
The object now is for me to know how to retrieve, update and otherwise manipulate data in ways I think I'll need to use in the future. I can only imagine I'll be asked many times in the future to get, update, add or delete data from a table or most likely multiple tables and I'll have to use VB. I just don't feel as ready to do that as I could in say Visual FoxPro. It's surprising when something like this comes up and I'm thinking hey I really haven't done that before. My VB database access to date has been with stored procedures and most of my heavy database work has been in Visual FoxPro as so, so, so much of our data is in VFP tables. But times are a-changing and we want to move away from VFP when and if we can. I'm already supposed to be writing a web service to lookup customer data. This customer data will come from multiple, you guessed it, VFP databases. So I'm learning all I can about accessing databases from VB using OleDb and Sql connections. Frankly I think my intimate knowledge of old dbase type databases and their access methods is preventing me from grasping how this is done in VB. It seems so much more complicated and inflexible.
So I'm wondering what if the results of the query contain more than one record? Will this ExecuteReader accept that? I'll start playing with it and see what I can figure out. Thanks for responding again.
P.S. I didn't mean to address the question to you personally I just didn't want you to see it and say, that's the same thing I helped him with yesterday.
|
|
|
|
|
JABOSL wrote: So I'm wondering what if the results of the query contain more than one record? Will this ExecuteReader accept that?
ExecuteReader returns a DataReader object, which provides a fast, forward-only means of reading data. As my example demonstrates, you typically use a While...End While loop to traverse the contents of a DataReader, calling its Read() method to advance the DataReader to the next record.
The new LINQ[^] stuff in .NET 3.0 may be of interest to you. It provides a more intuitive means of manipulating data from within your .NET code, especially if you are coming from a 4GL background.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Yes, I understand the while end while now. Somehow I was thinking that was to get each of the fields and not each row as I know there will only be one row the need for a while loop hadn't crossed my mind until after I read the code but it popped in as I though about the future so I added it into my response to you. I'm interested in .net 3.0 but that opens another line of questions. How do I go about using it in VB2005? I'm pretty sure I can but...
|
|
|
|
|
If you know that only 1 row of data will be returned, you don't need to use a While loop. You still need to call the Read() method to move the record pointer to the first row.
LINQ isn't available in VS2005. It is available in the Beta 2 of VS2008 though. You can download it for free from MSDN[^] if you are interested in playing with this new technology.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
I'm pretty sure they wouldn't support me going to 2008 quite yet around here. Can I install 2008 on the same pc as 2005 and 2003 and not affect them? I have some program in 2003 and some in 2005. For any major changes to a 2003 program I move it to 2005.
|
|
|
|
|
The version of VS2008 which is currently available is still only a beta release. I would wait until the full release comes out before you consider moving over to it completely. However, there shouldn't be any problem installing it side-by-side with VS2005 and using it for evaluation purposes.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
It seems like my VB Apps from time to time run into a problem where a file is being accessed at the same time I try to delete it or open it. I get an error like this:
The process cannot access the file "\\Server\Files\1556401.txt" because it is being used by another process.
How can I check if a file is being accessed and is there a way to see by who?
Any suggestions would be helpful.
Lost in the vast sea of .NET
|
|
|
|
|
There is an app called 'wholockme' that will tell you what process is locking a file, so it must be possible. The only way I know to check is to do your file access in a try/catch, but if you could work out how to tell who has the lock, that would obvioulsy tell you.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
FYI:
if you want write or delete access (anything other than read access) to a file
that just got created (by yourself or someone else, does not matter),
chances are you will find the file is being accessed by some other process,
and your access is not granted.
The other process very likely is some server code that is there to assist you
somehow. Candidates are:
- anti-virus software (Norton, McAfee, whatever)
- indexing software (Google Desktop, MS Office, whatever)
The common thing is these packages are looking all the time for new files, so
they can inspect them.
Microsoft is aware of the consequences; Windows Explorer will try rename and
delete attempts up to five times (with one-second interval), and only reports
failure if the action continues to fail for that time.
The solution:
1. either use a different file name
2. or remove all background reader candidates (bad idea)
3. or implement the retry loop as Explorer has it (use a Windows.Forms.Timer
for this)
BTW: if all you need is Read, make sure to allow others to read as well, i.e.
use File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thanks to both of you for your replies. I had the logic in a try catch, but it was a fairly wide open section of code. I narrowed down the code to several try catch sections and did exactly what Luc suggested as solution #3. I setup logic to retry the delete up to 6 times with a delay of 20 seconds between, and it worked.
The application I was having trouble with, has been in production working flawlessly for two years. It takes report spoolfiles off of our miniframe and translates them into PDF for delivery via e-mail or posting on our intranet. The problem came into light when my boss tried to put a 4000 page financial report which was 35MB in size through the application. It worked and sent a 7MB PDF to him via e-mail, but errored out when it tried to delete the original data / report file.
Thanks for your help! It's working flawlessly again.
Lost in the vast sea of .NET
|
|
|
|
|
Hello
Im using a background image on my form, and some pictureboxes that are used as buttons.
I load some other forms from the main form with the same setup(background picture+pictureboxes)
I takes quite a while to load this images.
Is there a way i can preload the images, or speed up the image loading?
Thank you
|
|
|
|
|
Hi,
if the images are much larger than what you need (hence the PictureBoxes will scale them
down), you could create smaller or even correctly sized images once and store them either
in separate files, or as resources in your exe/dll. This would, for each form, save both
the time to load the larger images, and the time to scale them down.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Already doing that
More ideas?
|
|
|
|
|
OK, time to get more specific. I'm looking for something (slightly) unusual:
What is your hardware? modern CPU, RAM size, disk speed?
what about your form(s): size, number of PictureBoxes, number of other Controls?
what is the size of the image files on disk? and in pixels? which format?
SiXke wrote: I takes quite a while to load this images
like how long? 100msec, 1sec, 10sec?
anything special about your code? extra events, extra logging?
network involved? database involved?
as a reference, you could maximize, then minimize, then measure the restore time;
and possibly show the Resize and/or Paint handlers involved.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Luc Pattyn wrote: What is your hardware? modern CPU, RAM size, disk speed?
4000+ / 2GB RAM / Raptor 10.000rpm
Luc Pattyn wrote: what about your form(s): size, number of PictureBoxes, number of other Controls?
Form size: 1920*1080 - 4 Picture boxes - No other controls
Luc Pattyn wrote: what is the size of the image files on disk? and in pixels? which format?
Background image: 1920*1080(97Kb) Pictureboxes: 300*300 (x4)(50-60Kb) all JPEG
Luc Pattyn wrote: like how long? 100msec, 1sec, 10sec?
Say like 1 sec, for example, when the form opens, i see the background, and a sec later the pictureboxes.
Luc Pattyn wrote: anything special about your code? extra events, extra logging?
nothing, simple FrmSub.show on the pictureboxes
Luc Pattyn wrote: network involved? database involved?
no network, access database used in the program, but has nothing to do with the pictures, and is not loaded during form load.
Luc Pattyn wrote: and possibly show the Resize and/or Paint handlers involved.
where can i find this?
Thnak you for your help man.
Do you think it would help to change from JPEG to GIF? (Pictures have max 10 different colors)
|
|
|
|
|
Hi,
it all sounds very reasonable.
and 1 sec is not too bad either.
SiXke wrote: where can i find this?
If you don't know, you don't have them, and they can't be a problem...
Here are a couple of things you could try:
1. a simpler image format for the pictureboxes, such as GIF.
2. embedding the images in the app itself, as resources.
3. set Form.DoubleBuffered true; that will not really solve much but it may change the look and
feel in the way you prefer (I expect it to show the form a bit later but with less activity!).
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Luc Pattyn wrote: 3. set Form.DoubleBuffered true; that will not really solve much but it may change the look and
feel in the way you prefer (I expect it to show the form a bit later but with less activity!).
Just what i needed.
Thx man
|
|
|
|
|