UDTs (as was vb6)

  • Thread starter Thread starter StrandElectric
  • Start date Start date
Cor said:
To give also some actual answers

@@@and to give some questions arising...
"StrandElectric" wrote in message
##What is a console application?
It is a kind of application template you can choose in Visual Basic
Express.
File -> New -> Project then a box with all program template opens, a
Console Application is the third template.
It creates an empty application which runs in a Dos Box like with Basic A.

In VB6 you were using what is in VB Express the first template "Windows
Forms Application".
@@@ so there are other ways? I could do this with a normal form?
##You have given some (well heaps of!) code, starting with Option Explicit
On
(which I understand!). After the Imports you write 'Module Module1?
That is standard created if you choose for Console Application

@@@ so if I chose a normal form instead should I also open a (non-form)
module as with vb6, and if so which parts of the code go in it?
##Next you dim Private m_NameOfFile. Is that some reserved keyword?
It is a notation for variables which Jason uses.
Currently the most I see used is the camel notation which would be in this
case mNameOfFile
However, mainly it is like you already thought. In fact you can use what
you want as long as it are not reserved words (From which the most are the
same like in VB6).


@@@Go that perfectly. Thanks. I can learn well with this style of very short
factual answers! Reminds me of the huge problems I first had with VB6
until I realised that capitalisation (and especially mixed case) was
entirely at the whim of a programmer (provided it did not clash with
reserved words. So I could invent a variable CorsWisdom with the capital W
just there to highlight that it is a compound word, as long as I declare it
as a type of course. Makes total sense, but is it explained anywhere in
beginners books? No! Not vb6 and not vb.net. Thanks again all
 
StrandElectric said:
What is a console operation? Is it just one possible approach or the only
one?

Have you ever written a DOS program? Remember that there was no GUI - it
was just text input and output. That's what the Console Application
provides. Open Visual Studio and select New Project - you will see it there.
Now here you have put the statement 'Module Module1 within this code '. Is
that *within* the form?

When you create a new Console Application it will automatically create
the following for you:

Module Module1

Sub Main()

End Sub

End Module

A Module is the equivalent of a .bas file in VB6. C# doesn't have them.

Module1 can be renamed anything you want. However, I think it's best to
rename it in the Properties window - to keep keep it the same as the
file name.

You should probably start all your projects from a Sub Main().
Next you dim Private m_NameOfFile. Is that some reserved keyword or could I
have put any variable name like OriginalNameOfFile? The same with 'hFile'
later on and m_Col(1) and m_Printer? and 'rec' too. Are they just the
variable names you've chosen? Can I substitute others that make more sense
to me (I have always found the underscore to be difficult to type).

The code I supplied is a combination of yours, Tom's and mine. I haven't
bothered to standardise all the variable names or (re)name them properly.

Microsoft (and others) have plenty of guidance on naming variable and
procedures. Cor has mentioned that camelCase is the norm for variables.
PascalCase is the norm for procedures (subs/functions).

I'm not interested in how you name your variables, but I still prefix
globals (ie variables declared Public in the Declarations section of a
Module) with g, and Private member variables (or fields) in the
Declarations section of Classes and Forms with m. Variables declared
within a procedure, using Dim, do not require a g or m scoping prefix.

People no longer recommend using s or str for Strings, o or obj for
Objects, etc. - but when upgrading old VB6 code to .NET I've ended up
with an awful lot of them and am not going to be bothered renaming all
my variables.

In answer to your question I would generally use something like:
Public gsClaimFile As String 'if I wanted a global string
Private msClaimFile As String 'if used throughout a Form or Class
Dim sClaimFile As String 'if within a procedure

But others think this type of naming convention is no longer required -
because if you hover the mouse over the variable then the IDE will tell
you what type it is. But, I think that's a stupid argument.

However, at this stage, the above is unimportant.

You should have created a Console Application, pasted the code into it,
created the reference mentioned, ensured there was a C:\temp folder and
clicked Run. Have you managed to do that?
 
| But you got me with one, I don't know what the meaning of a TV dinner in
| your language is.

I think TV dinners are still made but maybe people
don't eat them in front of the TV anymore. It's usually
a low-quality meal -- maybe hamburger, peas, and
processed potato -- all in their own sections of an
aluminum foil pan. The pan is covered with foil and
the product comes frozen. One then puts it into an oven
or microwave to heat it up.

The idea is a delicious, full course meal with no work.
The picture on the box shows such a meal. But the
contents inside are not very tasty.

I didn't mean to infer that VB and .Net are not
very tasty, though. Just that they're designed to
turn out a finished product easily. You can heat up
your TV dinner control, pour on a bit of Heinz
customization, and you've got an original software
product. :)
 
