[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

simulating in visual basic - very stupid beginner's question

atmkoh@yahoo.co.uk

6/17/2011 11:53:00 PM

Hi, this is a really strange question to ask. I need to simulate the
arrival of an aircraft at an airport and the unloading of cargo and
things like that. I am going to do that myself but I need to
understand something...and ask this question. Suppose I am simulating
the 1 busiest hour say 7-8 am in the morning and I know that at 7:10 a
flight takes off for Paris say and at 7:15 a flight takes off for
Brussels..etc etc ..how do I tell my program to be written in visual
basic that it is 7:10 or 7:15..etc..this is not real time obviously so
my program won't run for 1 hour but how do I get around this?? I am
utterly confused now with do events etc

I am not asking anyone to help me write a program or give me code for
this..but to help explain the concept behind the real time clock and
the computer simulated time clock which is supposed to be 7:15 when it
is clearly not in real-life!

Please can someone explain the concept if possible.
Thank you very much.
9 Answers

(nobody)

6/18/2011 1:53:00 AM

0

atmkoh@yahoo.co.uk wrote:
> Hi, this is a really strange question to ask. I need to simulate the
> arrival of an aircraft at an airport and the unloading of cargo and
> things like that. I am going to do that myself but I need to
> understand something...and ask this question. Suppose I am simulating
> the 1 busiest hour say 7-8 am in the morning and I know that at 7:10 a
> flight takes off for Paris say and at 7:15 a flight takes off for
> Brussels..etc etc ..how do I tell my program to be written in visual
> basic that it is 7:10 or 7:15..etc..this is not real time obviously so
> my program won't run for 1 hour but how do I get around this?? I am
> utterly confused now with do events etc
>
> I am not asking anyone to help me write a program or give me code for
> this..but to help explain the concept behind the real time clock and
> the computer simulated time clock which is supposed to be 7:15 when it
> is clearly not in real-life!
>
> Please can someone explain the concept if possible.
> Thank you very much.

Which version of VB are you using?


ralph

6/18/2011 2:03:00 AM

0

On Fri, 17 Jun 2011 16:53:29 -0700 (PDT), "atmkoh@yahoo.co.uk"
<atmkoh@yahoo.co.uk> wrote:

>Hi, this is a really strange question to ask. I need to simulate the
>arrival of an aircraft at an airport and the unloading of cargo and
>things like that. I am going to do that myself but I need to
>understand something...and ask this question. Suppose I am simulating
>the 1 busiest hour say 7-8 am in the morning and I know that at 7:10 a
>flight takes off for Paris say and at 7:15 a flight takes off for
>Brussels..etc etc ..how do I tell my program to be written in visual
>basic that it is 7:10 or 7:15..etc..this is not real time obviously so
>my program won't run for 1 hour but how do I get around this?? I am
>utterly confused now with do events etc
>
>I am not asking anyone to help me write a program or give me code for
>this..but to help explain the concept behind the real time clock and
>the computer simulated time clock which is supposed to be 7:15 when it
>is clearly not in real-life!
>
>Please can someone explain the concept if possible.
>Thank you very much.

1)

Dates and Times can be stored in VB in the Data data type. This data
type stores both a date and the time as a Double.

You can store any datetime in Date, by fetching from a system clock,
or from scratch and simple assignment.

For numeric expressions, 0 represents the date 12/30/1899.
Negative values represent dates before 12/30/1899; positive values
represent dates after.
The decimal portion represents the time as a proportion of a 24 hour
day (.25 = 6pm, .5 = noon, .75 = 6pm, etc.)

Here is a quick tutorial of how to work with the Date data type in VB.
(The first one Google came up with. <g>)
http://www.vb6.us/tutorials/date-time-functions-vi...

2)

But note that while some "times" are definitive, for example noon =
0.50, other times are actually represented by many significant digits
in the scale.
Often that works out especially if you stick to a granularity of one
minute, but all the usual problems associated with using floating
point arithimetic may arise as the Date storage is a Double. So
remember to always keep 'presentation' separate for 'storage', ie,
store in a double, but always use Format to present.

If these times are a matter of 'markers' you might consider storing
them as strings. Converting on to numbers when need for a calculation
and never touched.

-ralph

ralph

6/18/2011 2:10:00 AM

0

On Fri, 17 Jun 2011 21:53:12 -0400, "Nobody" <nobody@nobody.com>
wrote:

