|
Hi!
I'm stuck on a inheritance/typecast problem and would like some help.
I have two modules named Main.vb and Test.vb with the following contents:
'---------------- Test.vb ------------------------------------------------------
Imports SHDocVw
Module Test
Public Class clsTest
Public HWND As Long
'
' Omitted additional members goes here.
'
End Class
Public Sub doSomething(ByRef c() As clsTest)
Dim i As Integer
Dim ieCollection() As InternetExplorer = Nothing
'
' Omitted code that populates ieCollection goes here.
'
i = 0
For Each ie As InternetExplorer In ieCollection
' [Insert #1]
c(i).HWND = ie.HWND
i += 1
Next
End Sub
End Module
'---------------- End of Test.vb -----------------------------------------------
'---------------- Main.vb ------------------------------------------------------
Module Main
Private Class clsTestExtended
Inherits Test.clsTest
Public strParam1 As String
Public strParam2 As String
End Class
Public Sub main()
Dim ce() As clsTestExtended = Nothing ' [Change #1]
' [Insert #2]
Test.doSomething(ce)
For Each c As clsTestExtended In ce
c.strParam1 = ""
c.strParam2 = ""
Next
End Sub
End Module
'---------------- End of Main.vb -----------------------------------------------
This is my problem:
If I insert the following piece of code at the [Insert #1] marker in Test.vb:
If c Is Nothing Then
ReDim c(0)
Else
ReDim Preserve c(i)
End If
c(i) = New clsTest
then, on return from Test.doSomething, I get a runtime error:
Unable to cast object of type 'clsTest[]' to type 'clsTestExtended[]'
If instead of the above modification, I change the line marked [Change #1] in Main.vb to
Dim ce(1) As clsTestExtended
and insert this piece of code at the [Insert #2] marker in Main.vb :
ce(0) = New clsTestExtended
ce(1) = New clsTestExtended
then I get no runtime error (assuming the 'For Each' loop in Test.doSomething doesn't loop more than twice). The problem is that the main() sub can't/shouldn't know before the call to Test.doSomething how big the ce array will be on return from Test.doSomething and so dimensioning ce before the call to Test.doSomething is not safe.
What I really want to use is the first modification but without the typecast problem or another solution to the problem that achieves the same thing (which is: the main() sub works with the inherited 'ce' classes while the doSomething sub can dynamically change the 'c' classes and have the changes made available to the main() sub in the 'ce' classes).
Any ideas?
Best Regards,
Anders
-- modified at 16:00 Friday 1st December, 2006
|
|
|
|
|
Why are you using an array instead of dynamic container ?
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Christian,
Thanks for the quick reply!
Ummm, 'dynamic container' I think I need some hints here. Never heard of that before. Still trying to absorb all the new NET stuff.
Best Regards,
Anders
|
|
|
|
|
Your first step should be to remove references to the VisualBasic namespace. I suspect this is where Redim and so on are coming from. VB.NET contains a lot of bad stuff from VB6, only because MS was forced into it by people complaining. They are all in that namespace. Delete that, or you'll end up coding VB6 in .NET and not get the full benefit of moving.
If it's VS2005, you can create a List<baseType>, which is a generic container, to which you can add and remove objects at will. You therefore don't need to redim anything. If you ever need an array, those containers offer methods that return them.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Did some reading about Lists and generics and they look really useful. I'm not sure though how Lists and generics can solve my main problem (which is having the 'doSomething' sub work with the list as if it is a list of 'clsTest' objects while the 'main' sub can work with the same list as if it is a list of 'clsTestExtended' objects) but maybe that will become obvious if I do some more reading on the subject.
Best Regards,
Anders
|
|
|
|
|
I need to know how to make the DateTimePicker control in VB 2005 to basically real-time update itself. I want the DateTimePicker to keep track of the time. Guidence?
|
|
|
|
|
Well, the control really wasn't meant to be used the way you want to, but it's probably possible if you drop a Timer control on your form, set it for 1000 millisecond interval, then handle the Timer's Tick event. In the event handler code, just set the DateTimePicker's Value property with the current DateTime.Now().
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I can't get motherboard name on visual basic 2005. What way i can use instead of WMI functions???
because with WMI doesn't work!!! =(((( if somebody knows way please mail me: serg_212@mail.ru
-- modified at 17:15 Thursday 30th November, 2006
|
|
|
|
|
WMI *does* work.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
The WMI method is about the ONLY method you have. But, it will only work if the MoBo manufacturer includes the proper WMI Provider drivers to actually supply the information to WMI.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
O thank you for your answer but when i install soft witch determine motherboard name, temperature,
voltage and etc and this program is really works. And i'am very suprised when my code doesn't work!!! =(((( I want to know what method is use by that programms in gettting motherboard name????
|
|
|
|
|
Because the app doesn't use WMI to get it's information, it has to use the Win32 API function GetSystemFirmwareTable[^] to get this kind of information. There is no support for it in the .NET Framework BCL. Beyond that, it's a custom read of physical memory locations.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
O thank you!!! For this moment I didn't know a way(instead of WMI of course) in getting hardware information and etc.Later, I want to test this API function on Visual Basic 6!!!! I think it will work!!!
|
|
|
|
|
I'm just learning VB.NET and am writing some code that will poll the network and display status boxes within a form. This works fine using something, displaying a nice status strip kinda thing about 50 pixels high (+ the title bar).
But ... Now I come to rotate the form to show it vertically, and find that it seems to have a minimum width which is rather wide !!!
I find that setting the MinimumSize doesn't help. And trying to set the width in the code doesnt help either. It wont get smaller than 123 pixels. This restriction is also experienced in the Design window if manually creating a form.
If I remove the minimize box and maximize box from the form I can resize it to a narower size when the program is running (around 65 pixels), but the 'size' function wont take it to this width.
Now I guess there is something limiting the narowest width that you can chose for a form, but it does seem rather daft.
Maybe I shouldn't be using a Form, but it does everything I want. I have searched the web and the forums and can't see any reference to this restriction, which makes me think I'm missing something obvious !
Please help put me at rest and get me thinking about something else.
Thanks
Nigel
|
|
|
|
|
Probably because a small form like that is seldom ever used. Try changing the FormBorderStyle to SizableToolWindow or FixedToolWindow to see if that gives you what you want.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Oh my !!!!!!!
Thats exactly it !!!
I can't believe it. All those days of searching and it was that easy (for you of course).
Much appreciated, your my hero for today.
Please award yourself a gold star.
Nigel
|
|
|
|
|
I programmed a windows service that sends email alerts based on database returns... The problem is as Follows..
Background:
When I loop through the records I am building a large string (i.e. Result += ) for a mailmessage.body and including the HTML tags ... The record lengths are of various sizes and always random.
Issue:
My issue is when it sends the message, the string is split up after 989 characters and a ! is entered in the string... If the ! is in the middle of text it is not as much of an issue... I just see a ! in the mail message; but if it is put in the HTML Tag the message goes to Cr*p...
Does anyone know how I can prevent the ! from being placed in the string or another method to avoid this..
Thanks in advance
Adam Downs
|
|
|
|
|
Step through your code that builds this string and watch to see what the ! comes from. If you get through your code and just before you call Send , it's still not in your string, it's probably being inserted by your mail server.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
It is not in the string prior to the send function... Where do I go from here if it is put in by the mail server?
|
|
|
|
|
It's possible that there is a line length limit on the mail server, it's just a Telnet session after all... Try adding CarriageReturn characters in appropriate places in your string instead of making it one very long line.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Carriage Returns Did the Trick...
Thanks Alot!
Adam Downs
|
|
|
|
|
Hey Guys,
I made an application in which i had used dynamic generation of picture boxes. I have one picture box and the dynamic generation of the picture boxes are duplicate of the one that i already have. Even then the performance is really not good and it takes hell lot of time for the thumbnails to load in the picturebox.
Is there is good logic that i can use for this. Anything that just loads up everything instanetaneously?
Thanks !!!
Ankit
|
|
|
|
|
The performance of the PictureBox is dependant on the ORIGINAL size of the image your stuffing in it. If you're telling the PB to load an image from a file that's, say, 3000x3000x32bits, it'll take a while to load, even though your probably scaling it down to fit in a box that's 100x100.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
IF you are doing anything non-trivial with images, you should abandon the picturebox, and draw it yourself. And yes, use the DrawImageUnscaled method for speed, and make sure your image is the right size, so you don't waste memory.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Dear Friends,
Seeking help from Pros on how to write application using .net 2005
for a Mobile computer running windows CE.
Application also need to have a databse.
There are few of articles. But difficult to understand for a beginer
always share to enhance your knowledge...!
|
|
|
|