|
hi all,
anyone help me?
i have generated menus at run time.Now i want to disply reports on each menu.But i can't get index value of menu.I have created one click event for the menu but how i can identify the index of menu which is clicked.plz help me.
poonam
|
|
|
|
|
I am still confused on what you are trying to accomplish. Are you wanting an index value to determine what report to print? By the way, every control has a Tag variable. You could set integer values in the tag to differentiate betten the menu items.
Cheers!
Richard
may your code be error free.
(okay, maybe two lines.)
|
|
|
|
|
Hi Richard
Hw can i set tag value,Becoz my menus are generating at run time.Thats why i have created event handler.If i don't know which menu is clicked runtime then hw i can show the reports.I need a code which will store index value of a menu which is clicked.
by the way thanks for reply
poonam
|
|
|
|
|
Please post the code of how the menus are dynamically generated.
may your code be error free.
(okay, maybe two lines.)
|
|
|
|
|
[code]
Dim mShowMenuItem As System.Windows.Forms.MenuItem
mShowMenuItem = DirectCast(sender, System.Windows.Forms.MenuItem)
mShowMenuItem.MenuItems.Clear()
Dim n, i As Integer
Dim a, b As String
s = "Select srno from cash"
com = New OleDbCommand(s, con)
con.Open()
dr = com.ExecuteReader
While dr.Read
n = dr(0)
End While
con.Close()
For i = 1 To n
s = "Select account from cash"
com = New OleDbCommand(s, con)
con.Open()
dr = com.ExecuteReader
While dr.Read()
a = dr(0)
Dim mSubSubMenuItem As System.Windows.Forms.MenuItem
mSubSubMenuItem = New System.Windows.Forms.MenuItem
mSubSubMenuItem.Index = i
mSubSubMenuItem.Text = a
mSubSubMenuItem.Enabled = True
mSubSubMenuItem.Visible = True
AddHandler mSubSubMenuItem.Click, AddressOf MenuClickHandler
mShowMenuItem.MenuItems.Add(mSubSubMenuItem)
i = i + 1
End While
con.Close()
Next
this will generate menus
Public Sub MenuClickHandler(ByVal Sender As Object, ByVal e As System.EventArgs)
'Don't know wt to write here
End Sub
poonam
|
|
|
|
|
I'm playing around with the above method and I'm trying to calculate and display the difference between two dates. I'm getting the error "Value of type 'system.timespan' cannot be converted to 'string'". Can someone provide some guidance. Thanks. The following is my code.
Dim dateadd, datesubtract As System.DateTime
Dim datedifference As System.TimeSpan
Dim Date1 As System.DateTime = System.DateTime.ParseExact("20051127", "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture)
Dim Date2 As System.DateTime = System.DateTime.ParseExact("20061127", "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture)
datedifference = Date2.Subtract(Date1)
MessageBox.Show(datedifference)
George
|
|
|
|
|
The last line is the problem, that's where you assume a timespan is a string. Try the ToString method on the timespan object.
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 )
|
|
|
|
|
|
Hi George,
compiler errors and run-time exceptions tend to show line numbers
(look at Exception.ToString(), not Exception.Message).
The Visual Studio editor can show them too, but for some mysterious reason does not do so
by default; see menu Tools/Options/Text Editor/All Languages/General/...
If you turn them on, you'll locate problem spots much more easily.
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
|
|
|
|
|
HI
for the lie you wrote
MessageBox.Show(datedifference)
"datedifference" is not string....
TO resolve your issue you can convert datedifference's "value" to string using something like ctype
may be the this will work for you
MessageBox(Ctype(datedifference,String))
Good Luck
|
|
|
|
|
hi all
kidly help me to create menu with side by icon/image.
thanks in advance............
rmshah
Sr. Developer
|
|
|
|
|
Please Google before posting.
http://www.codeproject.com/vb/net/iconsmenu.asp
|
|
|
|
|
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.
|
|
|
|