WUGNET, the Windows User Group Network
Your Complete Resource Center for "The Best" in Shareware, Computing Tips and Support, Windows Industry News... and much more!
Home Forums Shareware Windows Tips Hot Offers FREE Newsletters Arcade Contact Us About Partners
Search WUGNET: RSS Feeds RSS Feeds Advertise with WUGNET    |    Shareware eBooks
HomeHome FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

explanation of codes in Visual Basic when creating User form

 
   Home -> Office -> New Users RSS
Next:  DCOUNTA with multiple criteria  
Author Message
Rachel

External


Since: Sep 17, 2004
Posts: 53



(Msg. 1) Posted: Sun Nov 01, 2009 5:35 pm
Post subject: explanation of codes in Visual Basic when creating User form
Archived from groups: microsoft>public>excel>newusers (more info?)

Hi,
I am trying to create a user form in Visual Basic however I'm trying to
teach myself by reading/watching tutorials. (www.contectures.o.ca, etc)
A lot of the instructions I am seeing simply give the code rather than
explain how to actually write one from scratch.
So...
I need to know what each 'term' means so I can understand how the codes work.
Any help is much appreciated Smile

One of the first codes is for the Add button
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("PartsData")
What does each term refer to?
Dim
iRow
As Long
ws
Set

etc?

Is there a website that has all these definitions?
I don't really want to just copy and paste codes because when my form
doesn't work I can't work out where the error is.

Thank you in advance.
Rachel
Back to top
Login to vote
Sox

External


Since: Nov 02, 2009
Posts: 1



(Msg. 2) Posted: Mon Nov 02, 2009 1:32 am
Post subject: Re: explanation of codes in Visual Basic when creating User form [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Depends on how extensive an explanation you need. A sketchy explantion of
most of the terms is available in the help files within the Visual Basic
editor. For example, looking up "Dim" will give you the syntax of Dim with
its minimum and optional parts, and a few examples. In its simplest use Dim
is used to define a variable. For the example you gave

Dim iRow as Long

means you have defined a variable named "iRow" and you want it to be the
data type long integer ("Long" in VB-speak). The named variable can then be
used later within the function or subroutine. In general, you can name your
variables almost anything you want but there are some restrictions -- you
can't have a variable named as all integers for example (there's no way to
tell that "1234" means your variable instead of just a number), and you
cannot give a variable a name that is a reserved word in visual basic.

Following that pattern, the line:

Dim ws as Worksheet

means you defined a variable named "ws" as a Worksheet. Defining that
variable just reserves memory for its later use, and does not actually
assign a value to it (more acurately, it has the special value of "Nothing"
until you tell the subroutine which Worksheet you want the variable ws to
refer to). Speaking of which....

Set ws = Worksheets("PartsData")

means you have set the variable ws, which you previously defined as a
variable referring to a Worksheet, to refer to the "PartsData" Worksheet.
For that particular example, presumably the workbook actually has a
Worksheet named "PartsData", otherwise any of the following code using the
variable ws is going to get really confused.

If you have any background in programming -- and in particular
object-oriented programming -- you can stumble your way through most Excel
programming just by recording Macros and looking at the resulting code,
supplmented with a healthy dose of the help files.

On the other hand, if you do not have any background at all in programming,
or if all of that Visual Basic for applications code looks like double-talk,
one of the many books on Excel programming might be advisable. The general
observation is that object-orietned programming has a fairly steep leanring
curve, because everything it talks about refers to something else you don't
know about. In that case a good book that actually steps through examples
and explains what is going on might be useful.

Regards,

"Rachel" <Rachel.RemoveThis@discussions.microsoft.com> wrote in message
news:653D7464-FCF3-47AF-A392-FDCA7B9EF709@microsoft.com...
> Hi,
> I am trying to create a user form in Visual Basic however I'm trying to
> teach myself by reading/watching tutorials. (www.contectures.o.ca, etc)
> A lot of the instructions I am seeing simply give the code rather than
> explain how to actually write one from scratch.
> So...
> I need to know what each 'term' means so I can understand how the codes
> work.
> Any help is much appreciated Smile
>
> One of the first codes is for the Add button
> Private Sub cmdAdd_Click()
> Dim iRow As Long
> Dim ws As Worksheet
> Set ws = Worksheets("PartsData")
> What does each term refer to?
> Dim
> iRow
> As Long
> ws
> Set
>
> etc?
>
> Is there a website that has all these definitions?
> I don't really want to just copy and paste codes because when my form
> doesn't work I can't work out where the error is.
>
> Thank you in advance.
> Rachel
Back to top
Login to vote
Rachel

