|
-
Apr 12th, 2000, 04:43 PM
#1
Thread Starter
Lively Member
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!
-
Apr 12th, 2000, 05:39 PM
#2
Fanatic Member
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!
-
Apr 12th, 2000, 05:57 PM
#3
Frenzied Member
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 |
| | |
| | |
|----------------------------------
-
Apr 12th, 2000, 06:12 PM
#4
Fanatic Member
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!
-
Apr 12th, 2000, 07:29 PM
#5
Thread Starter
Lively Member
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.
-
Apr 12th, 2000, 07:38 PM
#6
Fanatic Member
How are you getting the information from the database?
Iain, thats with an i by the way!
-
Apr 12th, 2000, 08:14 PM
#7
Thread Starter
Lively Member
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.
-
Apr 12th, 2000, 08:36 PM
#8
Fanatic Member
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.
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!
-
Apr 12th, 2000, 08:40 PM
#9
Thread Starter
Lively Member
Iain
That is great I understand now.
Thanks for your help!
-
Apr 12th, 2000, 08:48 PM
#10
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|