JustinN Posted June 28, 2004 Posted June 28, 2004 (edited) I need to create forms and save forms. I heard that a hashtable is a good way to do that. I have never used one before. Here is the code that I got. THIS IS THE ERROR THAT IM GETTING An unhandled exception of type 'System.InvalidCastException' occurred in AndersenAsi.exe Additional information: Specified cast is not valid. Dim CurrentForm As frmAddItemNumber = MyHashTable(1) Dim NewForm As New Form1 Dim MyHashTable As New Hashtable MyHashTable.Add(1, NewForm) Dim CurrentForm As frmAddItemNumber = MyHashTable(1) CurrentForm.Show() Edited June 29, 2004 by JustinN Quote
Moderators Robby Posted June 28, 2004 Moderators Posted June 28, 2004 You can't just add a form to the hash table, you can add its contents though. Quote Visit...Bassic Software
*Experts* Nerseus Posted June 29, 2004 *Experts* Posted June 29, 2004 You should be able to add/retrieve a form from a hashtable. You'll need to cast it to a form when you take it out - that's the compile problem. Here's the line to change: Dim CurrentForm As frmAddItemNumber = DirectCast(MyHashTable(1), frmAddItemNumber) -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
JustinN Posted June 30, 2004 Author Posted June 30, 2004 You should be able to add/retrieve a form from a hashtable. You'll need to cast it to a form when you take it out - that's the compile problem. Here's the line to change: Dim CurrentForm As frmAddItemNumber = DirectCast(MyHashTable(1), frmAddItemNumber) -ner Tried what you posted but the result was the same. Dim NewForm As New Form1 Dim MyHashTable As New Hashtable MyHashTable.Add(1, NewForm) Dim CurrentForm As frmAddItemNumber = DirectCast(MyHashTable(1), frmAddItemNumber) CurrentForm.Show() Quote
Administrators PlausiblyDamp Posted June 30, 2004 Administrators Posted June 30, 2004 You are adding a variable of type Form1 to the HashTable and then trying to get a frmAddItemNumber out of the HashTable - they are different types hence the InvalidCastException. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.