Results 1 to 11 of 11

Thread: Loading Multiple Forms

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Posts
    73

    Loading Multiple Forms

    I Have a Small form (frmAddItemNumber) with a text box (txtAdditemNumber) and a command button(cmdAddItemNumber)

    This is what I need the form to do.
    1) Connect to the database (Complete)
    2) Store the value entered into textbox to database. (Complete)
    3) Load a blank form so the user can draw on it. Must be a different form for each value entered in the textbox. (Not Complete)

    Any Ideas on how to do #3. Someone told me that I could use a hashtable but I could not get it to work.

    Dim NewForm As New Form1
    Dim MyHashTable As New Hashtable
    MyHashTable.Add(1, NewForm)
    Dim CurrentForm As frmAddItemNumber = MyHashTable(1)
    CurrentForm.Show()

  2. #2
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    Your CurrentForm is a different type than the Form you put in the Hash Table. One is type Form1, the other is type frmAdditemNumber. The following code works fine:

    Dim MyForm As New Form1
    Dim ht As New Hashtable
    Dim CurrentForm As Form1

    ht.Add(1, MyForm)

    CurrentForm = ht(1)

    CurrentForm.Show()

    And you can even leave out the CurrentForm and do:

    Dim MyForm As New Form1
    Dim ht As New Hashtable


    ht.Add(1, MyForm)

    ht(1).Show()
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Posts
    73
    It works!! I am new at VB.Net. What is the best source of information to learn vb.net. Books, internet sites? If so, what books or sites are the best.

    Thanks for your help!!!!!!!!!!!!!!!!!

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Posts
    73
    The only thing wrong with the way my program runs right now is that I need to bring up new forms every time the add button is clicked on. Right now we have it set up to bring up form1. Is thier a way to create new forms each time?

  5. #5
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    You could change the type to just Form, but if I am remembering correctly you had some draw functions as part of your Form1. Why not create a new blank form that just has the draw functions you need and make that the type that you new and add to the Hashtable?
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Posts
    73
    Well i am using my draw form instead of form1. so when the additemnumber button is seleted the draw form loads up. So now when I draw on the form I need to be able to save it to the database so I can retrieve it later. Is this posible?

  7. #7
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    Look into object Serialization.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Posts
    73
    What does this line of code mean

    ht.Add(1, MyForm)

  9. #9
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    You are adding an object called MyForm to the hashtable collection keyed to 1.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jun 2004
    Posts
    73
    I have a book that talks about serializable but ties it with xml. Saving it to a file. Do you know where I kind find info on using vb.net with an sql database?

  11. #11
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    I can't say that I've played around with it too much. I would guess though that you could serialize your forms into a MemoryStream, and then use a BinaryReader to read data from that stream and write it to, for example, an image field in a SQL Server database. I've never tried to do it though, so that is just a thought of a possible approach. Maybe somebody here has done it and knows better.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width