| All of that applies to .NET as well - in fact more so. Do I have to
| yet again show you the superior interop cababilities backed into .NET?
|

Oh, don't get me started... I did a Win7 upgrade
for someone the other day and found 600+MB of
..Net in one folder, with 150+- MB in another folder.
That was on a laptop with only 70 GB free to use.
It's enough to make one's blood boil.

And you want to talk about how I could create a
dependency on all that in order to access COM...

(Though, actually, the .Net mess was dwarfed by a
folder called winsxs. I had no idea that Vista/7 was
such a monstrosity. I thought it was outrageous that
it takes up 7-9 GB just for the OS. But a little research
turned up people complaining about winsxs folders
growing to 30 or even 60 GB. So Vista/7 is almost 10
times the size of XP, but it can bloat to some 60 times
the size. That even makes the .Net framework seem
almost civilized.)
 
Mayayana formulated on Wednesday :
Oh, don't get me started... I did a Win7 upgrade
for someone the other day and found 600+MB of
.Net in one folder, with 150+- MB in another folder.
That was on a laptop with only 70 GB free to use.
It's enough to make one's blood boil.

And you want to talk about how I could create a
dependency on all that in order to access COM...

LOL... Your going to bring size up again? You've been slapped down on
that before as well. And besides, in Vista up, .NET is part of the OS
- just as the vb runtimes were.

And, I wasn't talking about just COM... I was talking about things
like:

1) ability to call cdecl functions
2) ability to declare unicode api (no typelibs or hacks)
3) ability to use 64-bit api calls
4) ability to use unions in interop calls

And the list goes on. And if you want to talk about COM - well, VB.NET
is better at COM then VB6, in that it can use a wider range of com
objects, you know all those that don't implement IDispatch.

And what are you going to do when win8 supports ARM processors? Your
apps will be limited to intel architectures only. .NET apps, will
continue to work...

Oh, and no xbox, windows phone 7, or zune developement for you either
:)
 
from what I've seen.. VB.net has made a HUGE comeback in the past few
years.. and is now more popular than C#!





Am 02.01.2011 04:52, schrieb StrandElectric:
Understanding the project structure is one good beginning. :-)
The key point was only about putting classes into Namespaces, to
say it in short.

That sentence is way above my head!

 As you were already programming in VB6 and before,> I thought that's the first bigger change to VB6, and I explained it
because you were unsure about Imports.
If you want to get into VB.Net anyway, or if you want to upgrade code,
learn VB.Net. If you don't want or need to, and if you feel more
comfortable
in VB6 and just want to write the code that does what you need, then you
may use VB6 only. So, you must decide.

Well, I'm very happy with vb6, and I am looking at vb.net for two reasons..
1) In case my vb6 projects will not work with future Windows versions and2)
as a challenege. 1 is more important by a long way.
Anyway, you're welcome to the group with the left over lone fighters
that keep this dead group alive. ;)