>
>Which version of VB are you using?
>

LOL

I always forget to ask.

Could have save myself a lot of time.

-ralph

Schmidt

6/18/2011 9:09:00 AM

0

Am 18.06.2011 01:53, schrieb atmkoh@yahoo.co.uk:

> Hi, this is a really strange question to ask. I need to simulate the
> arrival of an aircraft at an airport and the unloading of cargo and
> things like that. I am going to do that myself but I need to
> understand something...and ask this question. Suppose I am simulating
> the 1 busiest hour say 7-8 am in the morning and I know that at 7:10 a
> flight takes off for Paris say and at 7:15 a flight takes off for
> Brussels..etc etc ..how do I tell my program to be written in visual
> basic that it is 7:10 or 7:15..etc..this is not real time obviously so
> my program won't run for 1 hour but how do I get around this?? I am
> utterly confused now with do events etc

You don't need DoEvents, just a simple timer is enough,
which triggers a repeated "adjust Objects-State" Event.

So (as in each computer-generated Sim) you have
something like a MainLoop-Function (triggered
from the Timer-Event in your case) - and it
is your choice what TimeDelta you apply/add to
a "progressing, simulated RealTime-Variable".

This 'dT' can be left constant for each "timer-
triggered round" - and mayhap in your case
should be 1sec - or maybe 0.1sec.

Now what remains is the switching of the already
mentioned "Object-States" of all "participating
entities" in your simulation (followed by the
reflection of possibly changes states in the GUI).

Objects and States... best done over normal
Classes for the Objects and internal Enums
for the different states (some States, which
are defined in the Enum should be accompanied
by Private userdefined Types, which describe
a complex State then in more detail).

For example make a Class cAirPlane, having
a rough StateEnum inside like this:

Public Enum AP_StateEnm
InFlightArriving
InLandingPhase
InRollOutPhase
InWaitForCargoTrainPhase
InCargoUnLoadPhase
InParkingPhase

InCargoLoadPhase
InStartPositioningPhase
InStartAccelPhase
InFlightDeparting
End Enum

'and of course a set of Public Variables
'(Properties) and Methods...

Public CurrentState As AP_StateEnum
Public CurrentDelayTime as Date
Public UsualLandingTime As Date
Public UsualRollOutTime as Date
Public UsualCargoTrainArrivalTime As Date
Public ExpectedArrival As Date, ExpectedUnloadTimeAfterArrival as Date
Public ExpectedDeparture as Date
Public TravelledFrom As String, TravellingTo as String
Public FlightIDArrival As String, FlightIDDeparture As String
'...

'Then you need a Public Method, which is able to switch
'internal states of the Airplane, depending on "Time"
Public Sub DoSimulationStep(dT as Date, RealTime as Date)
If RealTime < ExpectedArrival + _
CurrentDelayTime Then
CurrentState = InFlightArriving

ElseIf RealTime < ExpectedArrival + _
CurrentDelayTime + _
UsualLandingTime Then
CurrentState = InLandingPhase

ElseIf RealTime < ExpectedArrival + _
CurrentDelayTime + _
UsualLandingTime + _
UsualRollOutTime Then
CurrentState = InRollOutPhase

ElseIf RealTime < ExpectedArrival + _
CurrentDelayTime + _
UsualLandingTime + _
UsualRollOutTime + _
UsualCargoTrainArrivalTime Then
CurrentState = InWaitForCargoTrainPhase

elseif ... a.s.o.

End If

'One can then calculate further (more granular)
'details within a given "Raw-State", using the
'passed dT-Interval, to calculate "SubStates"
'to shade some more light on the Unloading-Process
'for example, or the "LiftOff-Process" or whatever
Select Case CurrentState
Case InCargoUnLoadPhase
'calculate details here for SubStates in UnloadPhase

Case InStartAccelPhase
'calculate details, based on dT here for the
'Start-Phase - for example the expected LiftOff-
'Point or whatever one wants, based on the physics
'of a given airplane-type

case a.s.o
End Select
End Sub


So, the above was something "inside" of a predefined
'cAirPlane'-VB-Class - you can also introduce other
participants (more simulated Objects) and define appropriate
Classes for them in a similar way.

Each Class should have such a '.DoSimulationStep' method
as just shown above.

So that you can do the following in the above mentioned
"trigger-loop":

