Results 1 to 10 of 10

Thread: Maybe a simple problem.....

  1. #1

    Thread Starter
    Lively Member brjames's Avatar
    Join Date
    Jan 2000
    Location
    Tenby, Wales, UK
    Posts
    121
    I am currently creating a harbour management system.
    But I am facing a problem. The system is mainly designed in VB but uses an access database with four tables for the data displayed on the VB forms. On the first menu is an aerial photo of the harbour. The users have to click on individual boats and the information about that boats is retrieved and displayed in text boxes on a form.

    The problem is that I need to re-use the form and am not sure how to go about retrieving the data needed to put on the form as it is different for every boat. I have thought about global variables and modules but cannot find any information on them.

    Can anyone please help me before I go mentally insane!

    Thanks in advance!

  2. #2
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Right.

    Assuming you can get all of the data out of the database.

    Create a user define type. Then create an array of this type. Lets say you have 4 boats.

    Place the following into a module. eg. boatModule. This way you will be able to access the data from any form

    Code:
    Priavte Type BoatInfoType
      Name As String
      Cost As Double
    End Type.
    
    Public boatInfo(3) As BoatInfoType

    When you get the data from the database put the information on each boat type into your User Type.

    Code:
    For i = 0 To 3
      boatInfo(i).Name = "Name Of Boat From DataBase Record i"
      boatInfo(i).Cost = "Cost Of Boat From DataBase Record i"
    Next i

    Then when a user click on a boat you should know what number the boat is and do the following.

    Code:
    txtBoatName.Text = boatInfo(boatNum).Name
    txtBoatCost.Text = boatInfo(boatNum).Cost
    Hope this helps.
    Iain, thats with an i by the way!

  3. #3
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    Using global variables is easy enougth but I'm not sure that's really what you want here

    add a moule to your project and just declare your variable using the Public keyword

    eg
    Public BoatName as String


    just a suggestion but...
    INstead of havinbg a seperate form to display the data, you could have add a bit on the on the end of your main form

    Code:
    -----------------------------------
    | main picture          |         |
    |                       | text 1  |
    |                       |         |
    |                       | text 2  |
    |                       |         |
    |                       | text 3  |
    |                       |         |
    |                       | text 4  |
    |                       |         |
    |                       |         |
    |----------------------------------
    Mark
    -------------------

  4. #4
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658

    Lightbulb

    Having just reviewed your question i have realised that i may have gone a little bit over the top with my solution.

    You don't really need an array of all the data for every boat, as when they click on a boat you retreive the data from the database according to that boat. So all you need is the Type and a variable of that Type.

    I am sticking by my guns about the user defined type though. It keeps everything in one place, much tidier.

    Say we have 4 pieces of data for each boat then you would have to have 4 seperate variables.

    eg.

    BoatName
    BoatCost
    BoatSize
    BoatSpeed

    Obviously you still have to have all of these variables in the type, but it makes it easier to manage and you don't have to go off looking for a variable name that you can't remember, because the type ahead will list all of the variables in the Type.

    Iain, thats with an i by the way!

  5. #5

    Thread Starter
    Lively Member brjames's Avatar
    Join Date
    Jan 2000
    Location
    Tenby, Wales, UK
    Posts
    121

    Still not sure

    Iain,

    I am a beginner at VB so am not very good. What I have in my module at the moment is:

    Private Type BoatInfoType
    MooringNumber As String
    BoatName As String
    BoatLength As String
    OwnerName As String
    OwnerAddress As String
    OwnerTelNo As Integer
    End Type

    Public boatinfo(4) As BoatInfoType

    I'm not sure what to do next when the person clicks on the boat. I need to get the information for the specific boat selected from the database and display it on the form but I'm not sure how to.


  6. #6
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658

    Question

    How are you getting the information from the database?
    Iain, thats with an i by the way!

  7. #7

    Thread Starter
    Lively Member brjames's Avatar
    Join Date
    Jan 2000
    Location
    Tenby, Wales, UK
    Posts
    121

    Smile

    At the moment I am getting the information from the database with a data control on the form that I want to re-use along with some text boxes.

  8. #8
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    Make sure the folling code is in a module, not a form

    Code:
    Private Type BoatInfoType 
      MooringNumber As String 
      BoatName As String 
      BoatLength As String 
      OwnerName As String 
      OwnerAddress As String 
      OwnerTelNo As Integer 
    End Type 
    
    Public boatinfo As BoatInfoType
    When the user clicks on a boat i assume you know which boat it is.

    Lets say they click on boat 1.

    Get the information from the database for boat 1.

    now store that info into "boatInfo"

    Code:
    boatInfo.MooringNumber = database.mooringNumber
    boatInfo.BoatName = database.boatName
    etc.
    now bring up the information form and display the data.

    Code:
      frmBoatInfo.Show
    Now in the form load event of the information form display the data.

    Code:
      Private Sub Form_Load()
        Text1.Text = boatInfo.MooringNumber
        Text2.Text = boatInfo.BoatName
        ...
      End Sub

    Is this helping you at all?
    Iain, thats with an i by the way!

  9. #9

    Thread Starter
    Lively Member brjames's Avatar
    Join Date
    Jan 2000
    Location
    Tenby, Wales, UK
    Posts
    121
    Iain

    That is great I understand now.
    Thanks for your help!

  10. #10
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658

    Wink

    No Worries
    Iain, thats with an i by the way!

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