But there may be millions of puzzled beginners. Where do they all go.? Ordo
they all give up vb.net...It seems to be a long way from the natural
progressionof the basic language as many of us have known it. I thought vb6
was absolutely brilliant. Why did Microsoft pull the plug on it? vb.net
seems so obscure from a user point of view. Almost as though a team
deliberately and peversely made the concepts as indirect as possible.


 
Jason Keats said:
Have you ever written a DOS program? Remember that there was no GUI - it
was just text input and output. That's what the Console Application
provides. Open Visual Studio and select New Project - you will see it
there.


When you create a new Console Application it will automatically create the
following for you:

Module Module1

Sub Main()

End Sub

End Module

A Module is the equivalent of a .bas file in VB6. C# doesn't have them.

Module1 can be renamed anything you want. However, I think it's best to
rename it in the Properties window - to keep keep it the same as the file
name.

You should probably start all your projects from a Sub Main().


The code I supplied is a combination of yours, Tom's and mine. I haven't
bothered to standardise all the variable names or (re)name them properly.

Microsoft (and others) have plenty of guidance on naming variable and
procedures. Cor has mentioned that camelCase is the norm for variables.
PascalCase is the norm for procedures (subs/functions).

I'm not interested in how you name your variables, but I still prefix
globals (ie variables declared Public in the Declarations section of a
Module) with g, and Private member variables (or fields) in the
Declarations section of Classes and Forms with m. Variables declared
within a procedure, using Dim, do not require a g or m scoping prefix.

People no longer recommend using s or str for Strings, o or obj for
Objects, etc. - but when upgrading old VB6 code to .NET I've ended up with
an awful lot of them and am not going to be bothered renaming all my
variables.

In answer to your question I would generally use something like:
Public gsClaimFile As String 'if I wanted a global string
Private msClaimFile As String 'if used throughout a Form or Class
Dim sClaimFile As String 'if within a procedure

But others think this type of naming convention is no longer required -
because if you hover the mouse over the variable then the IDE will tell
you what type it is. But, I think that's a stupid argument.

However, at this stage, the above is unimportant.

You should have created a Console Application, pasted the code into it,
created the reference mentioned, ensured there was a C:\temp folder and
clicked Run. Have you managed to do that?

Thanks Jason.

I've been trying to read an existing random access file with some of your
code. . I am not complicating the issue with writing to a file or printing
just yet! BTW, I fear that Visual Basic Expess 2008 will not allow Imports
....Powerpacks but I am trying other options
 
....and do I recognise that name? Fellow royalty gatherer...

message
from what I've seen.. VB.net has made a HUGE comeback in the past few
years.. and is now more popular than C#!





Am 02.01.2011 04:52, schrieb StrandElectric:
Understanding the project structure is one good beginning. :-)
The key point was only about putting classes into Namespaces, to
say it in short.

That sentence is way above my head!

As you were already programming in VB6 and before,> I thought that's the
first bigger change to VB6, and I explained it
because you were unsure about Imports.
If you want to get into VB.Net anyway, or if you want to upgrade code,
learn VB.Net. If you don't want or need to, and if you feel more
comfortable
in VB6 and just want to write the code that does what you need, then you
may use VB6 only. So, you must decide.

Well, I'm very happy with vb6, and I am looking at vb.net for two reasons.
1) In case my vb6 projects will not work with future Windows versions and
2)
as a challenege. 1 is more important by a long way.
Anyway, you're welcome to the group with the left over lone fighters
that keep this dead group alive. ;)

But there may be millions of puzzled beginners. Where do they all go.? Or
do
they all give up vb.net...It seems to be a long way from the natural
progressionof the basic language as many of us have known it. I thought
vb6
was absolutely brilliant. Why did Microsoft pull the plug on it? vb.net
seems so obscure from a user point of view. Almost as though a team
deliberately and peversely made the concepts as indirect as possible.


 
|
| And the list goes on. And if you want to talk about COM - well, VB.NET
| is better at COM then VB6, in that it can use a wider range of com
| objects, you know all those that don't implement IDispatch.
|

You didn't know that VB can do vTable binding?