Private Sub tmrStep_Timer()
Dim AirPlane As cAirPlane
glbDT = 1 / 86400 'a constant dT, here one second in VBs DateFormat
glbRealTime = glbRealTime + glbDT

For Each AirPlane In AirPlanesCollection
AirPlane.DoSimulationStep glbDT, glbRealTime
Next AirPlane
End Sub

Before you enable the tmrStep-Timer, you should
decide about the speed - for example if your
glbDT-Interval is set to one second, and you
set the Timer.Interval to 1000 (msec) then the
Simulation runs roughly in Realtime - if you
set it to only 100msec, then the Simulation runs
10 times as fast as in "reality" - also
make sure to set the glbRealTime-Variable to
your Starting-DateTime of choice, before enabling
the Timer.

That's it basically with regards to structuring -
just flesh out the details yourself.

Olaf

atmkoh@yahoo.co.uk

6/18/2011 5:48:00 PM

0

Thank you all for helpful explanations! I am less muddled as when I
first asked the question so kudos to you for helping out.

I am able to use both classic VB (vb6) as well as VB dot Net and we
have not decided which one yet.
In the eventuality that we might need a console, maybe dot Net is the
way to go.


On Jun 18, 10:09 am, Schmidt <s...@online.de> wrote:
> Am 18.06.2011 01:53, schrieb atm...@yahoo.co.uk:
>
> > Hi, this is a really strange question to ask. I need to simulate the
> > arrival of an aircraft at an airport and the unloading of cargo and
> > things like that. I am going to do that myself but I need to
> > understand something...and ask this question. Suppose I am simulating
> > the 1 busiest hour say 7-8 am in the morning and I know that at 7:10 a
> > flight takes off for Paris say and at 7:15 a flight takes off for
> > Brussels..etc etc ..how do I tell my program to be written in visual
> > basic that it is 7:10 or 7:15..etc..this is not real time obviously so
> > my program won't run for 1 hour but how do I get around this?? I am
> > utterly confused now with do events etc
>
> You don't need DoEvents, just a simple timer is enough,
> which triggers a repeated "adjust Objects-State" Event.
>
> So (as in each computer-generated Sim) you have
> something like a MainLoop-Function (triggered
> from the Timer-Event in your case) - and it
> is your choice what TimeDelta you apply/add to
> a "progressing, simulated RealTime-Variable".
>
> This 'dT' can be left constant for each "timer-
> triggered round" - and mayhap in your case
> should be 1sec - or maybe 0.1sec.
>
> Now what remains is the switching of the already
> mentioned "Object-States" of all "participating
> entities" in your simulation (followed by the
> reflection of possibly changes states in the GUI).
>
> Objects and States... best done over normal
> Classes for the Objects and internal Enums
> for the different states (some States, which
> are defined in the Enum should be accompanied
> by Private userdefined Types, which describe
> a complex State then in more detail).
>
> For example make a Class cAirPlane, having
> a rough StateEnum inside like this:
>
> Public Enum AP_StateEnm
>      InFlightArriving
>      InLandingPhase
>      InRollOutPhase
>      InWaitForCargoTrainPhase
>      InCargoUnLoadPhase
>      InParkingPhase
>
>      InCargoLoadPhase
>      InStartPositioningPhase
>      InStartAccelPhase
>      InFlightDeparting
> End Enum
>
> 'and of course a set of Public Variables
> '(Properties) and Methods...
>
> Public CurrentState As AP_StateEnum
> Public CurrentDelayTime as Date
> Public UsualLandingTime As Date
> Public UsualRollOutTime as Date
> Public UsualCargoTrainArrivalTime As Date
> Public ExpectedArrival As Date, ExpectedUnloadTimeAfterArrival as Date
> Public ExpectedDeparture as Date
> Public TravelledFrom As String, TravellingTo as String
> Public FlightIDArrival As String, FlightIDDeparture As String
> '...
>
> 'Then you need a Public Method, which is able to switch
> 'internal states of the Airplane, depending on "Time"
> Public Sub DoSimulationStep(dT as Date, RealTime as Date)
>      If RealTime < ExpectedArrival + _
>                    CurrentDelayTime Then
>         CurrentState = InFlightArriving
>
>      ElseIf RealTime < ExpectedArrival + _
>                        CurrentDelayTime + _
>                        UsualLandingTime Then
>         CurrentState = InLandingPhase
>
>      ElseIf RealTime < ExpectedArrival + _
>                        CurrentDelayTime + _
>                        UsualLandingTime + _
>                       UsualRollOutTime Then
>          CurrentState = InRollOutPhase
>
>      ElseIf RealTime < ExpectedArrival + _
>                        CurrentDelayTime + _
>                        UsualLandingTime + _
>                       UsualRollOutTime + _
>                       UsualCargoTrainArrivalTime Then
>          CurrentState = InWaitForCargoTrainPhase
>
>      elseif ... a.s.o.
>
>      End If
>
>      'One can then calculate further (more granular)
>      'details within a given "Raw-State", using the
>      'passed dT-Interval, to calculate "SubStates"
>      'to shade some more light on the Unloading-Process
>      'for example, or the "LiftOff-Process" or whatever
>      Select Case CurrentState
>         Case InCargoUnLoadPhase
>            'calculate details here for SubStates in UnloadPhase
>
>         Case InStartAccelPhase
>            'calculate details, based on dT here for the
>             'Start-Phase - for example the expected LiftOff-
>             'Point or whatever one wants, based on the physics
>             'of a given airplane-type
>
>         case a.s.o
>      End Select
> End Sub
>
> So, the above was something "inside" of a predefined
> 'cAirPlane'-VB-Class - you can also introduce other
> participants (more simulated Objects) and define appropriate
> Classes for them in a similar way.
>
> Each Class should have such a '.DoSimulationStep' method
> as just shown above.
>
> So that you can do the following in the above mentioned
> "trigger-loop":
>
> Private Sub tmrStep_Timer()
> Dim AirPlane As cAirPlane
>      glbDT = 1 / 86400 'a constant dT, here one second in VBs DateFormat
>      glbRealTime = glbRealTime + glbDT
>
>      For Each AirPlane In AirPlanesCollection
>         AirPlane.DoSimulationStep glbDT, glbRealTime
>      Next AirPlane
> End Sub
>
> Before you enable the tmrStep-Timer, you should
> decide about the speed - for example if your
> glbDT-Interval is set to one second, and you
> set the Timer.Interval to 1000 (msec) then the
> Simulation runs roughly in Realtime - if you
> set it to only 100msec, then the Simulation runs
> 10 times as fast as in "reality" - also
> make sure to set the glbRealTime-Variable to
> your Starting-DateTime of choice, before enabling
> the Timer.
>
> That's it basically with regards to structuring -
> just flesh out the details yourself.
>
> Olaf