External


Since: Sep 17, 2004
Posts: 53



(Msg. 3) Posted: Wed Nov 04, 2009 3:19 pm
Post subject: Re: explanation of codes in Visual Basic when creating User form [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thanks very much Sox,
I think I will invest in a good book and get studying.
Cheers


"Sox" wrote:

> Depends on how extensive an explanation you need. A sketchy explantion of
> most of the terms is available in the help files within the Visual Basic
> editor. For example, looking up "Dim" will give you the syntax of Dim with
> its minimum and optional parts, and a few examples. In its simplest use Dim
> is used to define a variable. For the example you gave
>
> Dim iRow as Long
>
> means you have defined a variable named "iRow" and you want it to be the
> data type long integer ("Long" in VB-speak). The named variable can then be
> used later within the function or subroutine. In general, you can name your
> variables almost anything you want but there are some restrictions -- you
> can't have a variable named as all integers for example (there's no way to
> tell that "1234" means your variable instead of just a number), and you
> cannot give a variable a name that is a reserved word in visual basic.
>
> Following that pattern, the line:
>
> Dim ws as Worksheet
>
> means you defined a variable named "ws" as a Worksheet. Defining that
> variable just reserves memory for its later use, and does not actually
> assign a value to it (more acurately, it has the special value of "Nothing"
> until you tell the subroutine which Worksheet you want the variable ws to
> refer to). Speaking of which....
>
> Set ws = Worksheets("PartsData")
>
> means you have set the variable ws, which you previously defined as a
> variable referring to a Worksheet, to refer to the "PartsData" Worksheet.
> For that particular example, presumably the workbook actually has a
> Worksheet named "PartsData", otherwise any of the following code using the
> variable ws is going to get really confused.
>
> If you have any background in programming -- and in particular
> object-oriented programming -- you can stumble your way through most Excel
> programming just by recording Macros and looking at the resulting code,
> supplmented with a healthy dose of the help files.
>
> On the other hand, if you do not have any background at all in programming,
> or if all of that Visual Basic for applications code looks like double-talk,
> one of the many books on Excel programming might be advisable. The general
> observation is that object-orietned programming has a fairly steep leanring
> curve, because everything it talks about refers to something else you don't
> know about. In that case a good book that actually steps through examples
> and explains what is going on might be useful.
>
> Regards,
>
> "Rachel" <Rachel.TakeThisOut@discussions.microsoft.com> wrote in message
> news:653D7464-FCF3-47AF-A392-FDCA7B9EF709@microsoft.com...
> > Hi,
> > I am trying to create a user form in Visual Basic however I'm trying to
> > teach myself by reading/watching tutorials. (www.contectures.o.ca, etc)
> > A lot of the instructions I am seeing simply give the code rather than
> > explain how to actually write one from scratch.
> > So...
> > I need to know what each 'term' means so I can understand how the codes
> > work.
> > Any help is much appreciated Smile
> >
> > One of the first codes is for the Add button
> > Private Sub cmdAdd_Click()
> > Dim iRow As Long
> > Dim ws As Worksheet
> > Set ws = Worksheets("PartsData")
> > What does each term refer to?
> > Dim
> > iRow
> > As Long
> > ws
> > Set
> >
> > etc?
> >
> > Is there a website that has all these definitions?
> > I don't really want to just copy and paste codes because when my form
> > doesn't work I can't work out where the error is.
> >
> > Thank you in advance.
> > Rachel
>
Back to top
Login to vote
Display posts from previous:   
       Home -> Office -> New Users All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Categories:
 Windows XP
 Windows Vista
 Windows Other
  Office
 Office Other
 Security
  • Home |
  • Shareware |
  • Windows Tips |
  • Hot Offers |
  • FREE Newsletters |
  • Arcade |
  • Forums |
  • eBooks |
  • About WUGNET |
  • Partners |
  • Contact

  • WUGNET Privacy Policy |
  • Link to WUGNET |
  • IT Support