| And what are you going to do when win8 supports ARM processors? Your
| apps will be limited to intel architectures only. .NET apps, will
| continue to work...
|
| Oh, and no xbox, windows phone 7, or zune developement for you either
| :)

...Or Silverlight. ...or Windows tablets. ...Thank goodness.

I read recently that what people want on their iPads
is music, TV, movies, etc. People are using computers
more and more, but doing less and less with them. So
iPads are big. No one needs to print or save files if they're
essentially just watching an overpriced, undersized,
mobile, interactive TV. It's a $600 digital pacifier.

Ironically that change in the market seems to be a big
part of the reason for Apple's success. They produce
beautiful, limited, overpriced, dependable toys...
just what the public wants.

According to Mary Jo Foley there's gossip that Win8
may be a services platform. (Remember, you heard
that predicted here first, several years ago. :) So then
programmers will be able to go broke writing ad-supported
..Net software to help people add custom icons to their
Twitter prattle, or to index their favorite TV shows...
Assuming that one buys a license from MS and can
qualify for their "app store".
(It costs $99 to just start to think about writing software
for the virtually non-existent WinPhone7.)

I love to code and I love to do Web design, but given
the way things are going, I might just take up watercolors
or gardening instead.
 
Here's the fragment of code I tried from Jason's submission, in vb2008
Express. For some reason I cannot remove the double spacing I only got
record lengths in the console output.:

Option Explicit On

Option Strict Off

Imports Microsoft.VisualBasic.FileIO 'tried other options. either not there
or no result.

Module Module1

Private m_NameOfFile As String = "C:\Claims\Claimall" 'exists. I do not want
to alter it.

Structure Claimall

<VBFixedString(30)> _

Public SampleString As String

<VBFixedString(20)> _

Public AnotherSample As String

<VBFixedString(205)> _

Public SpareSample As String

End Structure

Sub Main()

ReadRecord(1)

Console.WriteLine()

Console.ReadKey()

End Sub

Private Sub ReadRecord(ByVal recordNo As Integer)

Dim rec As New Claimall

Console.WriteLine("RecLength: " & Len(rec))

Dim hFile As Integer = FreeFile()

FileOpen(hFile, m_NameOfFile, OpenMode.Random, OpenAccess.Read, , Len(rec))

FileGet(hFile, rec, recordNo)

FileClose(hFile)

With rec

Console.WriteLine("{0}", .SampleString)

Console.WriteLine("{0}", .AnotherSample)' for now

End With

End Sub

End Module
 
After serious thinking Mayayana wrote :
You didn't know that VB can do vTable binding?

Sure, if you have a typelibrary. So for instance, when I wanted to use
the task scheduler classes in VB6, I had to create and compile my own
typelib. In .NET, you can actaully use attributes and bind to the
classes without using a custom typelib. In other words, you don't have
to step out side the language and use a completly different set of
tools to access an object that doesn't provide a typelib.
...Or Silverlight. ...or Windows tablets. ...Thank goodness.

I read recently that what people want on their iPads
is music, TV, movies, etc. People are using computers
more and more, but doing less and less with them. So
iPads are big. No one needs to print or save files if they're
essentially just watching an overpriced, undersized,
mobile, interactive TV. It's a $600 digital pacifier.

I tend to agree about the ipad. I think it's way over priced for what
it is... But, what is important about it is the the form factor and
the interface. Why do you think ms is going to be porting windows to
arm?
Ironically that change in the market seems to be a big
part of the reason for Apple's success. They produce
beautiful, limited, overpriced, dependable toys...
just what the public wants.

According to Mary Jo Foley there's gossip that Win8
may be a services platform. (Remember, you heard
that predicted here first, several years ago. :)

LOL... I don't know that anyone has ever argued that wouldn't happen.
The cloud seems to be the direction that things are moving in.
So then
programmers will be able to go broke writing ad-supported
.Net software to help people add custom icons to their
Twitter prattle, or to index their favorite TV shows...
Assuming that one buys a license from MS and can
qualify for their "app store".
(It costs $99 to just start to think about writing software
for the virtually non-existent WinPhone7.)