Darksaint

6/18/2011 6:13:00 PM

0

atmkoh@yahoo.co.uk wrote:

> Thank you all for helpful explanations! I am less muddled as when I
> first asked the question so kudos to you for helping out.
....


What sort of a simulation of which are you speaking? Monte Carlo comes
to my mind when I read the original posting and I wonder what end
objective is as I tend to think answer is perhaps dependent on knowing
what is desired as an end output objective here...

--

Thorsten Albers

6/18/2011 11:08:00 PM

0

atmkoh@yahoo.co.uk schrieb im Beitrag
<c6ed189c-be87-46f5-b630-6454caa8c110@q30g2000yqb.googlegroups.com>...
> I am able to use both classic VB (vb6) as well as VB dot Net and we
> have not decided which one yet.
> In the eventuality that we might need a console, maybe dot Net is the
> way to go.

Although I myself don't like VB.net:
When starting a >completely new< project VB.net (or, of course, C/C++/C#)
should be your choice in any case! VB.classic isn't supported by its
manufacturer since a long time now.

--
Thorsten Albers

gudea at gmx.de

(nobody)

6/19/2011 1:02:00 PM

0

atmkoh@yahoo.co.uk wrote:
> I am able to use both classic VB (vb6) as well as VB dot Net and we
> have not decided which one yet.
> In the eventuality that we might need a console, maybe dot Net is the
> way to go.

This group deals with VB6 and lower only. For VB.Net, use this forum:

http://social.msdn.microsoft.com/Forums/en-US/category/vi...

The two languages are different enough that the only way to upgrade is to
re-write.



Karl E. Peterson

6/24/2011 9:31:00 PM

0

atmkoh@yahoo.co.uk pretended :
> In the eventuality that we might need a console, maybe dot Net is the
> way to go.

I write console apps in VB6 all the time.

See: http://classicvb.net/sampl...

--
..NET: It's About Trust!
http://vfre...