Yes - it cost $99. The app store is growing at something like two
times the pace that android or iphone was at the same point in it's
release.

It costs $99 dollars (plus buying a mac) to develop for iphone. And it
costs $25 dollars for android.

I don't actually see a problem with that. What is wrong with having a
convenient way for end users to get the applications they want?
I love to code and I love to do Web design, but given
the way things are going, I might just take up watercolors
or gardening instead.

Actually, I've been playing quite a bit with XNA for windows and wp7
(and yes, I actually have one of the devices - and yes, I love it) -
and I have to say, it's actually quite fun. Your missing out a bit, I
think...
 
It happens that a a r o n . k e m p f @ g m a i l . c o m formulated :
from what I've seen.. VB.net has made a HUGE comeback in the past few
years.. and is now more popular than C#!
Not anywhere I've ever seen :)
 
StrandElectric said:
I've been trying to read an existing random access file with some of your
code. . I am not complicating the issue with writing to a file or printing
just yet! BTW, I fear that Visual Basic Expess 2008 will not allow Imports
...Powerpacks but I am trying other options

The Imports I used are only required for printing using the Printer
object. If they don't work in Express then you won't be able to use it -
but you can always use PrintDocument instead.
 
StrandElectric said:
Imports Microsoft.VisualBasic.FileIO

The above is not required.
Module Module1

Private m_NameOfFile As String = "C:\Claims\Claimall"

I bet the above file doesn't exist. What is the file extension?

Have you enabled viewing of file extensions in Windows?

The rest of the code worked for me. :-)
 
Oh Bother! You are right. I left the extension off. It is an old file with
the extension .dat right back from the BASIC interpreter days (programming
in 16K...)
 
## so if I chose a normal form instead should I also open a (non-form)
##module as with vb6, and if so which parts of the code go in it?

You can, you can use it and get it by:
Project -> Add New Item -> choose the module template, don't forget to give
it a name before you enter.

Using a module is not real OOP, most of the text of Armin in this thread is
based on that so no need to duplicate it, it is a nice course he has
written.
 
Mayayana,

But VB for Net is than not anymore alone for creating TV dinners.

You can still create those with VB for Net, however it has become in your
analogy more a complete food chain where also TV dinners are sold, however
also very fine and extravagant food and beverage.

The difference with VB6 is, that VB Net is not only mainly positioned for
the Windows Desktop environment, but for everything which is now available
for the current Windows OS environment.

Also are all the conceptual things, where Tom is writing about, all the same
for VB, C++, C# and F# because it is in fact Net which set the rules.

Net itself is however an environment which uses peeled potatoes.

If you want to peel the potatoes yourself you need program languages like C
or C++ non managed as the non Net version is.

You can do some things with C# to peel the potatoes, but in fact not as good
as with C++ or C.

That the terminology inside .Net is not only a kind of old VB6 vocabulary is
normal.

You are also not anymore all days eating the food the cowboys did and use
for some of the food they eat not anymore those old names.
(Beside that most cowboys in the west were speaking German).

:-)

Cor




"Mayayana" wrote in message

| But you got me with one, I don't know what the meaning of a TV dinner in
| your language is.

I think TV dinners are still made but maybe people
don't eat them in front of the TV anymore. It's usually
a low-quality meal -- maybe hamburger, peas, and
processed potato -- all in their own sections of an
aluminum foil pan. The pan is covered with foil and
the product comes frozen. One then puts it into an oven
or microwave to heat it up.

The idea is a delicious, full course meal with no work.
The picture on the box shows such a meal. But the
contents inside are not very tasty.

I didn't mean to infer that VB and .Net are not
very tasty, though. Just that they're designed to
turn out a finished product easily. You can heat up
your TV dinner control, pour on a bit of Heinz
customization, and you've got an original software
product. :)
 
Back
Top